我正在使用决策树分类器。 我的X(特征变量)看起来像一个字典:
{'location05': ['4425', '4436', '4425'],
'location04': ['425', '4436', '4425','232'],
'location03': ['4425', '4436'] }
我的Y(目标变量)只是二进制 现在,当我把它们放入适合的方法时,我收到了错误:
float()参数必须是字符串或数字
有任何帮助吗?
我的代码如下:
from sklearn.tree import DecisionTreeClassifier
import numpy as np
import csv
from sklearn import tree
reader = csv.reader(open("data.csv", "rb"))
next(reader, None)
location_dict = dict()
target = []
feat = []
for line in reader:
feat.append(line[2])
target.append(line[3])
if line[0] in location_dict:
location_dict[line[0]].append(line[2])
else:
location_dict[line[0]] = [line[2]]
X = location_dict
y = target
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)