was*_*asd 3 python machine-learning decision-tree scikit-learn grid-search
我正在学习ML并完成波士顿房价预测的任务。我有以下代码:
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)
Run Code Online (Sandbox Code Playgroud)
这给我ValueError:reg.fit(X,y)行不支持continuous,并且我不明白为什么。这是什么原因,我在这里想念什么?
这是因为:
scoring_function = make_scorer(fbeta_score, beta=2)
Run Code Online (Sandbox Code Playgroud)
您正在此处进行回归,如下所示:
regressor = DecisionTreeRegressor()
Run Code Online (Sandbox Code Playgroud)
来自文档
| 归档时间: |
|
| 查看次数: |
1957 次 |
| 最近记录: |