<jupyter_start><jupyter_text>Simple Linear Regression  Importing all libraries required<jupyter_code>import pandas as pd
import numpy as np  
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
%matplotlib inline
# Reading data from remote link
url = "http://bit.ly/w-data"
data = pd.read_csv(url)
print("Data imported successfully")
data.head(10)
# The shape of dataset 
data.shape
# check the info of data
data.info()
# check the description of student_score data
data.describe()<jupyter_output><empty_output><jupyter_text>Data Visualization<jupyter_code># Plotting the distribution of scores
data.plot(x='Hours', y='Scores', style='o')  
plt.title('Hours vs Percentage')  
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')  
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression Model<jupyter_code>X = data.iloc[:, :-1].values  
y = data.iloc[:, 1].values  
X_train, X_test, y_train, y_test = train_test_split(X, y,train_size=0.80,test_size=0.20,random_state=42)<jupyter_output><empty_output><jupyter_text>Training the model<jupyter_code>from sklearn.linear_model import LinearRegression
linearRegressor= LinearRegression()
linearRegressor.fit(X_train, y_train)
y_predict= linearRegressor.predict(X_train)<jupyter_output><empty_output><jupyter_text>Training the Algorithm<jupyter_code>regressor = LinearRegression()  
regressor.fit(X_train, y_train) 

print("Training complete.")

# Plotting the regression line
line = regressor.coef_*X+regressor.intercept_
# Plotting for the test data
plt.scatter(X, y)
plt.plot(X, line);
plt.title('Hours vs Percentage')  
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')
plt.show()<jupyter_output><empty_output><jupyter_text>Checking the accuracy scores for training and test set<jupyter_code>print('Test Score')
print(regressor.score(X_test, y_test))
print('Training Score')
print(regressor.score(X_train, y_train))
y_test
y_predict

y_predict[:5]
data= pd.DataFrame({'Actual': y_test,'Predicted': y_predict[:5]})
data
#Let's predict the score for 9.25 hpurs
print('Score of student who studied for 9.25 hours a dat', regressor.predict([[9.25]]))<jupyter_output>Score of student who studied for 9.25 hours a dat [92.38611528]<jupyter_text>Model Evaluation Metrics<jupyter_code>#Checking the efficiency of model
mean_squ_error = mean_squared_error(y_test, y_predict[:5])
mean_abs_error = mean_absolute_error(y_test, y_predict[:5])
print("Mean Squred Error:",mean_squ_error)
print("Mean absolute Error:",mean_abs_error)<jupyter_output>Mean Squred Error: 1404.2200673968694
Mean absolute Error: 33.80918778157651
{'fraction_non_alphanumeric': 0.11030478955007257, 'fraction_numerical': 0.026124818577648767, 'mean_word_length': 8.009803921568627, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '1592', 'license': 'MIT', 'n_tokens_mistral': 1039, 'n_tokens_neox': 946, 'n_words': 214, 'path': 'Task 1-Prediction using Supervised ML/Prediction using Supervised ML.ipynb', 'repo_name': 'Divyakathirvel26/GRIP-Internship-Tasks', 'size': '2756'}