gpt4 book ai didi

python - GridSearchCV 给出 ValueError : continuous is not supported for DecisionTreeRegressor

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:48 24 4
gpt4 key购买 nike

我正在学习机器学习并完成波士顿房价预测任务。我有以下代码:

from sklearn.metrics import fbeta_score, make_scorer
from sklearn.model_selection import GridSearchCV

def fit_model(X, y):
""" Tunes a decision tree regressor model using GridSearchCV on the input data X
and target labels y and returns this optimal model. """

# Create a decision tree regressor object
regressor = DecisionTreeRegressor()

# Set up the parameters we wish to tune
parameters = {'max_depth':(1,2,3,4,5,6,7,8,9,10)}

# Make an appropriate scoring function
scoring_function = make_scorer(fbeta_score, beta=2)

# Make the GridSearchCV object
reg = GridSearchCV(regressor, param_grid=parameters, scoring=scoring_function)

print reg
# Fit the learner to the data to obtain the optimal model with tuned parameters
reg.fit(X, y)

# Return the optimal model
return reg.best_estimator_

reg = fit_model(housing_features, housing_prices)

这给了我 ValueError: continuous is not supported for the reg.fit(X, y) 行,我不明白为什么。这是什么原因,我在这里缺少什么?

最佳答案

那是因为这条线:

scoring_function = make_scorer(fbeta_score, beta=2)

这会将评分指标设置为 fbeta ,用于分类任务!

您在这里进行回归,如下所示:

regressor = DecisionTreeRegressor()

来自 the docs

enter image description here

关于python - GridSearchCV 给出 ValueError : continuous is not supported for DecisionTreeRegressor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47659998/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com