Preview:
 import pandas as pd
 from sklearn.datasets import load_iris
 from sklearn.neighbors import KNeighborsClassifier
 from sklearn.metrics import classification_report,confusion_matrix,accuracy_score
 from sklearn.model_selection import train_test_split
 iris=load_iris()
 df=pd.DataFrame(iris.data,columns=iris.feature_names)
 print(df.head())
 df['Species']=iris.target
 x=df.drop('Species',axis=1)
 y=df['Species']
 x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=42)
 model=KNeighborsClassifier(n_neighbors=3)
 model.fit(x_train,y_train)
 y_pred=model.predict(x_test)
 print(accuracy_score(y_test,y_pred))
 print(confusion_matrix(y_test,y_pred))
 print(classification_report(y_test,y_pred))
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter