【发布时间】:2021-01-21 04:10:28
【问题描述】:
我在使用 pandas 和 sklearn 进行机器学习时遇到了问题。我的问题是
ValueError:未知标签类型:'连续'
我试过了
model = sklearn.tree.DecisionTreeClassifier()
model.fit(X, y)
它返回此错误:
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'
【问题讨论】:
-
现在知道
X和y包含什么内容可能会有所帮助?也许添加一个简短的例子来帮助理解它们的结构。 -
你需要检查你的目标是什么,很可能它是浮动的。在这种情况下,您可能会考虑切换到回归或检查在类似情况下已经在 SO 上给出的其他众多答案。
标签: python scikit-learn