Fix data normalization for knn

This commit is contained in:
coolneng 2020-12-13 22:24:52 +01:00
parent e63406c0a8
commit 4a345b832c
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 3 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from sklearn.metrics import confusion_matrix, roc_auc_score, roc_curve
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import scale
from sklearn.preprocessing import MinMaxScaler
from sklearn.svm import LinearSVC
from sklearn.tree import DecisionTreeClassifier
@ -32,7 +32,8 @@ def predict_data(data, target, model, results):
model_name = model
model = choose_model(model=model)
if model_name == "knn":
data = scale(data)
scaler = MinMaxScaler()
data[data.columns] = scaler.fit_transform(data[data.columns])
confusion_matrices, auc, fpr, tpr = [], [], [], []
for train_index, test_index in split_k_sets(data):
model.fit(data.iloc[train_index], target.iloc[train_index])