Created
August 16, 2020 02:46
-
-
Save douglaspsteen/937a9257dfe02bb7bfecc03203924081 to your computer and use it in GitHub Desktop.
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
X = X[random_cols] | |
# Train-test-split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, | |
test_size=0.25, | |
random_state=42) | |
# Perform feature scaling | |
scaler = StandardScaler() | |
X_train = scaler.fit_transform(X_train) | |
X_test = scaler.transform(X_test) | |
# Fit k-NN classifier and make predictions | |
knn = KNeighborsClassifier() | |
knn.fit(X_train, y_train) | |
y_pred_train = knn.predict(X_train) | |
y_pred_test = knn.predict(X_test) | |
print(f'Train f1 Score: {f1_score(y_train, y_pred_train)}') | |
print(f'Test f1 Score: {f1_score(y_test, y_pred_test)}') | |
print(classification_report(y_test, y_pred_test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment