| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2228 人关注过本帖
标题:随机森林套用代码报错
只看楼主 加入收藏
澄然之上
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-6-3
收藏
 问题点数:0 回复次数:0 
随机森林套用代码报错
from sklearn import cross_validation
from sklearn.ensemble import RandomForestClassifier
predictors =["age","Engineering age","Overall or management","Smoking type","Previous engineering relevance",
            "car","Face stiff","Accounts receivable","The probability of late","Investment proportion",
            "Color of skin","The subcontract hierarchy"]
alg = RandomForestClassifier(random_state=1, n_estimators=10, min_samples_split=2, min_samples_leaf=1)
kf = KFold(HHFB_info.shape[0], n_folds=2, random_state=1)
predictions = []
for train, test in kf:
    train_predictors = ( HHFB_info[predictors].iloc[train,:])
    train_target = HHFB_info["Performance evaluation"].iloc[train]
    alg.fit(train_predictors, train_target)
    test_predictions = alg.predict(HHFB_info[predictors].iloc[test,:])
    predictions.append(test_predictions)
报错
ValueError                                Traceback (most recent call last)
<ipython-input-10-7301796deada> in <module>()
     10     train_predictors = ( HHFB_info[predictors].iloc[train,:])
     11     train_target = HHFB_info["Performance evaluation"].iloc[train]
---> 12     alg.fit(train_predictors, train_target)
     13     test_predictions = alg.predict(HHFB_info[predictors].iloc[test,:])
     14     predictions.append(test_predictions)

E:\python\lib\site-packages\sklearn\ensemble\forest.py in fit(self, X, y, sample_weight)
    271         self.n_outputs_ = y.shape[1]
    272
--> 273         y, expanded_class_weight = self._validate_y_class_weight(y)
    274
    275         if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:

E:\python\lib\site-packages\sklearn\ensemble\forest.py in _validate_y_class_weight(self, y)
    469
    470     def _validate_y_class_weight(self, y):
--> 471         check_classification_targets(y)
    472
    473         y = np.copy(y)

E:\python\lib\site-packages\sklearn\utils\multiclass.py in check_classification_targets(y)
    170     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
    171                       'multilabel-indicator', 'multilabel-sequences']:
--> 172         raise ValueError("Unknown label type: %r" % y_type)
    173
    174

ValueError: Unknown label type: 'continuous'
搜索更多相关主题的帖子: 随机 报错 type python lib 
2018-06-03 17:11
快速回复:随机森林套用代码报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046270 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved