<jupyter_start><jupyter_text>GRIP : The Sparks Foundation Data Science and Business Analytics InternshipAuthor : <NAME>Task 1 : Prediction using Supervised ML In this task it is required to predict the percentage of a student on the basis of number of hours studied using the Linear Regression Supervised Machine Learning algorithmImporting the datasetIn this step we will import the dataset through the link with the help of Pandas Library and then we will observe the data.<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats
import statsmodels.formula.api as smf
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
data = pd.read_csv('http://bit.ly/w-data')
data.head()
data.tail()
# To find the number of columns and rows
data.shape
# To find more information about our dataset
data.info()
data.describe()
# now we will check if our dataset contains null or missings values  
data.isnull().sum()
# Plotting the dataset
plt.rcParams["figure.figsize"] = [13,7]
data.plot(x='Hours', y='Scores', style='.', color='red', markersize=10)
plt.title('Hours vs Percentage')  
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score')  
plt.grid()
plt.show()
data.head()
# using iloc function we will divide the data 
X = data.iloc[:, :1].values  
y = data.iloc[:, 1:].values
X
y
# Splitting data into training and testing data

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>Training the Algorithm<jupyter_code>from sklearn.linear_model import LinearRegression  

model = LinearRegression()  
model.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>line = model.coef_*X + model.intercept_

# Plotting for the training data
plt.rcParams["figure.figsize"] = [13,7]
plt.scatter(X_train, y_train, color='red')
plt.plot(X, line, color='green');
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score') 
plt.grid()
plt.show()
# Plotting for the testing data
plt.rcParams["figure.figsize"] = [13,7]
plt.scatter(X_test, y_test, color='red')
plt.plot(X, line, color='green');
plt.xlabel('Hours Studied')  
plt.ylabel('Percentage Score') 
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Making Predictions<jupyter_code>print(X_test) # Testing data - In Hours
y_pred = model.predict(X_test) # Predicting the scores
# Comparing Actual vs Predicted
comp = pd.DataFrame({ 'Actual':[y_test],'Predicted':[y_pred] })
comp
# Testing with your own data

hours = 9.25
own_pred = model.predict([[hours]])
print("The predicted score if a person studies for",hours,"hours is",own_pred[0])
from sklearn import metrics  

print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))<jupyter_output>Mean Absolute Error: 4.183859899002975
{'fraction_non_alphanumeric': 0.10943775100401607, 'fraction_numerical': 0.012382864792503346, 'mean_word_length': 5.777777777777778, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '418746', 'license': 'MIT', 'n_tokens_mistral': 1037, 'n_tokens_neox': 969, 'n_words': 288, 'path': 'Task1.ipynb', 'repo_name': 'Umesh3311/Task1--SPARK-FOUNDATION-INTERNSHIP', 'size': '3008'}