def svm_experiment(scope_name, X, y):
for lp in lp_cand:
results = []
for r in range(50):
with open('data/local/split/' + scope_name + '/lb' + str(lp).zfill(3) + '_' + str(r).zfill(
3) + '_train') as f:
trainLabel = pk.load(f)
with open('data/local/split/' + scope_name + '/lb' + str(lp).zfill(3) + '_' + str(r).zfill(
3) + '_test') as f:
testLabel = pk.load(f)
XTrain = X[trainLabel.keys()]
XTest = X[testLabel.keys()]
yTrain = y[trainLabel.keys()]
yTest = y[testLabel.keys()]
# train
clf = LinearSVC(C=0.01)
clf.fit(XTrain, yTrain)
# test
pred = clf.predict(XTest)
results.append(sum(pred == yTest) / float(yTest.shape[0]))
return np.mean(results)
评论列表
文章目录