【问题标题】:How to correct Value Error: Unknown label type 'continuous'如何更正值错误:未知标签类型“连续”
【发布时间】:2020-01-22 08:35:57
【问题描述】:

我收到一个值错误,我不知道如何解决。

from sklearn.ensemble import RandomForestClassifier
forest=RandomForestClassifier(n_estimators=50,
                         criterion='entropy',
                         min_samples_split=20,
                         min_samples_leaf=15,
                         max_features="sqrt",
                         max_leaf_nodes=12,
                         random_state=0)

forest.fit(X_train, y_train)
print("Acurracy on Training Set: {:.3f}".format(forest.score(X_train, 
y_train)))
print("Accuracy on Test Set: {:.3f}".format(forest.score(X_test, 
y_test)))

import numpy as np
import matplotlib.pyplot as plt
importances=forest.feature_importances_

这是导致错误的行。 ---> 17 森林.fit(X_train, y_train)

这是完整的错误信息: ValueError Traceback(最近的 称呼 最后的) 在 15 随机状态=0) 16 ---> 17 森林.fit(X_train, y_train) 18 print("训练集的准确性: {:.3f}".format(forest.score(X_train, y_train))) 19 print("测试集的准确率:{:.3f}".format(forest.score(X_test, y_test)))

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

~\Anaconda3\lib\site-packages\sklearn\ensemble\forest.py in 
_validate_y_class_weight(self, y)
    476 
    477     def _validate_y_class_weight(self, y):
--> 478         check_classification_targets(y)
    479 
    480         y = np.copy(y)

~\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in 
check_classification_targets(y)
    167     if y_type not in ['binary', 'multiclass', 'multiclass- 
multioutput',
    168                       'multilabel-indicator', 'multilabel- 
sequences']:
--> 169         raise ValueError("Unknown label type: %r" % y_type)
    170 
    171 


ValueError: Unknown label type: 'continuous'

【问题讨论】:

标签: python-3.x valueerror continuous


【解决方案1】:

问题似乎来自forest.fit(X_train, y_train),请检查您传递给fit 方法的参数,因为它们似乎属于错误类型。

【讨论】:

  • 这不是一个答案......你应该在评论部分告诉这些
  • @SamanSalehi 我没有能力发表评论。 @user11136504 问题似乎来自 forest.fit(X_train, y_train) 请检查您传递给 fit 方法的参数,因为它们似乎属于错误类型。
  • 所以在这个级别,我认为这是@stackoverflow 资格系统中的一个错误......干杯伙伴
猜你喜欢
  • 2017-07-16
  • 2018-01-20
  • 1970-01-01
  • 2020-05-01
  • 2017-08-29
  • 2018-12-10
  • 2022-01-24
  • 2018-02-15
  • 2021-07-17
相关资源
最近更新 更多