[英]Pandas returns this: ValueError: Unknown label type: 'continuous'
I am having trouble when using pandas and sklearn for machine learning.我在使用 pandas 和 sklearn 进行机器学习时遇到了麻烦。 My problem is我的问题是
ValueError: Unknown label type: 'continuous' ValueError:未知标签类型:“连续”
I tried我试过
model = sklearn.tree.DecisionTreeClassifier()
model.fit(X, y)
and it returns this error:并返回此错误:
ValueError Traceback (most recent call last)
<ipython-input-45-3caead2f350b> in <module>
----> 1 model.fit(ninp, out)
c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\sklearn\tree\_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
888 """
889
--> 890 super().fit(
891 X, y,
892 sample_weight=sample_weight,
c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\sklearn\tree\_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
179
180 if is_classification:
--> 181 check_classification_targets(y)
182 y = np.copy(y)
183
c:\users\user\appdata\local\programs\python\python38-32\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'
A classifier classifies a set of examples into discrete classes (ie it assigns a label corresponding to one of K classes).分类器将一组示例分类为离散类(即,它分配对应于 K 个类之一的标签)。 If your target (the content of your y
variable) is continuous (for example a float ranging between 0 and 1), then the decision tree does not know what to do with it.如果您的目标( y
变量的内容)是连续的(例如介于 0 和 1 之间的浮点数),那么决策树不知道如何处理它。
You have 2 solutions:您有 2 个解决方案:
DecisionTreeRegressor
)您的问题不是分类任务,而是回归任务,您需要使用适当的模型(例如DecisionTreeRegressor
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.