Posts

Showing posts with the label Linear Regression Python Coding

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 Prediction of future values in Python using Scatter Plot - Machine Learning

Image
We are Importing Necessary Libraries for this project  import pandas as pandas  import numpy as numpy  import matplotlib.pyplot as pyplot  from sklearn.linear_model import LinearRegression Importing Data using Pandas library and creating table dataframe data = pandas.read_csv('python_linear_regression_prediction_python_data.csv')  print(data) Assigning Input / Independent columns to X variable and Assigning Output / Dependent Column to Y Variable x = data[['Experience_Years','Calls_Made','Meetings_Conducted']]  y = data['Sales_Amount'] Asking Linear Regression Model to learn data from X and Y variables model = LinearRegression() model.fit(x,y) Printing Coefficient and Intercept to check their values print("Coefficient:",model.coef_)  print("Intercept",model.intercept_) Adding New Inputs / Independent Values to predict Output / Dependent values new_data = pandas.DataFrame({ 'Experience_Years': [8, 12, 15], '...

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...