0
$\begingroup$

just a short question, which may be easy to solve for most of you. I am just starting with linear regression models in python. Therefore I made a simple multiple linear regression with training and test data. If you have a look into the trained model, everything looks fine - but if I want to use it for my testing data the following problem occurs.

All predicted Values are constantly below the true values - what could be the reason for this issue and how to handle this?

Enclosed the code:

x = features_m_2007
y = target_m_2007

def split_data(data, split_date):
    return data[data.index <= split_date].copy(), \
           data[data.index >  split_date].copy()

train_x, test_x = split_data(x, '2017-01-01')
train_y, test_y = split_data(y, '2017-01-01')

Regression_model = LinearRegression()
Regression_model.fit(train_x, train_y)
pred_y = Regression_model.predict(test_x)

MIN=0
MAX=150
MAX=np.min([MAX,len(test_y)])
x_vals=np.arange(MIN,MAX)
y_pred_vals=pred_y
y_test_vals=test_y
plt.figure(figsize=(26,10))
plt.plot(x_vals,y_pred_vals,'ro--',label="predicted")
plt.plot(x_vals,y_test_vals,'bo--',label="true")
plt.xticks(x_vals, test_y.index)
plt.grid(True)
plt.legend()
plt.show()

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ It looks like you made a mistake, and without seeing the code and maybe also the data, chances are nobody here can tell you which one. $\endgroup$ – Lewian Jun 11 at 12:47
  • $\begingroup$ @Lewian Thanks for the hint, I attached the code $\endgroup$ – Hannes Jun 11 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.