0
$\begingroup$

So im using a dataset for Wine Prediction where im using Linear Regression model to predict the prices. These are the steps i'm using:

# SPLITTING THE DATASET

Y = data['price']
X = data.loc[:,data.columns != 'price']  # Selecting all the columns except 'price'

X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size=0.3)


# SCaling data
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Feature selection using SelectFromModel
estimator=LinearRegression()
selector = SelectFromModel(estimator)
selector.fit(X_train_scaled, Y_train)
X_train_selected = selector.transform(X_train_scaled)
X_test_selected = selector.transform(X_test_scaled)

LinReg = LinearRegression()
LinReg.fit(X_train_selected,Y_train)
y_pred = LinReg.predict(X_test_selected)

Calculating the errors

from sklearn.metrics import mean_squared_error,\
                            mean_absolute_percentage_error,\
                            r2_score


    # calculate errors
    MSE = mean_squared_error(Y_test, y_pred)  #MSE
    RMSE = mean_squared_error(Y_test, y_pred,squared=False) #RMSE
    r2_score = r2_score(Y_test, y_pred)
    MAPE = mean_absolute_percentage_error(Y_test, y_pred)
    
    # report error
    print('Mse: ',MSE)
    print('RMse: ',RMSE)
    print('R2 score: ',r2_score)
print('MAPE :',MAPE)

And this is the output im getting: Mse: 13786.05720056847 RMse: 117.41404175211953 R2 score: 0.2762311918398678 MAPE : 1.1204660481401496

Are the numbers correct??

$\endgroup$

1 Answer 1

1
$\begingroup$

it's difficult to state whether these metrics are 'correct' or not. For some applications, it might be an apex of possibilities, for others it might be gibberish. In my view, in your case, MAPE could testify to the high quality of the model - a 1.1% error is not much in most applications. However, R2 is very low and could imply that the model is poor. I always recommend taking a look at the actual vs predicted chart (hist2d + scatter) and error vs input variables charts (it will also let you understand why the models works poorly)

Also, if you want to analyse a linear model correctly you should examine your input variables and analyse more conventional metrics. You can do it simply in Python using statsmodels instead of sklearn what I recommend.

Small additional caveat - you needn't have scaled your data - it doesn't matter for the linear model and just spoils interpretation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.