You are on page 1of 1

In [1]: import pandas as pd

In [2]: import numpy as np

In [17]: from sklearn.datasets import load_wine

In [18]: df1=load_wine()

In [29]: print(df1.DESCR)

.. _wine_dataset:

Wine recognition dataset


------------------------

**Data Set Characteristics:**

:Number of Instances: 178 (50 in each of three classes)


:Number of Attributes: 13 numeric, predictive attributes and the class
:Attribute Information:
- Alcohol
- Malic acid
- Ash
- Alcalinity of ash
- Magnesium
- Total phenols
- Flavanoids
- Nonflavanoid phenols
- Proanthocyanins
- Color intensity
- Hue
- OD280/OD315 of diluted wines
- Proline

- class:
- class_0
- class_1
- class_2

:Summary Statistics:

============================= ==== ===== ======= =====


Min Max Mean SD
============================= ==== ===== ======= =====
Alcohol: 11.0 14.8 13.0 0.8
Malic Acid: 0.74 5.80 2.34 1.12
Ash: 1.36 3.23 2.36 0.27
Alcalinity of Ash: 10.6 30.0 19.5 3.3
Magnesium: 70.0 162.0 99.7 14.3
Total Phenols: 0.98 3.88 2.29 0.63
Flavanoids: 0.34 5.08 2.03 1.00
Nonflavanoid Phenols: 0.13 0.66 0.36 0.12
Proanthocyanins: 0.41 3.58 1.59 0.57
Colour Intensity: 1.3 13.0 5.1 2.3
Hue: 0.48 1.71 0.96 0.23
OD280/OD315 of diluted wines: 1.27 4.00 2.61 0.71
Proline: 278 1680 746 315
============================= ==== ===== ======= =====

:Missing Attribute Values: None


:Class Distribution: class_0 (59), class_1 (71), class_2 (48)
:Creator: R.A. Fisher
:Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
:Date: July, 1988

This is a copy of UCI ML Wine recognition datasets.


https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data

The data is the results of a chemical analysis of wines grown in the same
region in Italy by three different cultivators. There are thirteen different
measurements taken for different constituents found in the three types of
wine.

Original Owners:

Forina, M. et al, PARVUS -


An Extendible Package for Data Exploration, Classification and Correlation.
Institute of Pharmaceutical and Food Analysis and Technologies,
Via Brigata Salerno, 16147 Genoa, Italy.

Citation:

Lichman, M. (2013). UCI Machine Learning Repository


[https://archive.ics.uci.edu/ml]. Irvine, CA: University of California,
School of Information and Computer Science.

.. topic:: References

(1) S. Aeberhard, D. Coomans and O. de Vel,


Comparison of Classifiers in High Dimensional Settings,
Tech. Rep. no. 92-02, (1992), Dept. of Computer Science and Dept. of
Mathematics and Statistics, James Cook University of North Queensland.
(Also submitted to Technometrics).

The data was used with many others for comparing various
classifiers. The classes are separable, though only RDA
has achieved 100% correct classification.
(RDA : 100%, QDA 99.4%, LDA 98.9%, 1NN 96.1% (z-transformed data))
(All results using the leave-one-out technique)

(2) S. Aeberhard, D. Coomans and O. de Vel,


"THE CLASSIFICATION PERFORMANCE OF RDA"
Tech. Rep. no. 92-01, (1992), Dept. of Computer Science and Dept. of
Mathematics and Statistics, James Cook University of North Queensland.
(Also submitted to Journal of Chemometrics).

In [34]: wine_features=pd.DataFrame(df1.data,columns=df1.feature_names)
wine_features.head()

Out[34]: alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols flavanoids nonflavanoid_phenols proanthocyanins color_intensity hu

0 14.23 1.71 2.43 15.6 127.0 2.80 3.06 0.28 2.29 5.64 1.

1 13.20 1.78 2.14 11.2 100.0 2.65 2.76 0.26 1.28 4.38 1.

2 13.16 2.36 2.67 18.6 101.0 2.80 3.24 0.30 2.81 5.68 1.

3 14.37 1.95 2.50 16.8 113.0 3.85 3.49 0.24 2.18 7.80 0.

4 13.24 2.59 2.87 21.0 118.0 2.80 2.69 0.39 1.82 4.32 1.

In [35]: wine_target=pd.DataFrame(df1.target,columns=['Target'])

wine_target.head()

Out[35]: Target

0 0

1 0

2 0

3 0

4 0

In [40]: # Dataframe shape


wine_features.shape

(178, 13)
Out[40]:

In [41]: # Dataframe size


wine_features.size

2314
Out[41]:

In [42]: # data types


wine_features.dtypes

alcohol float64
Out[42]:
malic_acid float64
ash float64
alcalinity_of_ash float64
magnesium float64
total_phenols float64
flavanoids float64
nonflavanoid_phenols float64
proanthocyanins float64
color_intensity float64
hue float64
od280/od315_of_diluted_wines float64
proline float64
dtype: object

In [43]: #Discriptive analysis


wine_features.describe()

Out[43]: alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols flavanoids nonflavanoid_phenols proanthocyanins col

count 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000

mean 13.000618 2.336348 2.366517 19.494944 99.741573 2.295112 2.029270 0.361854 1.590899

std 0.811827 1.117146 0.274344 3.339564 14.282484 0.625851 0.998859 0.124453 0.572359

min 11.030000 0.740000 1.360000 10.600000 70.000000 0.980000 0.340000 0.130000 0.410000

25% 12.362500 1.602500 2.210000 17.200000 88.000000 1.742500 1.205000 0.270000 1.250000

50% 13.050000 1.865000 2.360000 19.500000 98.000000 2.355000 2.135000 0.340000 1.555000

75% 13.677500 3.082500 2.557500 21.500000 107.000000 2.800000 2.875000 0.437500 1.950000

max 14.830000 5.800000 3.230000 30.000000 162.000000 3.880000 5.080000 0.660000 3.580000

In [44]: #Correlation
wine_features.corr()

Out[44]: alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols flavanoids nonflavanoid_phenols

alcohol 1.000000 0.094397 0.211545 -0.310235 0.270798 0.289101 0.236815 -0.155929

malic_acid 0.094397 1.000000 0.164045 0.288500 -0.054575 -0.335167 -0.411007 0.292977

ash 0.211545 0.164045 1.000000 0.443367 0.286587 0.128980 0.115077 0.186230

alcalinity_of_ash -0.310235 0.288500 0.443367 1.000000 -0.083333 -0.321113 -0.351370 0.361922

magnesium 0.270798 -0.054575 0.286587 -0.083333 1.000000 0.214401 0.195784 -0.256294

total_phenols 0.289101 -0.335167 0.128980 -0.321113 0.214401 1.000000 0.864564 -0.449935

flavanoids 0.236815 -0.411007 0.115077 -0.351370 0.195784 0.864564 1.000000 -0.537900

nonflavanoid_phenols -0.155929 0.292977 0.186230 0.361922 -0.256294 -0.449935 -0.537900 1.000000

proanthocyanins 0.136698 -0.220746 0.009652 -0.197327 0.236441 0.612413 0.652692 -0.365845

color_intensity 0.546364 0.248985 0.258887 0.018732 0.199950 -0.055136 -0.172379 0.139057

hue -0.071747 -0.561296 -0.074667 -0.273955 0.055398 0.433681 0.543479 -0.262640

od280/od315_of_diluted_wines 0.072343 -0.368710 0.003911 -0.276769 0.066004 0.699949 0.787194 -0.503270

proline 0.643720 -0.192011 0.223626 -0.440597 0.393351 0.498115 0.494193 -0.311385

In [46]: #column wise count of null or NaN values


wine_features.isnull().sum()

alcohol 0
Out[46]:
malic_acid 0
ash 0
alcalinity_of_ash 0
magnesium 0
total_phenols 0
flavanoids 0
nonflavanoid_phenols 0
proanthocyanins 0
color_intensity 0
hue 0
od280/od315_of_diluted_wines 0
proline 0
dtype: int64

In [62]: #duplicates
wine_features.duplicated()

0 False
Out[62]:
1 False
2 False
3 False
4 False
...
173 False
174 False
175 False
176 False
177 False
Length: 178, dtype: bool

In [56]: #number of dupliacte rows


wine_features.duplicated().sum()

0
Out[56]:

In [64]: #any dupliacte rows


wine_features.duplicated().any()

False
Out[64]:

In [66]: #values in alcohol column


wine_features['alcohol'].values

array([14.23, 13.2 , 13.16, 14.37, 13.24, 14.2 , 14.39, 14.06, 14.83,


Out[66]:
13.86, 14.1 , 14.12, 13.75, 14.75, 14.38, 13.63, 14.3 , 13.83,
14.19, 13.64, 14.06, 12.93, 13.71, 12.85, 13.5 , 13.05, 13.39,
13.3 , 13.87, 14.02, 13.73, 13.58, 13.68, 13.76, 13.51, 13.48,
13.28, 13.05, 13.07, 14.22, 13.56, 13.41, 13.88, 13.24, 13.05,
14.21, 14.38, 13.9 , 14.1 , 13.94, 13.05, 13.83, 13.82, 13.77,
13.74, 13.56, 14.22, 13.29, 13.72, 12.37, 12.33, 12.64, 13.67,
12.37, 12.17, 12.37, 13.11, 12.37, 13.34, 12.21, 12.29, 13.86,
13.49, 12.99, 11.96, 11.66, 13.03, 11.84, 12.33, 12.7 , 12. ,
12.72, 12.08, 13.05, 11.84, 12.67, 12.16, 11.65, 11.64, 12.08,
12.08, 12. , 12.69, 12.29, 11.62, 12.47, 11.81, 12.29, 12.37,
12.29, 12.08, 12.6 , 12.34, 11.82, 12.51, 12.42, 12.25, 12.72,
12.22, 11.61, 11.46, 12.52, 11.76, 11.41, 12.08, 11.03, 11.82,
12.42, 12.77, 12. , 11.45, 11.56, 12.42, 13.05, 11.87, 12.07,
12.43, 11.79, 12.37, 12.04, 12.86, 12.88, 12.81, 12.7 , 12.51,
12.6 , 12.25, 12.53, 13.49, 12.84, 12.93, 13.36, 13.52, 13.62,
12.25, 13.16, 13.88, 12.87, 13.32, 13.08, 13.5 , 12.79, 13.11,
13.23, 12.58, 13.17, 13.84, 12.45, 14.34, 13.48, 12.36, 13.69,
12.85, 12.96, 13.78, 13.73, 13.45, 12.82, 13.58, 13.4 , 12.2 ,
12.77, 14.16, 13.71, 13.4 , 13.27, 13.17, 14.13])

In [77]: #If duplicate or not


wine_features['alcohol'].duplicated().values

array([False, False, False, False, False, False, False, False, False,


Out[77]:
False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, False, True, True,
False, True, False, True, False, True, True, False, False,
False, True, True, False, False, False, False, False, False,
True, False, True, False, True, False, False, False, True,
False, False, False, False, False, False, True, False, False,
False, False, True, True, False, False, False, False, True,
True, True, False, True, False, False, False, True, True,
True, True, False, False, False, False, False, False, True,
False, False, False, False, False, False, True, False, True,
True, False, True, False, False, True, True, False, False,
False, False, True, False, False, False, False, True, True,
True, True, False, True, False, True, False, False, False,
True, True, True, False, False, False, True, False, True,
False, False, False, False, False, False, True, False, False,
True, False, False, True, False, False, True, False, False,
True, False, True, True, False, True, False])

In [71]: #Total number of duplicate items


wine_features['alcohol'].duplicated().sum()

52
Out[71]:

In [76]: #Duplicate Items with their index


wine_features['alcohol'][wine_features['alcohol'].duplicated()]

20 14.06
Out[76]:
37 13.05
43 13.24
44 13.05
46 14.38
48 14.10
50 13.05
51 13.83
55 13.56
56 14.22
63 12.37
65 12.37
67 12.37
71 13.86
78 12.33
83 13.05
84 11.84
89 12.08
90 12.08
91 12.00
93 12.29
97 12.29
98 12.37
99 12.29
100 12.08
107 12.72
114 12.08
116 11.82
117 12.42
119 12.00
122 12.42
123 13.05
128 12.37
133 12.70
134 12.51
135 12.60
136 12.25
138 13.49
140 12.93
144 12.25
145 13.16
146 13.88
150 13.50
152 13.11
159 13.48
162 12.85
165 13.73
168 13.58
171 12.77
173 13.71
174 13.40
176 13.17
Name: alcohol, dtype: float64

In [79]: # dropping duplicates in alcohol column from dataframe while keeping first
wine_features.drop_duplicates(subset=['alcohol'],keep='first')

Out[79]: alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols flavanoids nonflavanoid_phenols proanthocyanins color_intensity

0 14.23 1.71 2.43 15.6 127.0 2.80 3.06 0.28 2.29 5.64

1 13.20 1.78 2.14 11.2 100.0 2.65 2.76 0.26 1.28 4.38

2 13.16 2.36 2.67 18.6 101.0 2.80 3.24 0.30 2.81 5.68

3 14.37 1.95 2.50 16.8 113.0 3.85 3.49 0.24 2.18 7.80

4 13.24 2.59 2.87 21.0 118.0 2.80 2.69 0.39 1.82 4.32

... ... ... ... ... ... ... ... ... ... ...

169 13.40 4.60 2.86 25.0 112.0 1.98 0.96 0.27 1.11 8.50

170 12.20 3.03 2.32 19.0 96.0 1.25 0.49 0.40 0.73 5.50

172 14.16 2.51 2.48 20.0 91.0 1.68 0.70 0.44 1.24 9.70

175 13.27 4.28 2.26 20.0 120.0 1.59 0.69 0.43 1.35 10.20

177 14.13 4.10 2.74 24.5 96.0 2.05 0.76 0.56 1.35 9.20

126 rows × 13 columns

In [93]: # showing data based on conditions


wine_features[(wine_features['alcohol']>13) & (wine_features['malic_acid']>4)]

Out[93]: alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols flavanoids nonflavanoid_phenols proanthocyanins color_intensity

45 14.21 4.04 2.44 18.9 111.0 2.85 2.65 0.30 1.25 5.24

123 13.05 5.80 2.13 21.5 86.0 2.62 2.65 0.30 2.01 2.60

143 13.62 4.95 2.35 20.0 92.0 2.00 0.80 0.47 1.02 4.40

146 13.88 5.04 2.23 20.0 80.0 0.98 0.34 0.40 0.68 4.90

155 13.17 5.19 2.32 22.0 93.0 1.74 0.63 0.61 1.55 7.90

156 13.84 4.12 2.38 19.5 89.0 1.80 0.83 0.48 1.56 9.01

165 13.73 4.36 2.26 22.5 88.0 1.28 0.47 0.52 1.15 6.62

169 13.40 4.60 2.86 25.0 112.0 1.98 0.96 0.27 1.11 8.50

173 13.71 5.65 2.45 20.5 95.0 1.68 0.61 0.52 1.06 7.70

175 13.27 4.28 2.26 20.0 120.0 1.59 0.69 0.43 1.35 10.20

177 14.13 4.10 2.74 24.5 96.0 2.05 0.76 0.56 1.35 9.20

In [ ]:

You might also like