我正在尝试用相应的 test_size
在字典中存储培训和测试错误,因为我想创建一个测试/训练错误。不幸的是,for循环不起作用。有人知道我在做什么错吗?(而不是将它们存放在熊猫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)
您永远不会在字典中分配值:
dicto[i, test, train] # This is trying to lookup a key of (i, test, train), which doesn't exist yet.
而是尝试一下:
dicto[i] = (test, train) # map test and train variables to test_size, which is i
是,您想要什么?
dicto[i] = test, train