#Reading pretrained model
            model = read_model(model_num, optimizer, original_models_path)
            models_grid.append(model)

            #Re-fit and create a new model initialized with pretrained model weights
            model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size)

            #saving model info with respect to threshold
            file_name = "Model_" + str(model_num) + "_" + str(index)
            file_path = model_path_pretrained_all

            #storng max accuracy possible with this model (for shortlisting)
            max_accuracy = plotMetricsWithThreshold(
                models_grid[index],
                X_test,
                y_test,
                fig_name=file_name,
                fig_path=file_path,
                display_info=False,
                return_max_metric='accuracy')
            max_accuracy_all_grid.append(max_accuracy)

            #saving model and model info
            saveModelandModelInfo(models_grid[index], file_name, file_path)

        #Get top 5 models by max accuracy
        max_accuracy_array = np.array(max_accuracy_all_grid)
        top_n_by_accuracy = max_accuracy_array.argsort()[-5:][::-1]

        #Copy those files in folder "grid_selected" with their rank
        for rank_index in range(len(top_n_by_accuracy)):
            model_index = top_n_by_accuracy[rank_index]
Ejemplo n.º 2
0
                                   )

dl_fit1.train(x=x, y=y, training_frame=train)

model_name = "MLP - Feedforward Grid"
#defined_params = str(nn_params1) + ": hidden=[50,20,30,5]"
defined_params = ""
file_name = "NN_1"
training_ratio = 0.65

os.getcwd()

fig_name = file_name + "_plot"
plot_info_1_base = plotMetricsWithThreshold(dl_fit1, test, y_test, fig_name=fig_name, fig_path = None,
                  precision="majority", recall="minority", 
                  fpoint5score = False, f1score=True, f2score=False, fbetascore=False,
                  TPR=True, FPR=True, specificity=True,
                  accuracy=True, misclassification=False,
                  display_info=True, model_type='h2o')

threshold = 0.3
report_df = report(dl_fit1, test, y , model_path, 4, report_df, 
              model_name, defined_params, file_name, training_ratio, 
              threshold=threshold, sampling=None, model_type='basic')

#NN2
dl_fit2 = H2ODeepLearningEstimator(model_id='dl_fit2',
                                   hidden=[30,15],
                                   seed=1,
                                   max_categorical_features=4,
                                   export_weights_and_biases=True,
                                   shuffle_training_data=True,
Ejemplo n.º 3
0
#run 'no of models' times
filename = filenames[index]
print(filename)
json_file = open(filename + '.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.load_weights(filename + ".h5")

y_pred = model.predict(X_test)

fig_name = filename + "_plot"
plot_info_one = plotMetricsWithThreshold(model,
                                         X_test,
                                         y_test,
                                         fig_name=fig_name,
                                         fig_path=None,
                                         precision="majority",
                                         recall="minority",
                                         fpoint5score=False,
                                         f1score=True,
                                         f2score=False,
                                         fbetascore=False,
                                         TPR=True,
                                         FPR=True,
                                         specificity=True,
                                         accuracy=True,
                                         misclassification=False,
                                         display_info=True)
model_plot_info.append(plot_info_one)
index += 1
Ejemplo n.º 4
0
model_name = "CNN"
defined_params = ""
file_name = "CNN_1"
training_ratio = 0.65
num_layers = '1+3'
fig_name = file_name + "_metrics_plot"

#plotting threshold vs metrics
model_1_plot_info = plotMetricsWithThreshold(y_test,
                                             y_pred,
                                             fig_name=fig_name,
                                             fig_path=None,
                                             precision="majority",
                                             recall="minority",
                                             fpoint5score=False,
                                             f1score=True,
                                             f2score=False,
                                             fbetascore=False,
                                             TPR=True,
                                             FPR=True,
                                             specificity=True,
                                             accuracy=True,
                                             misclassification=False,
                                             display_info=True)

#report()
threshold = 0.22

report_df = report(model_1,
                   X_test,
                   y_test,
                   model_path,