<jupyter_start><jupyter_text>Author - <NAME> Data Science and Business Analytics Intern GRIP - The Sparks Foundation Task-1  Prediction using Supervised Machine Learning<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression  
from sklearn.model_selection import train_test_split  
from sklearn import metrics  
import numpy as np
data = pd.read_csv('data.csv')
data.head()
data.plot(x = "Hours", y = "Scores", style='o')
plt.title('Hours vs Percentage')                                     
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')  
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Train-Test Split<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,test_size=0.2, random_state=0)<jupyter_output><empty_output><jupyter_text>Training a simple linear regression model<jupyter_code>from sklearn.linear_model import LinearRegression  
regressor = LinearRegression()  
regressor.fit(X_train, y_train) 
regressor.score(X_test, y_test)
regressor.coef_, regressor.intercept_
line = regressor.coef_*X+regressor.intercept_
plt.scatter(X, y,c='red')
plt.plot(X, line,c='black')

plt.show()<jupyter_output><empty_output><jupyter_text>Prediction<jupyter_code>y_pred = regressor.predict(X_test)
df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})  
df 
Hours=9.25
own_pred= regressor.predict(np.atleast_2d(Hours))                          
print("No of hours = {}".format(Hours))
print("Predicted percentage = {}".format(own_pred[0]))<jupyter_output>No of hours = 9.25
Predicted percentage = 93.69173248737539<jupyter_text>Evaluation<jupyter_code>from sklearn import metrics  
from sklearn.metrics import r2_score
print('Mean Absolute Error:',metrics.mean_absolute_error(y_test, y_pred)) 

print("The R-Square of my model is: ",r2_score(y_test,y_pred))<jupyter_output>Mean Absolute Error: 4.183859899002982
The R-Square of my model is:  0.9454906892105354
{'fraction_non_alphanumeric': 0.11473018959649976, 'fraction_numerical': 0.03159941662615459, 'mean_word_length': 5.492113564668769, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '370147', 'license': 'MIT', 'n_tokens_mistral': 795, 'n_tokens_neox': 725, 'n_words': 148, 'path': 'task1/.ipynb_checkpoints/Task1-checkpoint.ipynb', 'repo_name': 'HimanchalChandra/GRIPTasks-TSF', 'size': '2068'}