Reputation: 11
I'm working on a gradient boosting model and wanted to apply GridSearchCV
to it but I am getting this error: ValueError: Unknown label type: 'continuous'
. My data is all continuous. All of the suggestions I have seen have been to transform my y_train
using LabelEncoder()
but this is a regression problem so I don't see the need in doing that. I am using the Boston Housing dataset from Kaggle if that helps at all.
Also, I have used GridSearchCV
on a random forest model with the same data and it works. Not sure why it works on one but not the other.
# doesn't work for this one
from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor
from sklearn.model_selection import GridSearchCV
gbc = GradientBoostingClassifier()
parameters = {
"n_estimators" : [5 , 50, 250, 500],
"max_depth" : [1, 3, 5, 7, 9],
"learning_rate" : [0.01, 0.1, 1, 10, 100]
}
cv = GridSearchCV(gbc, parameters, cv=5)
cv.fit(X_train, y_train.values.ravel())
# Works for this one
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import GridSearchCV
tree = DecisionTreeRegressor()
model = GridSearchCV(tree, param_grid={'max_depth': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}, cv=5)
model.fit(X_train, y_train)
# get metrics
print(model.best_params_)
print(model.best_score_)
Upvotes: 1
Views: 483
Reputation: 945
You can't use GradientBoostClassifier()
for regression tasks. As the name suggests this model is only for classification tasks. What you need instead is the GradientBoostRegressor(). Seems like you imported both but just called the wrong one.
(In the Decision Tree case you correctly specified DecisionTreeRegressor()
and not DecisionTreeClassifier()
)
Upvotes: 0