【发布时间】:2013-01-25 11:01:31
【问题描述】:
我正在尝试在 scikit-learn 中使用一种算法来根据大量输入预测输出。我似乎收到了错误“太多索引”返回,但不知道为什么。
CSV 文件训练:
1.1 0.2 0.1 0 0.12 0.1
1.4 0.2 0.1 0.1 0.14 0.1
0.1 0.1 0.1 0 0.26 0.1
24.5 0.1 0 0.1 0.14 0.1
0.1 0.1 0.1 0 0.25 0.1
代码:
fileCSVTraining = genfromtxt('TrainingData.csv', delimiter=',', dtype=None)
#Define first 6 rows of data as the features
t = fileCSVTraining[:, 6:]
#Define which column to put prediction in
r = fileCSVTraining[:, 0-6:]
#Create and train classifier
x, y = r, t
clf = LinearSVC()
clf = clf.fit(x, y)
#New data to predict
X_new = [1.0, 2.1, 3.0, 2.4, 2.1]
b = clf.predict(X_new)
错误:
t = fileCSVTraining[:, 6:]
IndexError: too many indices
【问题讨论】:
-
我认为如果您尝试在二维中索引一维数组,则会发生此错误,但不完全确定
-
也许不是问题,但您在读取文件时使用
delimiter=',',虽然值是用空格分隔的 -
好像和CSV文件中的小数点有关
标签: python numpy scikit-learn