我是一名化学家,仍然在学习机器学习…
我使用Keras训练了7个不同的模型,使用不同类型的分子指纹作为特征来预测一个属性…然而准确率并不是很好。
所以我使用了一个在线找到的教程
def optimized_weights(prd,y_fold): # define bounds on each weight bound_w = [(0.0, 1.0) for _ in range(n_members) ] # arguments to the loss function search_arg = (prd ,y_fold) # global optimization of ensemble weights result = differential_evolution(loss_function, bound_w,search_arg, maxiter=2000, tol=0.0001) # get the chosen weights weights = normalize(result['x']) return weightsdef weighted_accuracy(prd,weights,y_fold): summed = tensordot(prd, weights, axes=((0),(0))) yhat=np.round(summed) score = accuracy_score(y_fold,yhat ) f1 = f1_score(y_fold,yhat) fpr, tpr, thresholds = roc_curve(y_fold,summed,pos_label=1) auc_test = auc(fpr, tpr) conf_matrix=confusion_matrix(y_fold,yhat) total=sum(sum(conf_matrix)) sensitivity = conf_matrix[0,0]/(conf_matrix[0,0]+conf_matrix[0,1]) specificity = conf_matrix[1,1]/(conf_matrix[1,0]+conf_matrix[1,1]) return score,auc_test,sensitivity,specificity,f1
对于加权平均集成模型,我在80%的数据上训练了模型,并使用20%的数据通过differential_evolution(来自scipy)来寻找最优权重以最大化准确率,但我认为这种准确率对测试数据有偏见…
我还对同样的过程进行了5折交叉验证,并确定了平均准确率….这是可以接受的吗…如果不可以,请告诉我我可以做什么
谢谢
回答:
DeepStack 提供了一个用于堆叠和“集成”Keras模型的接口。它还提供基于验证数据的性能测试,功能齐全