Skip to content

Instantly share code, notes, and snippets.

@leandrocl2005
Last active November 30, 2018 15:26
Show Gist options
  • Save leandrocl2005/9e6fefbb54257cecbf1f846b7bb294f5 to your computer and use it in GitHub Desktop.
Save leandrocl2005/9e6fefbb54257cecbf1f846b7bb294f5 to your computer and use it in GitHub Desktop.
# bibliotecas
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
import numpy as np
# remove warnings
import warnings
warnings.filterwarnings("ignore")
# dataset
iris = load_iris()
# features e target
X = iris.data
y = iris.target
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