bci_workshop_tools.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:Wall-EEG 作者: neurotechuoft 项目源码 文件源码
def classifier_train(feature_matrix_0, feature_matrix_1, algorithm = 'SVM'):
    """
    Trains a binary classifier using the SVM algorithm with the following parameters

    Arguments
    feature_matrix_0: Matrix with examples for Class 0
    feature_matrix_0: Matrix with examples for Class 1
    algorithm: Currently only SVM is supported

    Outputs
    classfier: trained classifier (scikit object)
    mu_ft, std_ft: normalization parameters for the data
    """
    # Create vector Y (class labels)
    class0 = np.zeros((feature_matrix_0.shape[0],1))
    class1 = np.ones((feature_matrix_1.shape[0],1))

    # Concatenate feature matrices and their respective labels
    y = np.concatenate((class0, class1),axis=0)
    features_all = np.concatenate((feature_matrix_0, feature_matrix_1),axis=0)

    # Normalize inputs
    mu_ft = np.mean(features_all)
    std_ft = np.std(features_all)
    X = (features_all - mu_ft) / std_ft

    # Train SVM, using default parameters     
    classifier = svm.SVC()
    classifier.fit(X, y)

    return classifier, mu_ft, std_ft
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号