Skip to content Skip to sidebar Skip to footer

How To Inverse Transform Regression Predictions After Lasso And Robustscalar?

I'm trying to figure out how to unscale my data (presumably using inverse_transform) for predictions after using RobustScalar and Lasso. The data below is just an example. My actua

Solution 1:

You cannot use the same tranformer object for both X and y. In your snippet, your transformer is for X, which is 2D, thus you get an error when transforming the result of your prediction, which is 1D. (Actually you are lucky to get an error; if your X was 1D, you would get nonsense).

Something like this should work:

transformer_x = RobustScaler().fit(X_train)
transformer_y = RobustScaler().fit(y_train) 
X_rtrain = transformer_x.transform(X_train)
y_rtrain = transformer_y.transform(y_train)
X_rtest = transformer_x.transform(X_test)
y_rtest = transformer_y.transform(y_test)

#Fit Train Model
lasso = Lasso()
lasso_alg = lasso.fit(X_rtrain,y_rtrain)

train_score =lasso_alg.score(X_rtrain,y_rtrain)
test_score = lasso_alg.score(X_rtest,y_rtest)

print ("training score:", train_score)
print ("test score:", test_score)

example = [[10,100]]
transformer_y.inverse_transform(lasso.predict(example).reshape(-1, 1))

Post a Comment for "How To Inverse Transform Regression Predictions After Lasso And Robustscalar?"