use*_*752 5 python scikit-learn
我正在使用 sklean 14.1 并且我希望返回 partial_plot 值而不是使用plot_partial_dependence返回一个数字,所以我想也许我可以使用partial_dependence,但这里有一些麻烦。
似乎partial_dependence只需要两个功能,而我只想要一个功能的值。
当我修改 scikit-learn 网站提供的示例代码时:(将 target_feature = (1,2) 更改为 target_feature = (1)),它抱怨:
*** ValueError: need more than 1 value to unpack
Run Code Online (Sandbox Code Playgroud)
这是代码:
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.ensemble.partial_dependence import plot_partial_dependence
from sklearn.ensemble.partial_dependence import partial_dependence
from sklearn.datasets.california_housing import fetch_california_housing
cal_housing = fetch_california_housing()
X_train, X_test, y_train, y_test = train_test_split(cal_housing.data,
cal_housing.target,test_size=0.2,
random_state=1)
names = cal_housing.feature_names
clf = GradientBoostingRegressor(n_estimators=100, max_depth=4,
learning_rate=0.1, loss='huber',random_state=1)
clf.fit(X_train, y_train)
target_feature = (1)
pdp, (x_axis, y_axis) = partial_dependence(clf, target_feature, X=X_train, grid_resolution=50)
Run Code Online (Sandbox Code Playgroud)
在源代码中,它说:
Run Code Online (Sandbox Code Playgroud)target_variables : array-like, dtype=int The target features for which the partial dependecy should be computed (size should be smaller than 3 for visual renderings).
谁能帮我弄清楚我做错了什么?或者帮我提取我需要的一个特征的部分依赖值?
非常感谢!
| 归档时间: |
|
| 查看次数: |
873 次 |
| 最近记录: |