【发布时间】:2016-06-20 14:28:55
【问题描述】:
我正在尝试将培训和测试错误与相应的test_size 存储在字典中,因为我想创建一个测试/培训错误图。不幸的是 for 循环不起作用。有谁知道我做错了什么? (而不是将它们存储在 pandas df 中的字典也可以)。
array = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
dicto = {}
for i in array:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = i)
clf.fit(X_train,y_train)
test = clf.score(X_test, y_test)
train = clf.score(X_train, y_train)
dicto[i, test, train]
print(dicto)
我收到以下错误:
KeyError: (0.1, 0.89473684210526316, 0.91176470588235292)
【问题讨论】:
-
你希望你的键和值是什么?
-
我想我得到了一个键错误,因为我请求了一个不在字典中的字典对象..
-
发布我们可以使用预期输入和输出运行的最小脚本。您正在查找一个不存在的密钥。
-
我想要一个键,即我的 test_size,值是测试和训练变量(这些是我的测试和训练错误)
-
你是对的 Bahrom。我想将它们添加到字典中.. 但它不是这样工作的
标签: python dictionary pandas scikit-learn