GridSearchCV 出现 ValueError: 决策树回归器不支持连续值。

4

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

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)

这个问题是因为reg.fit(X, y)中的continuous不被支持,但我不明白原因。请问这是什么原因,我漏掉了什么?

1个回答

7
那是因为这一行代码:
scoring_function = make_scorer(fbeta_score, beta=2)

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

你正在进行的是回归,如下所示:

regressor = DecisionTreeRegressor()

来自文档

在此输入图片描述


这是一个关于it技术的翻译,具体内容请参考上述链接和图片。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接