在不同的数据预处理情况下训练得到了三个SVM模型,结果都差不多,对这三个模型的分类结果进行投票
1、三个模型的model_path
# 最终model的path
self.model_path = log_path+'/'+model_name+'_model.gz'
self.time_log = log_path+'/'+model_name+'_time_log.csv'
# 模型1
self.model1_path = 'F:/20230911_bcic_windowlenth/4/subject_dependent_2_classes' + '/' + model_name + '_model.gz'
# 模型2
self.model2_path = 'F:/20230911_bcic_windowlenth/2_1/subject_dependent_2_classes' + '/' + model_name + '_model.gz'
# 模型3
self.model3_path = 'F:/20230911_bcic_windowlenth/2_2/subject_dependent_2_classes' + '/' + model_name + '_model.gz'
2、导入、拟合、保存
# model1
clf1 = load(self.model1_path)
# model2
clf2 = load(self.model2_path)
# model3
clf3 = load(self.model3_path)
estimators = [('svm', clf1), ('svm1', clf2), ('svm2', clf3)]
# soft/hard
classifier = VotingClassifier(estimators, voting="soft")
classifier.fit(X_train, y_train)
# save
dump(classifier, self.model_path)
3、predict
classifier = load(self.model_path)
vote_acc = classifier.score(X_test, y_test)
遇到的问题:
AttributeError: predict_proba is not available when probability=False
分别在model1、model2、model3训练svm的时候按照上述设置