Part 13 | Python Programming | Reading an Excel file and Creating a Simple Linear Regression Graph

preview_player
Показать описание
This is part 13 of a series of python coding I am having fun with and want to show others interested or stuck.

Code Example:

#We are going to read data from an Excel file and create a linear regression scatter plot

#First, import the necessary Modules
import numpy as np
import pandas as pd

#We are going to use an Excel file that contains SAT scores and GPA
#Now we need to read the Excel file that we have in our folder
#In windows, you can right click and select the copy as path option

#We must change the direction of our slashes to lean to the right in order to work correctly

#Check to see if we can read the Excel file
data

#Next we will use the a method from on of the imported libraries .describe()

#Now create our x and y and assign which column belongs to the one we want
y = data['GPA']
x1 = data['SAT']

#Now lets display our results with the use of a graph

#We can take it a step further and display the Ordinary Least Squares regression (OLS)
results = sm.OLS(y,x).fit()

#Now we can create the linear regression graph
yhat = 0.0017*x1 + 0.275

#python #pythonprogramming #pythontutorial #pythonforbeginners #shorts

Music: Paid Subscription with Wondershare Filmora
Рекомендации по теме
join shbcf.ru