In [8]: df = pd.read_csv('iris.data')
In [9]: df.head()
Out[9]:
5.1 3.5 1.4 0.2 Iris-setosa
In [10]: col = ['sepal length','sepal width', 'petal length', 'petal width', 'class']
In [11]: df.columns=col
In [12]: df.head()
Out[12]:
sepal length sepal width petal length petal width class
In [13]: x = df.iloc[:,0:4]
x.head()
Out[13]:
sepal length sepal width petal length petal width
In [14]: y = df.iloc[:,4:]
y.head()
Out[14]:
class
0 Iris-setosa
1 Iris-setosa
2 Iris-setosa
3 Iris-setosa
4 Iris-setosa
For: n_neighbors = 5
metric : 'manhattan'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [21]: accuracy_score(y_test,pred)
Out[21]: 0.9666666666666667
metric : 'hamming'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [23]: accuracy_score(y_test,pred)
Out[23]: 0.7666666666666667
metric : 'euclidean'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [30]: accuracy_score(y_test,pred)
Out[30]: 0.9666666666666667
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [33]: accuracy_score(y_test,pred)
Out[33]: 0.9666666666666667
For: n_neighbors = 7
metric : 'manhattan'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [36]: accuracy_score(y_test,pred)
Out[36]: 0.9833333333333333
metric : 'hamming'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [38]: accuracy_score(y_test,pred)
Out[38]: 0.8
metric : 'euclidean'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [40]: accuracy_score(y_test,pred)
Out[40]: 0.9833333333333333
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [42]: accuracy_score(y_test,pred)
Out[42]: 0.9833333333333333
For: n_neighbors = 3
metric : 'manhattan'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [44]: accuracy_score(y_test,pred)
Out[44]: 0.95
metric : 'hamming'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [47]: accuracy_score(y_test,pred)
Out[47]: 0.7166666666666667
metric : 'euclidean'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [50]: accuracy_score(y_test,pred)
Out[50]: 0.95
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [52]: accuracy_score(y_test,pred)
Out[52]: 0.95
For: n_neighbors = 1
metric : 'manhattan'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [57]: accuracy_score(y_test,pred)
Out[57]: 0.95
metric : 'hamming'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [59]: accuracy_score(y_test,pred)
Out[59]: 0.8333333333333334
metric : 'euclidean'
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [61]: accuracy_score(y_test,pred)
Out[61]: 0.95
C:\Users\Saili\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: DataCon
versionWarning: A column-vector y was passed when a 1d array was expected.
Please change the shape of y to (n_samples, ), for example using ravel().
In [63]: accuracy_score(y_test,pred)
Out[63]: 0.95
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: