【发布时间】:2016-10-25 20:13:38
【问题描述】:
首先,我定义了 X 和 y,下面部分描述了它们。
from sklearn import svm
from sklearn.cross_validation import train_test_split
X = array([[11.8, 0., 3.4, 5.7, 0., 5.7],
[33.4, 6.8, 0., 5.7, 0., 5.7],
[33.4, 6.8, 0., 5.7, 0., 5.7])
y = array([ 1., 1., 0.])
我正在使用以下代码中创建的字典绘制学习曲线:
#First separation of test data
X_train_prev, X_test_prev, y_train_prev, y_test_prev = train_test_split(X, y, test_size = 0.2)
#storing test and training error in dictionary as a function of decreasing test size
array = np.arange(0.01,0.9,0.025)
dicto = {}
for i in array:
X_train, _, y_train, _ = train_test_split(X_train_prev, y_train_prev, test_size = i)
clf.fit(X_train,y_train)
#use the previous test data...
test = clf.score(X_test_prev, y_test_prev)
train = clf.score(X_train, y_train)
dicto[i] = test, train
print(dicto)
问题在于测试误差与模型无关。这怎么可能?我应该如何更改我的代码,以使测试错误取决于经过训练的模型?
【问题讨论】:
-
您能否提供完整的工作 sn-p,最好使用 sklearn 中提供的样本数据集
-
我编辑了我的帖子。感谢您的评论 michael_j_ward
-
通过工作 sn-p,我的意思是我应该能够将 sn-p 复制并粘贴到 python 中并获得您所遇到的结果。我不会立即出现错误,因此它可能在您的分类器设置或绘图功能中 - 所以我需要一个完整的工作 sn-p 才能诊断问题
-
你的数据不是很不平衡吗,88%的单类? (因此这个结果只是简单的模型说“总是正确的”?)
标签: python for-loop machine-learning