Showing Relationship between X and Y Values using Linear Regression Line in Python - Machine Learning
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...