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]
答案 0 :(得分:0)
欢迎使用StackOverflow。请修改stackoverflow指南中的“how to ask a good question”段落。
现在,您遇到的问题是因为您考虑使用不同的编程语言,可能是C语言。错误IndexError: list assignment index out of range
表明您正在索引不存在的元素。
而不是
for test in data:
output[count] = decision_tree.predict(sample) #testing the results
count += 1
尝试:
for test in data:
output.append(decision_tree.predict(sample)) #testing the results