<jupyter_start><jupyter_text>The Spark Foundation  By: Karan  Task-1 Prediction using Supervised ML Problem statment● predicted score if a student studies for 9.25 hrs/ day● dataset: http://bit.ly/w-data  libraries required<jupyter_code>import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Importing data<jupyter_code>url=('https://raw.githubusercontent.com/AdiPersonalWorks/Random/master/student_scores%20-%20student_scores.csv')
stud=pd.read_csv(url)
stud
# checking for null values
stud.isnull().sum()<jupyter_output><empty_output><jupyter_text>Hours vs Score<jupyter_code>sns.lineplot(x="Hours",y="Scores",data=stud, color='red')
plt.show()<jupyter_output><empty_output><jupyter_text>outliers detection<jupyter_code>sns.boxplot(y="Hours", data=stud)
plt.show()
sns.boxplot(y="Scores", data=stud)
plt.show()<jupyter_output><empty_output><jupyter_text>Most time spent  by students<jupyter_code>stud['Hours'].value_counts().plot(kind= 'bar')<jupyter_output><empty_output><jupyter_text>Most scored  by students<jupyter_code>stud['Scores'].value_counts().plot(kind= 'bar')<jupyter_output><empty_output><jupyter_text>Observations:Higher the hours spent the scores are good in numberno outier detectedmax spent hours is 2.5 and 2.7max scored is 30   Dividing the data features  into X,y variables<jupyter_code>X = stud.iloc[:,:1]
y = stud.iloc[:,1]<jupyter_output><empty_output><jupyter_text>Imported the sklearn library train_test split<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size = 0.7, test_size = 0.3, random_state = 100)
X_train.head()
y_train.head()
from sklearn.linear_model import LinearRegression

# Representing LinearRegression as lr(Creating LinearRegression Object)
lm = LinearRegression()

# Fit the model using lr.fit()
lm.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Print the parameters, i.e. the intercept and the slope of the regression line fitted<jupyter_code>print(lm.intercept_)
print(lm.coef_)<jupyter_output>1.4951421092364043
[9.87171443]<jupyter_text>plotting the best fit line<jupyter_code>plt.scatter(X_train, y_train)
plt.plot(X_train, 1.495142109236383 + 9.87171443*X_train, 'y')
plt.title("Prediction")
plt.xlabel("Hours")
plt.ylabel("Scores")
plt.show()<jupyter_output><empty_output><jupyter_text>Predict the y values corresponding to X_test_sm<jupyter_code>y_pred = lm.predict(X_test)
print(y_pred)<jupyter_output>[28.14877107 39.00765694 34.07179972 59.73825724 16.30271375 74.54582888
 69.60997167 48.87937137]<jupyter_text>comparing the actual versus predicted<jupyter_code>comparison=pd.DataFrame({"Actual":y_test,"Predicted":y_pred})
comparison<jupyter_output><empty_output><jupyter_text>plotting the best fit line for the test dataset<jupyter_code>plt.scatter(X_test, y_test)
plt.plot(X_test, 1.495142109236383 + 9.87171443 * X_test, 'y')
plt.show()<jupyter_output><empty_output><jupyter_text>printing the predicted score<jupyter_code>pred_score = lm.predict([[9.25]])
print("The predicted score is :",pred_score)<jupyter_output>The predicted score is : [92.80850057]<jupyter_text>Returns the mean squared error; we'll take a square root<jupyter_code>np.sqrt(mean_squared_error(y_test, y_pred))
r_squared = r2_score(y_test, y_pred)
r_squared
mean_absolute_error(y_test, y_pred)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11834835708054667, 'fraction_numerical': 0.05612096539691771, 'mean_word_length': 9.207715133531158, 'pattern_counts': {'":': 2, '<': 58, '<?xml version=': 0, '>': 58, 'https://': 1, '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': '579994', 'license': 'Apache-2.0', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1290, 'n_words': 231, 'path': 'Student prediction T1 TSF.ipynb', 'repo_name': 'Karanmehra7107/TSF-GRIP-Intern-Tasks', 'size': '3439'}