Created
November 30, 2018 16:18
-
-
Save leandrocl2005/b39bc0154d2ba9eaade692d43198bca4 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
# bibliotecas | |
from sklearn.datasets import load_iris | |
from sklearn.model_selection import train_test_split | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.preprocessing import Normalizer | |
import numpy as np | |
# remove warnings | |
import warnings | |
warnings.filterwarnings("ignore") | |
# dataset | |
iris = load_iris() | |
# features e target | |
X = iris.data | |
y = iris.target | |
# normalizando | |
scaler = Normalizer() | |
scaler.fit(X) | |
X = scaler.transform(X) | |
scores = [] | |
for i in range(2000): | |
X_train, X_test, y_train, y_test = train_test_split(X,y) | |
model = KNeighborsClassifier() | |
model.fit(X_train,y_train) | |
accuracy = model.score(X_test,y_test) | |
scores.append(accuracy) | |
print("Média: {:.2f}%".format(np.mean(scores)*100)) | |
print("Desvio padrão: {:.2f}%".format(np.std(scores)*100)) | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.distplot(scores) | |
plt.yticks([]) | |
plt.title("Acurácias do k-NN") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment