<jupyter_start><jupyter_text>The Sparks Foundation: Prediction using Supervised ML Predict the percentage of an student based on No. of study hours 🧑‍💻**Author: <NAME>**  Importing the Libraries and DatasetStep 1: Importing all the required libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Step 2: Importing the [dataset](https://bit.ly/w-data "Student Scores Dataset")<jupyter_code>dataset = pd.read_csv("student_scores.csv")
print("Student scores dataset: ")
dataset.head(15)<jupyter_output>Student scores dataset:<jupyter_text>Step 3: Checking null value in dataset<jupyter_code>dataset.isnull == True<jupyter_output><empty_output><jupyter_text>Step 4: Plotting the graph for detailed analysis 📊<jupyter_code>dataset.plot.scatter(x='Hours',y='Scores',style='1')
plt.title('Hours vs Percentage')  
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')  
plt.show()<jupyter_output><empty_output><jupyter_text>Preparing the DataStep 5: Dividing the data into "attributes" (inputs) and "labels" (outputs)<jupyter_code>x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
#print(x)<jupyter_output><empty_output><jupyter_text>Step 6: Splitting the dataset in Training set and Test set for train_test_split() method<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, random_state = 0)<jupyter_output><empty_output><jupyter_text>Training the ModelStep 7: Fitting Simple Linear Regression to the training set<jupyter_code>from sklearn.linear_model import LinearRegression
regressor = LinearRegression()

regressor.fit(x_train, y_train)

print("Training Completed!")<jupyter_output>Training Completed!<jupyter_text>Step 8: Plotting the Regression line and for the Test data<jupyter_code>regression_line = regressor.coef_*x+regressor.intercept_

plt.scatter(x, y)
plt.plot(x, regression_line)
plt.title('Hours VS Score')
plt.xlabel('Hours')
plt.ylabel('Score');
plt.show()<jupyter_output><empty_output><jupyter_text>Testing the ModelStep 9: Making Predictions<jupyter_code>print(x_test) 
print("Predection of the Score: ")
y_pred = regressor.predict(x_test)
print(y_pred)<jupyter_output>[[1.5]
 [3.2]
 [7.4]
 [2.5]
 [5.9]
 [3.8]
 [1.9]
 [7.8]]
Predection of the Score: 
[17.05366541 33.69422878 74.80620886 26.8422321  60.12335883 39.56736879
 20.96909209 78.72163554]<jupyter_text>Step 10: Comparing Actual vs Predicted<jupyter_code>df = pd.DataFrame({'Actual Score': y_test, 'Predicted Score': y_pred})  

df<jupyter_output><empty_output><jupyter_text>Step 11: Testing with our Data<jupyter_code>hours = np.array([9.25])
hours = hours.reshape(-1,1)
our_pred = regressor.predict(hours)

print("Number of Hours = {}".format(float(hours))) 
print("Predicted Score = {}".format(round(our_pred[0],3)))<jupyter_output>Number of Hours = 9.25
Predicted Score = 92.915<jupyter_text>Checking Accuracy of the Model<jupyter_code>from sklearn import metrics

mae = metrics.mean_absolute_error(y_test,y_pred)
print('Mean Absolute Error:', mae)


rmse = np.sqrt(metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:', rmse)<jupyter_output>Mean Absolute Error: 4.419727808027652
Root Mean Squared Error: 4.792191274636315
{'fraction_non_alphanumeric': 0.12173913043478261, 'fraction_numerical': 0.048875562218890556, 'mean_word_length': 7.778947368421052, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '139621', 'license': 'MIT', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1208, 'n_words': 263, 'path': 'Prediction-using-Supervised-ML.ipynb', 'repo_name': 'zerothrohit/Prediction-using-Supervised-ML', 'size': '3341'}