Question: Use this worksheet to complete your lab activity. Submit it to the applicable assignment submission folder when complete. Deliverable: A word document showing and explaining
Use this worksheet to complete your lab activity. Submit it to the applicable assignment submission folder when complete.
Deliverable:
A word document showing and explaining the results of the linear regression model
Using the Weather.csv dataset
Start by exploring the Weather.csv data using the describe function from the last module
You will need to import the Weather.csv dataset and the following libraries:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as seabornInstance
from sklearn.modelselection import traintestsplit
from sklearn.linearmodel import LinearRegression
from sklearn import metrics
matplotlib inline
Next plot data points on a D graph to check for a relationship manually using the code below:
dfplotx'MinTemp', y'MaxTemp', styleo
plttitleMinTemp vs MaxTemp'
pltxlabelMinTemp
pltylabelMaxTemp
pltshow
Plot the MaxTemp data using the code below:
pltfigurefigsize
plttightlayout
seabornInstance.distplotdfMaxTemp
Divide the data into attributes and labels by using the following:
X dfMinTempvalues.reshape
y dfMaxTempvalues.reshape
Split the data into training and testing sets using a training and testing split using the code below:
Xtrain, Xtest, ytrain, ytest traintestsplitX y testsize randomstate
Train the algorithm using linear regression following the code below:
regressor LinearRegression
regressor.fitXtrain, ytrain #training the algorithm
Print the intercepts and slope using the following:
#To retrieve the intercept:
printregressorintercept
#For retrieving the slope:
printregressorcoef
Use the test data to see how accurately the model works using the following:
ypred regressor.predictXtest
Compare the actual output values to the predicted values using the following:
compare pdDataFrameActual: ytest.flatten 'Predicted': ypred.flatten
compare
Create a scatter plot with a line portraying the model to evaluate the model visually using the following:
pltscatterXtest, ytest, color'gray'
pltplotXtest, ypred, color'red', linewidth
pltshow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
