Esempio n. 1
0
#shu=scale(data_AAindex)
#shu=scale(data)
#X=data
#y=label
[m, n] = np.shape(X)
sepscores = []
sepscores_ = []
ytest = np.ones((1, 2)) * 0.5
yscore = np.ones((1, 2)) * 0.5
cv_clf = AdaBoostClassifier(n_estimators=500)
skf = StratifiedKFold(n_splits=5)
for train, test in skf.split(X, y):
    X_train_enc = cv_clf.fit(X[train], y[train])
    y_score = cv_clf.predict_proba(X[test])
    yscore = np.vstack((yscore, y_score))
    y_test = to_categorical(y[test])
    ytest = np.vstack((ytest, y_test))
    fpr, tpr, _ = roc_curve(y_test[:, 0], y_score[:, 0])
    roc_auc = auc(fpr, tpr)
    y_class = categorical_probas_to_classes(y_score)
    y_test_tmp = y[test]
    acc, precision, npv, sensitivity, specificity, mcc, f1 = calculate_performace(
        len(y_class), y_class, y_test_tmp)
    sepscores.append(
        [acc, precision, npv, sensitivity, specificity, mcc, f1, roc_auc])
    print(
        'xgb:acc=%f,precision=%f,npv=%f,sensitivity=%f,specificity=%f,mcc=%f,f1=%f,roc_auc=%f'
        % (acc, precision, npv, sensitivity, specificity, mcc, f1, roc_auc))
scores = np.array(sepscores)
print("acc=%.2f%% (+/- %.2f%%)" %
      (np.mean(scores, axis=0)[0] * 100, np.std(scores, axis=0)[0] * 100))
Esempio n. 2
0
    output = Dense(int(n / 4),
                   activation='relu',
                   init='glorot_normal',
                   name='High_dim_feature')(protein_input1)
    outputs = Dense(2, activation='softmax', name='output')(output)
    model = Model(input=input_1, output=outputs)
    #sgd = SGD(lr=0.01, momentum=0.9, decay=0.001)
    model.compile(loss='categorical_crossentropy',
                  optimizer='Adam',
                  metrics=['accuracy'])
    return model


skf = StratifiedKFold(n_splits=5)
for train, test in skf.split(X, y):
    y_train = to_categorical(y[train])  #generate the resonable results
    cv_clf = get_con_model()
    hist = cv_clf.fit(X[train], y_train, nb_epoch=50)
    y_test = to_categorical(y[test])  #generate the test
    ytest = np.vstack((ytest, y_test))
    y_test_tmp = y[test]
    y_score = cv_clf.predict(X[test])  #the output of  probability
    yscore = np.vstack((yscore, y_score))
    fpr, tpr, _ = roc_curve(y_test[:, 0], y_score[:, 0])
    roc_auc = auc(fpr, tpr)
    y_class = categorical_probas_to_classes(y_score)
    acc, precision, npv, sensitivity, specificity, mcc, f1 = calculate_performace(
        len(y_class), y_class, y_test_tmp)
    sepscores.append(
        [acc, precision, npv, sensitivity, specificity, mcc, f1, roc_auc])
    print(