<jupyter_start><jupyter_text>**The Sparks Foundation** **Data Science and Business Analytics** by **<NAME>** Task 1  Importing the Libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Creating the DataFrame<jupyter_code>data = pd.read_csv('/content/drive/MyDrive/student_scores - student_scores.csv')
data.head() # printing the whole dataset<jupyter_output><empty_output><jupyter_text>Visualizing the dataset<jupyter_code>plt.figure(figsize=(5,5), dpi=120)
plt.scatter(data['Hours'], data['Scores'])
plt.xlabel('Hours studied in a day')
plt.ylabel('Scores(%) obtained')
plt.title('Scores Vs. Marks')<jupyter_output><empty_output><jupyter_text>Splitting the DataFrame Object into forcaster Series object and target Series Object.<jupyter_code>X = np.array(data['Hours'])
y = np.array(data['Scores'])
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state = 42)
X_train.shape, y_train.shape, X_test.shape, y_test.shape<jupyter_output><empty_output><jupyter_text>Importing the LinearRegression class from Scikit Learn<jupyter_code>from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()<jupyter_output><empty_output><jupyter_text>Fitting the model with our training dataset<jupyter_code>lin_reg.fit(X_train.reshape(-1,1),y_train)<jupyter_output><empty_output><jupyter_text>Printing the parameter of our hypothesis function<jupyter_code>lin_reg.intercept_, lin_reg.coef_<jupyter_output><empty_output><jupyter_text>Predicting the testset<jupyter_code>y_pred_test = lin_reg.predict(X_test.reshape(-1,1))<jupyter_output><empty_output><jupyter_text>Plotting the regression line on our dataset<jupyter_code>plt.figure(figsize=(5,5), dpi=120)
y_pred = lin_reg.intercept_ + lin_reg.coef_*X
plt.scatter(X, y)
plt.plot(X,y_pred,"r-")
plt.title('Prediction line evaluated by Linear Regression Model')
plt.xlabel('Hours studied in a day')
plt.ylabel('Scores obtained')<jupyter_output><empty_output><jupyter_text>Linear Regression using SGDRegressor Class of sklearn<jupyter_code>from sklearn.linear_model import SGDRegressor
sgd_reg = SGDRegressor(max_iter=1000, tol=1e-3, penalty=None, eta0=0.1)
sgd_reg.fit(X_train.reshape(-1,1),y_train.ravel())<jupyter_output><empty_output><jupyter_text>Printing the parameters of our hypothesis function<jupyter_code>sgd_reg.intercept_, sgd_reg.coef_<jupyter_output><empty_output><jupyter_text>Prediciting the TestSet<jupyter_code>y_pred_test_sgd = sgd_reg.predict(X_test.reshape(-1,1))<jupyter_output><empty_output><jupyter_text>Comparative Analysis of the above two linear models<jupyter_code>from sklearn.metrics import mean_squared_error

np.sqrt(mean_squared_error(y_test, y_pred_test)), np.sqrt(mean_squared_error(y_test, y_pred_test_sgd))<jupyter_output><empty_output><jupyter_text>* Hence, the Stochastic Gradient Descent algorithm based model works well comparatively.  Predicting marks for a score value = 9.25 Hours<jupyter_code>lin_reg.predict(np.array(9.25).reshape(-1,1))<jupyter_output><empty_output><jupyter_text>* According to our LinearRegression Class based model, a student who studys for 9.25 hours a day can score 93% more or less.<jupyter_code>sgd_reg.predict(np.array(9.25).reshape(-1,1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1135280095351609, 'fraction_numerical': 0.014898688915375448, 'mean_word_length': 10.07920792079208, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '391906', 'license': 'MIT', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1219, 'n_words': 215, 'path': 'Task 1/TSF___Task_1___Prediction_Using_Supervised_ML.ipynb', 'repo_name': 'noob-coder-dev/TSF-GRIP-Projects', 'size': '3361'}