# cross-validation:
# matplotlib inline
The from sklearn import datasets
The from sklearn. Model_selection import train_test_split, cross_val_score
The from sklearn. Neighbors import KNeighborsClassifier
The import matplotlib. Pyplot as PLT
Iris=datasets. Load_iris ()
X=iris. Data
Y=iris. The target
X_train X_test, y_train, y_test=train_test_split (X, y, test_size=1/3., random_state=10)
K_range=range (1, 31)
Cv_scores=[]
For n in k_range:
KNN=KNeighborsClassifier (n)
Scores=cross_val_score (KNN, X_train y_train, CV=10, scoring='accuracy') # classification problems using the
Cv_scores. Append (scores. The scheme ())
PLT. The plot (k_range cv_scores)
PLT. Xlabel (' K ')
PLT. Ylabel (' Accuracy ')
PLT. The show ()
After the operation:
Traceback (the most recent call last) :
The File "F:/PyCharm Community Edition 2020.1/Microsoft Office programming/PDF File operations/machine learning - AI. Py", line 75, in & lt; module>
The import matplotlib. Pyplot as PLT
The File "F: \ Python \ Python3.7.7 \ lib \ matplotlib \ pyplot py", line 32, in & lt; module>
The import matplotlib. Colorbar
The File "F: \ Python \ Python3.7.7 \ lib \ matplotlib \ colorbar py", line 27, the in & lt; module>
The import matplotlib. Artist as martist
The File "F: \ Python \ Python3.7.7 \ lib \ matplotlib \ artist py", line 13, the in & lt; module>
From the path import path
The File "F: \ Python \ Python3.7.7 \ lib \ matplotlib \ path py", line 17, in & lt; module>
From the import _path cbook, rcParams
ImportError: always import a name '_path' from 'matplotlib (F: \ \ Python Python3.7.7 \ lib \ matplotlib \ set py)