# Simple Linear Regression-----How to make my model more efficient??

I am working on a simple linear regression model,

This is my Python code :

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

X=dataset.iloc[:,:-1].values
Y=dataset.iloc[:,1].values

from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=1/3)

from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,Y_train)

plt.scatter(X_train,Y_train,color='red')
plt.plot(X_train,regressor.predict(X_train),color='blue')
plt.title('X vs Y(Training Set)')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()

plt.scatter(X_test,Y_test,color='red')
plt.plot(X_train,regressor.predict(X_train),color='blue')
plt.title('X vs Y(Test Set)')
plt.xlabel('X')[enter image description here][1]
plt.ylabel('Y')
plt.show()


This is my plot of Training Set Training Set This is my plot of Test Set Test Set

How can I increase the efficiency of my ML model??? This is my first ML model, so all suggestions are welcome. Thanks in Advance

• You can add images directly too... – Aditya May 28 '18 at 8:16
• Can you host the data somewhere so that we can access it please? – JahKnows May 28 '18 at 9:30

You cannot really do much: the fit of the regressor is optimum, therefore it is the best that the algorithm can do given these points. What you can do, is change the weights of individual points of the dataset using the sample weight parameter of

LinearRegression.fit(X, y, sample_weight)
`

method, to "attract" the line towards them and see how this affects the accuracy.

I would not expect notable difference because your data do not follow a linear pattern.

Your data does not follow a linear trend. For this reason, your linear model has clear limitations. In order to overcome them, you can build a nonlinear model. With the few data that you have, I advise you to do LOESS. As your training data seems to be able to follow a cubic trend, you can also try with polynomial regression of degree 3.

Bear in mind that the distribution of your train and test data is very different, so you are very likely to overfit. For this reason, it might not be the best data to get started with ML.

• Did I answer your question? – David Masip May 29 '18 at 7:32