Python ValueError:未知标签类型:'连续'

问题描述 投票:0回答:1

我是这里的初学者,我正在努力让我的生活能够理解这个与流程相同的其他堆栈与我有同样的问题.Logistic Regression:Unknown label type: 'continuous'

这是我下面的机器学习代码,shell输出给我ValueError:未知标签类型:'continuous'

我想我明白我是“将浮点数传递给一个分类器,它将分类值作为目标向量。如果将它转换为int,它将被接受作为输入(尽管如果这是正确的方法,这将是有问题的)。最好通过使用scikit的labelEncoder函数转换你的训练分数“

有人可以给我一个关于如何将scikit的labelEncoder函数合并到我的代码中的提示吗?这是在陈述分类器X&y之前实现的吗?无论我在尝试什么,我都在做错事。谢谢

import numpy as np
from sklearn import preprocessing, cross_validation, neighbors, utils
import pandas as pd

df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\WB             
Data\\WB_RTU6data.csv', index_col='Date', parse_dates=True)

print(df.head())
print(df.tail())
print(df.shape)
print(df.columns)
print(df.info())
print(df.describe())


X = np.array(df.drop(['VAV6znt'],1))
df.dropna(inplace=True)

y = np.array(df['VAV6znt'])


accuracies = []

X_train, X_test, y_train, y_test =             
cross_validation.train_test_split(X,y,test_size=0.50)

clf = neighbors.KNeighborsClassifier(n_neighbors=50)
clf.fit(X_train, y_train)
accuracy = clf.score(X_test, y_test)

print(accuracy)

enter image description here enter image description here

python python-3.x machine-learning scikit-learn data-science
1个回答
2
投票

由于您的VAV6znt列是浮点数,这意味着您正在尝试从数据中估算数值。这使它成为一个回归问题,你使用的是KNeighborsClassifier这是一个分类估算器。

尝试使用KNeighborsRegressor或其名称中包含Regressor的任何其他估算器。

如上所述将它们转换为int将起作用,但不会产生良好的结果,因为这意味着您的数据中有许多类,因为它们是唯一的内容,这显然是错误的。

© www.soinside.com 2019 - 2024. All rights reserved.