python - Pandas 返回:ValueError: Unknown label type: 'continuous'
问题描述
我在使用 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'
解决方案
分类器将一组示例分类为离散的类(即,它分配与 K 个类中的一个对应的标签)。如果您的目标(y
变量的内容)是连续的(例如介于 0 和 1 之间的浮点数),则决策树不知道如何处理它。
您有 2 个解决方案:
- 您的问题是分类任务,您需要对目标变量进行建模,使其代表类别而不是连续变量
- 您的问题不是分类任务,而是回归任务,您需要使用适当的模型(例如
DecisionTreeRegressor
)
推荐阅读
- azure - 使用 ARM 模板动态启用/禁用部署 Azure Function
- python - 字符串匹配并在 Pandas 中获得超过 1 列
- c++ - 是否有解析属性值的工具?
- javascript - extjs 3.4.0 - 如何过滤读取 JSON 的存储
- ios - 如何将字符传说显示为两行?
- swift - 如何更新 MVVM 中的变量?
- javascript - javascript中不同对象数组的一种排序函数
- ios - 如何将企业 iOS App 分发到特定的 iPhone 设备类型
- android - Android Oreo 通知显示在状态栏中,但不显示在点通知中
- makefile - 如何编译 unison 的静态版本