Professional Documents
Culture Documents
%matplotlib inline
import pandas as
pd import numpy as
np
import matplotlib.pyplot as plt
fruits =
pd.read_table('fruit_data_with_colors.txt')
Out[1]:
In [2]:
print(fruits.shape)
(59, 7)
In [3]:
print(fruits['fruit_name'].unique())
['apple' 'mandarin' 'orange' 'lemon']
In [4]:
print(fruits.groupby('fruit_name').size())
fruit_name apple
19
lemon 16
mandarin 5
orange 19
dtype: int64
In [5]:
2/
In [6]:
3/
In [7]:
import pylab as pl
fruits.drop('fruit_label' ,axis=1).hist(bins=30,
figsize=(9,9)) pl.suptitle("Histogram for each numeric input
variable") plt.savefig('fruits_hist')
plt.show()
4/
In [15]:
In [16]:
5/
In [18]:
C:\Users\BRINZEL RODRIGUES\Anaconda3\lib\site-packages\sklearn\line
ar_model\logistic.py:432: FutureWarning: Default solver will be cha
nged to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
C:\Users\BRINZEL RODRIGUES\Anaconda3\lib\site-packages\sklearn\line
ar_model\logistic.py:469: FutureWarning: Default multi_class will b
e changed to 'auto' in 0.22. Specify the multi_class option to sile
nce this warning.
"this warning.", FutureWarning)
In [22]:
In [24]:
In [26]:
6/
In [28]:
C:\Users\BRINZEL RODRIGUES\Anaconda3\lib\site-packages\sklearn\svm
\base.py:193: FutureWarning: The default value of gamma will change
from 'auto' to 'scale' in version 0.22 to account better for unscal
ed features. Set gamma explicitly to 'auto' or 'scale' to avoid thi
s warning.
"avoid this warning.", FutureWarning)
In [29]:
accuracy 1.00 15
macro avg 1.00 1.00 1.00 15
weighted avg 1.00 1.00 1.00 15
7/
In [69]:
import matplotlib.cm as cm
from matplotlib.colors import ListedColormap, BoundaryNorm
from sklearn.neighbors import KNeighborsClassifier
import matplotlib.patches as mpatches
import matplotlib.patches as mpatches
X = fruits[['mass', 'width', 'height', 'color_score']]
y = fruits['fruit_label']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
8/
-------------------------------------------------------------------
--------
NameError Traceback (most recent ca
ll last)
<ipython-input-69-8e6bd5daee2a> in <module>
42 plt.xlabel('height (cm)')
43 plt.ylabel('width (cm)')
---> 44 plt.title("4-Class classification (k = %i, weights = '%s')"
% (n_neighbors, weights))
45 plt.show()
46 plot_fruit_knn(X_train, y_train, 5, 'uniform')