<jupyter_start><jupyter_text>Graduated Rotational Internship Program: The Sparks Foundation  Data Science & Analytics Intern Author: Daksh.R.Solanki   TASK 1: Prediction using Supervised ML  Problem StatementIn this regression task we will predict the percentage of marks that a student is expected to score based upon the number of hours they studied. This is a simple linear regression task as it involves just two variables. To predict:What will be predicted score if a student studies for 9.25 hrs/ day?  Importing required Libraries<jupyter_code>#importing required libraries  
import pandas as pd
import numpy as np  
import matplotlib.pyplot as plt  
%matplotlib inline

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# importing link from the url link
url = "http://bit.ly/w-data"
data = pd.read_csv(url)
print("Data Imported Successfully")
data
data.head()
data.tail()
data.info()
data.describe()
# Plotting the graph to know the relationship between the data 
data.plot(x='Hours', y='Scores', style='*')  
plt.title('Hours vs Percentage')  
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')  
plt.show()<jupyter_output><empty_output><jupyter_text>Above graph that there is a positive relation between numbers of hours studied and percentage of score  Linear Regression Linear regression is a supervised learning algorithm used when target ? dependent variable continues real number. It establishes relationship between dependent variable y and one or more independent variable x using fit line.  Data Visualization<jupyter_code>#visulizing with line plot

plt.style.use('ggplot')
data.plot(kind="line" )
plt.title('Hours vs Percentage')
plt.xlabel('Hours studied')
plt.ylabel('Percentage score')
plt.show()

x=np.asanyarray(data[['Hours']])
y=np.asanyarray(data['Scores'])

#using train test split to split the data in train and test data
train_x,test_x,train_y,test_y=train_test_split(x,y,test_size=0.2,random_state=2)

regressor=LinearRegression()
regressor.fit(train_x,train_y)

print("Training completed")
print("Coefficients:",regressor.coef_)
print("Intercept",regressor.intercept_)
from sklearn.metrics import mean_squared_error
from sklearn import metrics
from sklearn.metrics import r2_score

y_pred=regressor.predict(test_x)
print("Mean_Absolute_Error:{}".format(metrics.mean_absolute_error(y_pred,test_y)))
print("R2 score: %.2f"%r2_score(y_pred,test_y))
# Making Predictions 
data=pd.DataFrame({'Actual':test_y,'Predicted':y_pred})
data<jupyter_output><empty_output><jupyter_text>test<jupyter_code>hours=9.25
predicted_score=regressor.predict([[hours]])

print(f'No of hours= {hours}')
print(f'Predicted Score= {predicted_score[0]}')<jupyter_output>No of hours= 9.25
Predicted Score= 93.45860055685802
{'fraction_non_alphanumeric': 0.096415770609319, 'fraction_numerical': 0.012186379928315413, 'mean_word_length': 6.974285714285714, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '65428', 'license': 'MIT', 'n_tokens_mistral': 920, 'n_tokens_neox': 860, 'n_words': 261, 'path': 'GRIP _TASK_1.ipynb', 'repo_name': 'dakshsol/The-Sparks-Foundation-Task-1-', 'size': '2790'}