-1

I have:


sc = StandardScaler()

training_x, training_y = loader.load_data('data/training.csv')
training_x = sc.fit_transform(training_x)
training_y = sc.fit_transform(training_y)

I am then running a Random Forest:

X_train, X_test, y_train, y_test = train_test_split(
    training_x, training_y, test_size=0.1)


regressor = RandomForestRegressor(n_estimators=5, random_state=0)
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)

But my y_pred are all scaled. How can I unscale it?

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • 1
    Random Forests are [invariant to monotonic transformations](https://stats.stackexchange.com/questions/255765/does-random-forest-need-input-variables-to-be-scaled-or-centered) of the variables - why call `StandardScaler` in the first place? Regardless of that, your `y_pred` scaling should have nothing to do with the scaling of your features. – pault Jun 24 '19 at 15:41
  • To elaborate on my second point above: in traditional linear modeling, you would scale your features so that they become more linearly related to the target variable. In other words, you're making your features "more like" the target so that when they are used for making predictions, the output will more closely match. Unless you scaled your `y_train`, there's no need to un-scale the `y_pred`. But for tree-based models, scaling is irrelevant. – pault Jun 24 '19 at 15:48
  • @pault can you please post your comment as an answer so I can accept? Classic XY problem – Shamoon Jun 24 '19 at 15:55
  • I don't know. Unless you can edit it with an [mcve] to make it more useful for a broader audience, I feel like you should probably just delete the question instead. – pault Jun 24 '19 at 15:58
  • I edited the question to make it more broad – Shamoon Jun 24 '19 at 16:31

1 Answers1

0
y_inverse = sc.inverse_transform(y_pred)

This will do it.

secretive
  • 2,032
  • 7
  • 16