Skip to content

Instantly share code, notes, and snippets.

@leandrocl2005
Last active November 30, 2018 14:42
Show Gist options
  • Save leandrocl2005/84834148bf0fea5b9e4e529e31cdf91a to your computer and use it in GitHub Desktop.
Save leandrocl2005/84834148bf0fea5b9e4e529e31cdf91a 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
# dataset
iris = load_iris()
# features e target
X = iris.data
y = iris.target
# treino e teste
X_train, X_test, y_train, y_test = train_test_split(X,y)
# instanciando o modelo
model = KNeighborsClassifier()
# treinando o modelo utilizando o conjunto de treino
model.fit(X_train,y_train)
# validando o modelo utilizando o conjunto de teste
accuracy = str(round(model.score(X_test,y_test) * 100, 2))+"%"
# imprimindo o resultado
print("A acurácia do modelo k-NN foi",accuracy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment