Posts

Showing posts with the label Linear Regression

Showing Relationship between X and Y Values using Linear Regression Line in Python - Machine Learning

Image
Importing Libraries for this project import numpy as np  import pandas as pd from sklearn.linear_ model import LinearRegression  import matplotlib.pyplot as plt  Importing Data file into python code  filepath = 'PythonRegressionPracticeWorkbook.csv'  data = pd.read_csv(filepath)  print(data)  Assigning Input / Independent Column to X and assigning dependent / Output Column to Y variables  x = data[['Square Feet']]  y = data['Price']  Training the X and Y variables using Linear Regression Model to find how X affects Y model = LinearRegression()  model.fit(x,y)  Checking Slope, Intercept values from the learned Model slope = model.coef_[0]  intercept = model.intercept_  print("Slope:", slope)  print("Intercept:",intercept)  Predicting the output value / Y value for each X value / input value  y_pred = model.predict(x)  Plotting Scatter plot with Regression Line to show both Original X and Y values, P...

Linear Regression in Python to find Relationship between two columns - Code Explanation

import numpy as np Importing Numpy Library and giving it a short name as np import pandas as pd Importing pandas librabry and giving it a short name as pd from sklearn.linear_model import LinearRegression Importing Linear Regression Model from Sckit Learn Library. import matplotlib.pyplot as plt Importing Matplotlib library for making graphs and giving a short name as plt filepath = r'C:\Users\kkumaran\Downloads\Python - Regression Practice Workbook.xlsx' This is the Location of the Excel File in my Computer. I am importing Excel file into variable called "filepath" data = pd.read_excel(filepath,sheet_name='Linear Regression Practice 1') This code reads the excel file using pandas library and load the sheet Linear Regression Practice 1 into a dataframe called "data". Now your excel data is inside python. print(data) This show the dataset for you to verify. x = data[['Square Feet']] I am creating a variable called x and putting Square feet Col...

Linear Regression in Python to find Relationship between two columns - Formula Explanation

Image
Have you ever noticed in your Life that One thing affects another thing? If Someone Study Well, they score High Marks If Someone Eat Well, they gain Weight If Someone Sleep Well, they remain Younger Doing One thing affects Another thing. But, How much? How much One thing affects Another thing? 50%? 90%? or only 20%? To find that, we use Linear Regression method. Linear Regression Method uses this Formula:  Y = MX + C What is Y: Y is also called as 'Dependent' Value. Because it depends on X. If X Changes, Y Changes. So Y is Dependent value. So we always assign Dependent Column to Variable Y is Python. example: We have 2 Columns. "Study Hours" and "Exam Score" Now, does the Exam score increase when Study Hour increase? YESS! If Someone study more time, their score will obviously increase. So 'Exam Score' Column is depending on 'Study Hours' Column, Right? We call 'Exam Score' Column as Y Column. Because, it is dependent on another Colum...