Linear Regression Prediction of future values in Python using Scatter Plot - Machine Learning


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], 'Calls_Made': [105, 150, 180], 'Meetings_Conducted': [10, 14, 18]})


Predicting the Output for new Inputs using Model

Predicted_y = model.predict(new_data) 

print(Predicted_y)


Showing both the Original Input and Output as well as New Input and predicted output, in a Scatter plot graph

pyplot.figure(figsize=(15,8)) 

pyplot.scatter(data['Experience_Years'],data['Sales_Amount'], color='blue', label='Actual Sales') 

pyplot.scatter(new_data['Experience_Years'],Predicted_y,color='red',label='Predicted Sales') 

pyplot.legend() 

pyplot.xlabel('Experience Years') 

pyplot.ylabel('Sales Amount') 

pyplot.show()





Comments

Popular posts from this blog

What is Artificial Intelligence? What is Machine Learning? What is Data Science? how they are related to each other?

Linear Algebra - What is it?

What is a Python Library?