-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evaluator save and returns to execute predict
- Loading branch information
Showing
8 changed files
with
124 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
DATA_PATH = BASE_PATH + 'data/' | ||
MODEL_PATH = BASE_PATH + 'model/' | ||
EVALUATE_PATH = BASE_PATH + 'evaluate/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"results": [{"model": "cardio_dt", "inductor": "Decision Tree", "acc": 0.63, "sen": 0.63, "spe": 0.62, "roc": 0.63}, {"model": "cardio_lr", "inductor": "Logistic Regression", "acc": 0.71, "sen": 0.74, "spe": 0.67, "roc": 0.71}, {"model": "cardio_rf", "inductor": "Random Forest", "acc": 0.72, "sen": 0.73, "spe": 0.7, "roc": 0.72}, {"model": "cardio_svm_poly", "inductor": "SVM Kernel Poly", "acc": 0.72, "sen": 0.73, "spe": 0.7, "roc": 0.72}]} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
import config | ||
|
||
def evaluate_best_model(): | ||
filename = config.EVALUATE_PATH + 'results.json' | ||
|
||
best_model = 0 | ||
with open(filename) as json_file: | ||
data = json.load(json_file) | ||
for p in data['results']: | ||
sum = p['acc']+p['sen']+p['spe']+p['roc'] | ||
if sum > best_model: | ||
best_model = sum | ||
sel_model = p['model'] | ||
name_model = p['inductor'] | ||
|
||
return sel_model, name_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,129 @@ | ||
from trabalho_final.preprocessing import get_data | ||
from MachineLearning import MachineLearning, accuracy, sensitivity, specificity | ||
import json | ||
import config | ||
|
||
machine_learning = MachineLearning() | ||
attributes, classes = get_data() | ||
|
||
json_data = {} | ||
json_data['results'] = [] | ||
|
||
# Decision Tree | ||
print("\nGerando modelo de Decision Tree") | ||
response, auc_roc, matrix, report = machine_learning.generate_decision_tree(attributes, classes, 'cardio_dt') | ||
print(response) | ||
print("\nAcurácia") | ||
print(accuracy(matrix)) | ||
acc = accuracy(matrix) | ||
print(acc) | ||
print("\nSensibilidade") | ||
print(sensitivity(matrix)) | ||
sen = sensitivity(matrix) | ||
print(sen) | ||
print("\nEspecificidade") | ||
print(specificity(matrix)) | ||
spe = specificity(matrix) | ||
print(spe) | ||
|
||
json_data['results'].append({ | ||
'model': 'cardio_dt', | ||
'inductor': 'Decision Tree', | ||
'acc': acc, | ||
'sen': sen, | ||
'spe': spe, | ||
'roc': auc_roc, | ||
}) | ||
|
||
# Logistic Regression | ||
print("\nGerando modelo de Logistic Regression") | ||
response, auc_roc, matrix, report = machine_learning.generate_logistic_regression(attributes, classes, 'cardio_lr') | ||
print(response) | ||
print("\nAcurácia") | ||
print(accuracy(matrix)) | ||
acc = accuracy(matrix) | ||
print(acc) | ||
print("\nSensibilidade") | ||
print(sensitivity(matrix)) | ||
sen = sensitivity(matrix) | ||
print(sen) | ||
print("\nEspecificidade") | ||
print(specificity(matrix)) | ||
spe = specificity(matrix) | ||
print(spe) | ||
|
||
json_data['results'].append({ | ||
'model': 'cardio_lr', | ||
'inductor': 'Logistic Regression', | ||
'acc': acc, | ||
'sen': sen, | ||
'spe': spe, | ||
'roc': auc_roc, | ||
}) | ||
|
||
# Random Forest | ||
print("\nGerando modelo de Random Forest") | ||
response, auc_roc, matrix, report = machine_learning.generate_random_forest(attributes, classes, 'cardio_rf') | ||
print(response) | ||
print("\nAcurácia") | ||
print(accuracy(matrix)) | ||
acc = accuracy(matrix) | ||
print(acc) | ||
print("\nSensibilidade") | ||
print(sensitivity(matrix)) | ||
sen = sensitivity(matrix) | ||
print(sen) | ||
print("\nEspecificidade") | ||
print(specificity(matrix)) | ||
spe = specificity(matrix) | ||
print(spe) | ||
|
||
# SVM kernel linear | ||
print("\nGerando modelo de SVM Kernel Linear") | ||
response, auc_roc, matrix, report = machine_learning.generate_svm(attributes, classes, 'cardio_svm_linear') | ||
print(response) | ||
print("\nAcurácia") | ||
print(accuracy(matrix)) | ||
print("\nSensibilidade") | ||
print(sensitivity(matrix)) | ||
print("\nEspecificidade") | ||
print(specificity(matrix)) | ||
json_data['results'].append({ | ||
'model': 'cardio_rf', | ||
'inductor': 'Random Forest', | ||
'acc': acc, | ||
'sen': sen, | ||
'spe': spe, | ||
'roc': auc_roc, | ||
}) | ||
|
||
# SVM kernel poly | ||
print("\nGerando modelo de SVM Kernel Poly") | ||
response, auc_roc, matrix, report = machine_learning.generate_svm(attributes, classes, 'cardio_svm_poly', kernel='poly') | ||
print(response) | ||
print("\nAcurácia") | ||
print(accuracy(matrix)) | ||
print("\nSensibilidade") | ||
print(sensitivity(matrix)) | ||
print("\nEspecificidade") | ||
print(specificity(matrix)) | ||
# # SVM kernel linear | ||
# print("\nGerando modelo de SVM Kernel Linear") | ||
# response, auc_roc, matrix, report = machine_learning.generate_svm(attributes, classes, 'cardio_svm_linear') | ||
# print(response) | ||
# print("\nAcurácia") | ||
# acc = accuracy(matrix) | ||
# print(acc) | ||
# print("\nSensibilidade") | ||
# sen = sensitivity(matrix) | ||
# print(sen) | ||
# print("\nEspecificidade") | ||
# spe = specificity(matrix) | ||
# print(spe) | ||
# | ||
# json_data['results'].append({ | ||
# 'model': 'cardio_svm_linear', | ||
# 'inductor': 'SVM Kernel Linear', | ||
# 'acc': acc, | ||
# 'sen': sen, | ||
# 'spe': spe, | ||
# 'roc': auc_roc, | ||
# }) | ||
# | ||
# # SVM kernel poly | ||
# print("\nGerando modelo de SVM Kernel Poly") | ||
# response, auc_roc, matrix, report = machine_learning.generate_svm(attributes, classes, 'cardio_svm_poly', kernel='poly') | ||
# print(response) | ||
# print("\nAcurácia") | ||
# acc = accuracy(matrix) | ||
# print(acc) | ||
# print("\nSensibilidade") | ||
# sen = sensitivity(matrix) | ||
# print(sen) | ||
# print("\nEspecificidade") | ||
# spe = specificity(matrix) | ||
# print(spe) | ||
|
||
json_data['results'].append({ | ||
'model': 'cardio_svm_poly', | ||
'inductor': 'SVM Kernel Poly', | ||
'acc': acc, | ||
'sen': sen, | ||
'spe': spe, | ||
'roc': auc_roc, | ||
}) | ||
|
||
filename = config.EVALUATE_PATH + 'results.json' | ||
with open(filename, 'w') as outfile: | ||
json.dump(json_data, outfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters