p300_detector.py
def plot_matrix(X, y, model, label):
    '''
    This function takes trained model and testing data, and prints out its
    perfermance on the testing data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Testing data
    y : 1d array
        DESCRIPTION. Testing labels
    model : ML object
        DESCRIPTION. Trained classifer
    label : string
        DESCRIPTION. The label for confusion matrix

    Returns
    -------
    None.

    '''
    # generate the predicted labels
    print('Predict labels for tested dataset...')
    y_pred = model.predict(X)
    # ====================================================
    # if for neural network
    # y_pred = model.predict_classes(X)
    # ====================================================
    # calculate the accuracy score
    accuracy = accuracy_score(y, y_pred)
    # print the results
    print('Accuracy: ', accuracy)
    
    # plot the confusion matrix
    print('Plot the confusion matrix...')
    ConfusionMatrixDisplay.from_predictions(y, y_pred)
    plt.show()
    plt.text(4.3, 2.1, 'number of samples', rotation=90)
    plt.title(label)
    plt.savefig(label+'.png')
    # display the main classification metrics
    print('Display the main classification metrics:')
    print(classification_report(y, y_pred))

    This function takes trained model and testing data, and prints out its
    perfermance on the testing data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Testing data
    y : 1d array
        DESCRIPTION. Testing labels
    model : ML object
        DESCRIPTION. Trained classifer
    label : string
        DESCRIPTION. The label for confusion matrix

    Returns
    -------
    None.

    
This function takes trained model and testing data, and prints out its
perfermance on the testing data.

Parameters

X : 2d array: sample x feature
DESCRIPTION. Testing data
y : 1d array
DESCRIPTION. Testing labels
model : ML object
DESCRIPTION. Trained classifer
label : string
DESCRIPTION. The label for confusion matrix

Returns

None.
This function takes trained model and testing data and prints out its perfermance on the testing data . Parameters X : 2d array : sample x feature DESCRIPTION . Testing data y : 1d array DESCRIPTION . Testing labels model : ML object DESCRIPTION . Trained classifer label : string DESCRIPTION . The label for confusion matrix Returns None .
def plot_matrix(X, y, model, label):
    print('Predict labels for tested dataset...')
    y_pred = model.predict(X)
    accuracy = accuracy_score(y, y_pred)
    print('Accuracy: ', accuracy)
    print('Plot the confusion matrix...')
    ConfusionMatrixDisplay.from_predictions(y, y_pred)
    plt.show()
    plt.text(4.3, 2.1, 'number of samples', rotation=90)
    plt.title(label)
    plt.savefig(label+'.png')
    print('Display the main classification metrics:')
    print(classification_report(y, y_pred))
def plot_matrix ( X , y , model , label ) : print ( 'Predict labels for tested dataset...' ) y_pred = model . predict ( X ) accuracy = accuracy_score ( y , y_pred ) print ( 'Accuracy: ' , accuracy ) print ( 'Plot the confusion matrix...' ) ConfusionMatrixDisplay . from_predictions ( y , y_pred ) plt . show ( ) plt . text ( 4.3 , 2.1 , 'number of samples' , rotation = 90 ) plt . title ( label ) plt . savefig ( label + '.png' ) print ( 'Display the main classification metrics:' ) print ( classification_report ( y , y_pred ) )
This function takes trained model and testing data, and prints out its
perfermance on the testing data.
This function takes trained model and testing data and prints out its perfermance on the testing data .
'''
    This function takes trained model and testing data, and prints out its
    perfermance on the testing data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Testing data
    y : 1d array
        DESCRIPTION. Testing labels
    model : ML object
        DESCRIPTION. Trained classifer
    label : string
        DESCRIPTION. The label for confusion matrix

    Returns
    -------
    None.

    ''' # generate the predicted labels # ==================================================== # if for neural network # y_pred = model.predict_classes(X) # ==================================================== # calculate the accuracy score # print the results # plot the confusion matrix # display the main classification metrics
X
y
model
label