Gadgets 4 Students Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
5.6k views
in Python Programming by Goeduhub's Expert (2.2k points)
edited by

Prediction using Supervised Machine Learning using Simple Linear Regression

In this task we have to find the students scores based on their study hours. This is a simple Regression problem type because it has only two variables. 

Sample Dataset- you can download a csv file of dataset

2 Answers

0 like 0 dislike
by (278 points)
selected by
 
Best answer

GO_STP_6266

https://www.linkedin.com/posts/sahil-parmar-4099391bb_google-colaboratory-activity-6805454270809415680-c71D

1 like 0 dislike
by (113 points)

import pandas as pd

data = pd.read_csv("E:\python practice data\StudentHoursScores.csv")

# In[3]:

print(data.head())

print(data.tail())

print(data.shape)

print(data.dtypes)

print(data.columns)

print(data.corr())

# In[4]:

data.describe()

# In[5]:

type(data)

# In[13]:

x = data.iloc[:,0:-1]

y = data.iloc[:,-1]

print(x.head())

print(y.head())

print(x.shape,y.shape)

# In[14]:

from sklearn.model_selection import train_test_split

x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=.2,random_state=1)

print(x_train.shape)

print(x_test.shape)

print(y_train.shape)

print(y_test.shape)

# In[15]:

from sklearn.linear_model import LinearRegression

std_model  = LinearRegression()

std_model.fit(x_train,y_train)

# In[17]:

y_pred = std_model.predict(x_test)

print(y_pred)

print(y_test)

print(x_test)

# In[22]:

print(std_model.coef_)

print(std_model.intercept_)

from sklearn.metrics import r2_score, mean_squared_error

print("accuracy is: ", r2_score(y_test,y_pred))

print(mean_squared_error(y_test,y_pred))

# In[24]:

vif = 1/1-(r2_score(y_test,y_pred))

vif

coef:  [9.9073553]
intercept: 0.2569567372371395
accuracy is:  0.9311770139374417
mean squared error: 3.7164412473781487

Best Online Learning Opportunities

UDEMY::  Attend All Udemy Courses in Just INR 450[Coupon]
Coursera:: Join For FREE
UDACITY (Best Nanodegrees)::

Machine Learning Engineer || Artificial Intelligence
Data Scientist

3.3k questions

7.1k answers

395 comments

4.5k users

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...