0% found this document useful (0 votes)
240 views3 pages

Linear Regression Tutorial Notebook

The document describes using a linear regression model to predict car acceleration (acc) based on year. It loads and splits a dataset into training and test sets. A simple linear regression model is fitted to the training set and used to predict the test set values, which are then visualized along with the training data on scatter plots. The model is used to predict acceleration for given years.

Uploaded by

vijaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views3 pages

Linear Regression Tutorial Notebook

The document describes using a linear regression model to predict car acceleration (acc) based on year. It loads and splits a dataset into training and test sets. A simple linear regression model is fitted to the training set and used to predict the test set values, which are then visualized along with the training data on scatter plots. The model is used to predict acceleration for given years.

Uploaded by

vijaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9/19/2019 Copy_of_Linear_Regression (1) (1).

ipynb - Colaboratory

from google.colab import drive


drive.mount('/gdrive')
%cd /gdrive

Drive already mounted at /gdrive; to attempt to forcibly remount, call drive.mount("/g


/gdrive

New Section
ls

'My Drive'/

cd /gdrive/My Drive/Colab Notebooks/comp

/gdrive/My Drive/Colab Notebooks/comp

Double-click (or enter) to edit

ls

comp1.csv 'Copy_of_Linear_Regression (1) (1).ipynb'

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#import data set


dataset= pd.read_csv('comp1.csv')
X= dataset.iloc[:,:-1].values
Y= dataset.iloc[:,1].values

#Splitting the data


from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test= train_test_split(X,Y,test_size= 1/3)

#Fitting Simple Linear Regression ipynb


#This is called Model
from sklearn.linear_model import LinearRegression
regressor= LinearRegression()
regressor.fit(X_train,Y_train)

LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

##Predicting the test results


https://colab.research.google.com/drive/1BTw1H4zczAjF2BhhX2fsV5jSAM4OrzOG#scrollTo=P0tTbPSioHlN&printMode=true 1/3
9/19/2019 Copy_of_Linear_Regression (1) (1).ipynb - Colaboratory
Y_pred= regressor.predict(X_test)

#Visualising the training set Results

plt.scatter(X_train, Y_train, color='red')


plt.plot(X_train, regressor.predict(X_train), color='blue')
plt.title('acc Vs year')
plt.xlabel('year')
plt.ylabel('acc')
plt.show()
plt.scatter(X_test, Y_test, color='red')
plt.plot(X_test, regressor.predict(X_test), color='blue')
plt.title('acc Vs. year')
plt.xlabel('year')
plt.ylabel('acc')
plt.show()

print(regressor.predict([[1002]]))

[62.74409214]

a=int(input("What is the acc? "))


print('The year is', regressor.predict([[a]]))

https://colab.research.google.com/drive/1BTw1H4zczAjF2BhhX2fsV5jSAM4OrzOG#scrollTo=P0tTbPSioHlN&printMode=true 2/3
9/19/2019 Copy_of_Linear_Regression (1) (1).ipynb - Colaboratory

What is the acc? 123


The year is [62.95891594]

https://colab.research.google.com/drive/1BTw1H4zczAjF2BhhX2fsV5jSAM4OrzOG#scrollTo=P0tTbPSioHlN&printMode=true 3/3

You might also like