(model, classes, tr_X, tr_Y, te_X, te_Y)
Evaluate accuracy and time cost
Evaluate accuracy and time cost
Evaluate accuracy and time cost
def evaluate_model(model, classes, tr_X, tr_Y, te_X, te_Y):
    ''' Evaluate accuracy and time cost '''

    # Accuracy
    t0 = time.time()

    tr_accu, tr_Y_predict = model.predict_and_evaluate(tr_X, tr_Y)
    print(f"Accuracy on training set is {tr_accu}")

    te_accu, te_Y_predict = model.predict_and_evaluate(te_X, te_Y)
    print(f"Accuracy on testing set is {te_accu}")

    print("Accuracy report:")
    print(classification_report(
        te_Y, te_Y_predict, target_names=classes, output_dict=False))

    # Time cost
    average_time = (time.time() - t0) / (len(tr_Y) + len(te_Y))
    print("Time cost for predicting one sample: "
          "{:.5f} seconds".format(average_time))

    # Plot accuracy
    axis, cf = lib_plot.plot_confusion_matrix(
        te_Y, te_Y_predict, classes, normalize=False, size=(12, 8))
    plt.show()
def evaluate_model ( model , classes , tr_X , tr_Y , te_X , te_Y ) : # Accuracy t0 = time . time ( ) tr_accu , tr_Y_predict = model . predict_and_evaluate ( tr_X , tr_Y ) print ( f"Accuracy on training set is {tr_accu}" ) te_accu , te_Y_predict = model . predict_and_evaluate ( te_X , te_Y ) print ( f"Accuracy on testing set is {te_accu}" ) print ( "Accuracy report:" ) print ( classification_report ( te_Y , te_Y_predict , target_names = classes , output_dict = False ) ) # Time cost average_time = ( time . time ( ) - t0 ) / ( len ( tr_Y ) + len ( te_Y ) ) print ( "Time cost for predicting one sample: " "{:.5f} seconds" . format ( average_time ) ) # Plot accuracy axis , cf = lib_plot . plot_confusion_matrix ( te_Y , te_Y_predict , classes , normalize = False , size = ( 12 , 8 ) ) plt . show ( )