【发布时间】:2014-08-30 20:22:43
【问题描述】:
from sklearn import tree
import numpy as np
from sklearn.preprocessing import Imputer
data = np.genfromtxt('bank_int.csv', delimiter = ' ')
sample = np.genfromtxt('test_sample.csv', delimiter = ' ')
output = []
count = 0
train_data = data[:,:-1]
target_data = data[:,-1:]
decision_tree = tree.DecisionTreeClassifier() #creation of decision tree
decision_tree = decision_tree.fit(train_data, target_data) #training the tree
for test in data:
output[count] = decision_tree.predict(sample) #testing the results
count += 1
#result = decision_tree.predict(sample)
print output[count]
【问题讨论】:
-
Traceback(最近一次调用最后一次):文件“classification.py”,第 21 行,在
output[count] = decision_tree.predict(sample) #testing 结果 IndexError: list assignment index超出范围 -
错误显示如上
-
输出是一个空列表
output = []所以你不能访问不存在的元素