如何保存深度超级学习者图?

时间:2019-05-22 08:58:42

标签: python deep-learning

我正在尝试运行一个深度超级学习包(https://github.com/levyben/DeepSuperLearner),该包提供2张图,但未显示如何保存它们-从此代码中可以添加任何内容来保存图吗?

这是我的代码:

if __name__ == '__main__':
    MLP_learner = dcv.GridSearchCV(mlp, parameter_space, cv=inner_cv,iid=False, n_jobs=-1)
    GBM_learner = dcv.GridSearchCV(gbm, param, cv=inner_cv,iid=False, n_jobs=-1)
    LR_learner = dcv.GridSearchCV(logreg, LR_par, cv=inner_cv, iid=False, n_jobs=-1)
    RFC_learner = dcv.GridSearchCV(rfc, param_grid, cv=inner_cv,iid=False, n_jobs=-1)
    SVM_learner =  dcv.GridSearchCV(svm, tuned_parameters, cv=inner_cv, iid=False, n_jobs=-1)
    Keras_learner = GridSearchCV(estimator=keras, param_grid=kerasparams, cv=inner_cv,iid=False, n_jobs=-1)
    Base_learners = {'MultilayerPerceptron':MLP_learner, 'GradientBoostingMachine':GBM_learner, 
        'LogisticRegression':LR_learner,'RandomForest':RF_learner, 'SupportVectorMachine':SVM_learner, 'Keras':Keras_learner}

    X_train, X_test, Y_train, Y_test = train_test_split(X_res, y_res, test_size=0.2, random_state=0)

    DSL_learner = DeepSuperLearner(Base_learners)
    DSL_learner.fit(X_train, Y_train,max_iterations=1,sample_weight=None)
    DSL_learner.get_precision_recall(X_test, Y_test, show_graphs=True) 
    y_pred = DSL_learner.predict(X_test)
    y_pred = numpy.argmax(y_pred,axis=1) 
    print("Deep Super Learner Test Accuracy:", accuracy_score(y_pred, Y_test)*100, "%")

我认为这是'show_graphs = True'给我的图,但是我需要能够保存这些输出,因为阅读github中的文档后,他们没有将该选项添加到.get_precision_recall()函数中。我一直在尝试应用matplotlib的savefig(),但到目前为止没有成功。

我尝试添加:

    plot = DSL_learner.get_precision_recall(X_test, Y_test, show_graphs=True)
    plt.show(plot)
    plot.savefig('DeepSuperLearner.png')

但这给出了错误: AttributeError: 'tuple' object has no attribute 'savefig'

这是我得到的图像(为了显示速度,用较少的模型快速运行了),并且我要保存: graphs

这些也与github示例中的相同。 同样在我跑步时:

  plot = DSL_learner.get_precision_recall(X_test, Y_test, show_graphs=True)
  plt.show(plot)

图形图像第二次输出。我正在jupyter实验室中运行它(但是需要能够保存图形以在其他地方运行此代码并仍然获取图形)

0 个答案:

没有答案