<jupyter_start><jupyter_text>**Task1****Prediction using Supervised ML***Predict the percentage of an student based on the no. of study hours.*  **Importing Libraries and Dataset**<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from google.colab import files
uploaded = files.upload()<jupyter_output><empty_output><jupyter_text>**Reading the data**<jupyter_code>dataset=pd.read_csv("student_scores.csv")

print(dataset)
dataset.shape

dataset.head()<jupyter_output><empty_output><jupyter_text>**Data Preprocesing**  Preparing the Data<jupyter_code>X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
print(X)
print(y)
# 2-D graph to establish relationship between the data
dataset.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>**Next, we will split both variables into the test set and training set.**<jupyter_code># splitting of dataset
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=0)<jupyter_output><empty_output><jupyter_text>**We have split our data into training and testing sets, and now is finally the time to train our algorithm.**<jupyter_code>from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>**To retrieve the intercept**<jupyter_code>print(regressor.intercept_)<jupyter_output>2.018160041434662<jupyter_text>**For retrieving the slope (coefficient of x)**<jupyter_code>print(regressor.coef_)<jupyter_output>[9.91065648]<jupyter_text>**Prediction of test set result**<jupyter_code>y_pred= regressor.predict(X_test)  
X_pred= regressor.predict(X_train)

print(y_pred)
print(X_pred)<jupyter_output>[16.88414476 33.73226078 75.357018   26.79480124 60.49103328]
[39.67865467 20.84840735 79.32128059 70.40168976 12.91988217 52.56250809
 78.33021494 34.72332643 84.27660883 93.19619966 62.47316457 36.70545772
 28.77693254 56.52677068 28.77693254 86.25874013 26.79480124 49.58931115
 90.22300272 46.6161142 ]<jupyter_text>**Visualizing the Training set results**<jupyter_code>plt.scatter(X_train, y_train, color="green")   
plt.plot(X_train, X_pred, color="red")    
plt.title("Hours Studied Vs Percentage (Training Dataset)")  
plt.xlabel("Hours")  
plt.ylabel("Percentage")  
plt.show()<jupyter_output><empty_output><jupyter_text>**Visualizing the Test set results**<jupyter_code>plt.scatter(X_test, y_test, color="blue")   
plt.plot(X_train, X_pred, color="red")    
plt.title("Hours Studied Vs Percentage  (Test Dataset)")  
plt.xlabel("Hour")  
plt.ylabel("Percentage")  
plt.show()<jupyter_output><empty_output><jupyter_text>**To compare the actual output values for Y_test with the predicted values**<jupyter_code>df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})
df
from sklearn import metrics
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))<jupyter_output>Mean Absolute Error: 4.183859899002982
Mean Squared Error: 21.598769307217456
Root Mean Squared Error: 4.647447612100373
{'fraction_non_alphanumeric': 0.12273940112659354, 'fraction_numerical': 0.0972428105544026, 'mean_word_length': 7.973404255319149, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '643747', 'license': 'MIT', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1223, 'n_words': 252, 'path': 'LinearRegression.ipynb', 'repo_name': 'AKASHANAND8029/Prediction-using-Supervised-ML', 'size': '3373'}