随机森林套用代码报错
from sklearn import cross_validationfrom 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'