<jupyter_start><jupyter_text>Author : <NAME>  Task 1 : Prediction using Supervised Machine Learning  GRIP @ The Sparks Foundation Sept 2021  Domian :- Data Science and Buiseness Analytics  Level:- Beginner In this regression task I tried to predict the percentage of marks that a student is expected to score based upon the number of hours they studied.  Importing The Required labraries<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Importing The Data Set<jupyter_code># import data 

df=pd.read_csv('https://raw.githubusercontent.com/AdiPersonalWorks/Random/master/student_scores%20-%20student_scores.csv')
print("Data Imported Done")
df

# to check shape of data

print("The shape of data is",df.shape)
# to check information of all data
df.info()
# to check the correlation between dependent variable and independent variable

df.corr()
# to check null values in data 
df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Data Visualization  let's plot our data point on 2D graph and see if we can manually find the realation between Hourse and Scores<jupyter_code>df.plot(x="Hours",y="Scores",style='o')
plt.title("Hours vs Scores")
plt.xlabel("Hours")
plt.ylabel('scores')
plt.grid(True)
plt.show()<jupyter_output><empty_output><jupyter_text>From the above graph we can clearly see that there is  positive reationship between number of hours studied and percentage of scores  Data Preprocessing The next step is to divide the data into "attributes" (inputs) and "labels" (outputs).i.e dependent and independent variables<jupyter_code># to define dependent and independent variables
x = df.iloc[:,: -1].values
y = df.iloc[:, 1].values
x
y<jupyter_output><empty_output><jupyter_text>Spliting The Data set Into Train and Test Set now we have  our "attributes" and "labels", now we split the data set into train set and test set for that we will do this by using Scikit-Learn's in biuld 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,test_size=0.2,random_state =0)
# to check the shape of the train and test set
x_train.shape
print(x_test)
y_test.shape<jupyter_output>[[1.5]
 [3.2]
 [7.4]
 [2.5]
 [5.9]]<jupyter_text>Training The Model we have have train and test set  Now Finally it's time to  train our Algorithm<jupyter_code>from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(x_train,y_train)<jupyter_output><empty_output><jupyter_text>Ploting The Regression Line<jupyter_code>#ploting the regression line

line = lr.coef_*x + lr.intercept_

plt.scatter(x,y)
plt.plot(x,line,color ="red")
plt.show()<jupyter_output><empty_output><jupyter_text>Making Prediction<jupyter_code>y_pred = lr.predict(x_test)

y_pred

## comparing the actual vs predicted values
df1 = pd.DataFrame({'actual':y_test,'predict':y_pred})
df1<jupyter_output><empty_output><jupyter_text>Visualize The Actual and Predected Values Using  Garph<jupyter_code>df1.plot(kind = "bar", figsize = (12,6))
plt.grid(which="minor", linewidth = "0.5", color = "yellow")
plt.grid(which="major", linewidth = "0.5", color = "red")<jupyter_output><empty_output><jupyter_text>Estimiting Train and Test Score<jupyter_code>print("Training Score :",lr.score(x_train,y_train))
print("Testing Score :",lr.score(x_test,y_test))<jupyter_output>Testing Score : 0.9454906892105354<jupyter_text>Test The Random Data<jupyter_code>## let's test the data 
hours = 2.5
test_pred= lr.predict([[hours]])

print('No of hours:- {}'.format(hours))
print('predicted hours:- {}'.format(test_pred))<jupyter_output>No of hours:- 2.5
predicted hours:- [26.79480124]<jupyter_text>Evaluating The Model The final step is to evaluate the performance of algorithm. This step is particularly important to compare how well different algorithms perform on a particular dataset. Here different errors have been calculated to compare the model performance and predict the accuracy.<jupyter_code>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)))
print('R-2:', metrics.r2_score(y_test, y_pred))<jupyter_output>Mean Absolute Error: 4.183859899002982
Mean Squared Error: 21.598769307217456
Root Mean Squared Error: 4.647447612100373
R-2: 0.9454906892105354
{'fraction_non_alphanumeric': 0.10246262093227793, 'fraction_numerical': 0.029683377308707123, 'mean_word_length': 6.776068376068376, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 46, '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': '521805', 'license': 'MIT', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1504, 'n_words': 444, 'path': 'Sol_task1.ipynb', 'repo_name': 'patpankaj/The-Spark-s-Foundation-Tasks', 'size': '4554'}