I have a dataset that contains 7 features. Values are not too large. I trained scikit-learn's RandomForestRegressor
for predicting the target variable. The $R^2$ score turns out to be something aroung 0.2, but when I first scale x_train
and x_test
using scitkit-learn's MinMaxScaler
, the $R^2$ score drops to 0.11. I heard decision trees are not affected by scaling so it is not necessary to scale the data. My question is why would the score drop so much if trees are not affected by scaling?
This is without scaling
regressor = RandomForestRegressor()
predictions = fit_predict(X_train, y_train, X_test)
evaluate(y_test, predictions)
This is with scaling
scaler = preprocessing.MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.fit_transform(X_test)
regressor = RandomForestRegressor()
predictions = fit_predict(X_train_scaled, y_train, X_test_scaled)
evaluate(y_test, predictions)
transform
to scale your test data instead offit_transform
$\endgroup$