Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
0 like 0 dislike
3.7k views
in Python Programming by Goeduhub's Expert (2.1k 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

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

3.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

2 Answers

0 like 0 dislike
1 like 0 dislike
by (112 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

3.3k questions

7.1k answers

393 comments

4.5k users

Related questions

 Goeduhub:

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