Specificities = []
kf = KFold(n_splits=10)
for train_i, test_i in kf.split(X):
    x_train = X[train_i].reshape(X[train_i].shape[0],
                                 X[train_i].shape[1] * X[train_i].shape[2])
    x_test = X[test_i].reshape(X[test_i].shape[0],
                               X[test_i].shape[1] * X[test_i].shape[2])
    y_train, y_test = Y[train_i], Y[test_i]

    svm_model = SVC(C=100, kernel='linear', gamma='scale')
    svm_model.fit(x_train, y_train)
    y_pred = svm_model.predict(x_test)

    print("-------------------------------")
    ACC, TPR, TNR, PPV, NPV, FPR = per.GetPerformanceMetrics(y_test,
                                                             y_pred,
                                                             weighted=True)
    Accuracies.append(ACC)
    Recalls.append(TPR)
    Specificities.append(TNR)
    Precisions.append(PPV)
    NPVs.append(NPV)
    FPRs.append(FPR)

    print("Accuracy: ", ACC)
    print("Recall: ", TPR)
    print("Specificity: ", TNR)
    print("Precision: ", PPV)
    print("Negative Predictive Value: ", NPV)
    print("FP rate(fall-out): ", FPR)
    print(confusion_matrix(y_test, y_pred))
Exemplo n.º 2
0
])

model.compile(optimizer="adam",
              loss="sparse_categorical_crossentropy",
              metrics=['accuracy'])

model.summary()

model.fit(train_x, train_y, verbose=2, batch_size=2, epochs=50)

model.evaluate(test_x, test_y, batch_size=2, verbose=2)
ypred = np.argmax(model.predict(test_x, batch_size=2), axis=-1)

print("-------------------------------")
ACC, TPR, TNR, PPV, NPV, FPR = per.GetPerformanceMetrics(test_y,
                                                         ypred,
                                                         weighted=True)

print("Accuracy: ", ACC)
print("Recall: ", TPR)
print("Specificity: ", TNR)
print("Precision: ", PPV)
print("Negative Predictive Value: ", NPV)
print("FP rate(fall-out): ", FPR)
print(confusion_matrix(test_y, ypred))

print("-------------------------------")

print(
    "0: fighting\n 1: front\n 2: ready\n 3: cat\n 4: horse \n 5: hicho \n 6: seiza"
)