Code Day 9 ML (Ordinal) - Jupyter Notebook
Code Day 9 ML (Ordinal) - Jupyter Notebook
Import Datasets
In [2]: df = pd.read_csv('customer.csv')
In [5]: df.sample(5)
39 76 Male Poor PG No
In [6]: df = df.iloc[:,2:]
In [7]: df.sample(5)
45 Poor PG Yes
29 Average UG Yes
21 Average PG No
46 Poor PG No
27 Poor PG No
Train_Test_Split
Import_OrdinalEncoder
42 Good PG
7 Poor School
36 Good UG
23 Good School
0 Average School
43 Poor PG
3 Good PG
49 Good UG
13 Average School
12 Poor School
24 Average PG
5 Average School
28 Poor School
21 Average PG
4 Average UG
10 Good UG
33 Good PG
31 Poor School
18 Good School
19 Poor PG
44 Average UG
1 Poor UG
2 Good PG
17 Poor UG
41 Good PG
30 Average UG
47 Good PG
26 Poor PG
20 Average School
22 Poor PG
40 Good School
14 Poor PG
8 Average UG
38 Good School
6 Good School
48 Good UG
11 Good UG
25 Good School
29 Average UG
27 Poor PG
Define Categories
In [13]: oe = OrdinalEncoder(categories=[['Poor','Average','Good'],['School','UG','PG']])
In [14]: oe.fit(x_train)
In [16]: x_train
Label Encoding
In [18]: from sklearn.preprocessing import LabelEncoder
In [19]: le = LabelEncoder()
In [20]: le.fit(y_train)
C:\Users\ASUS\anaconda3\Lib\site-packages\sklearn\preprocessing\_label.py:97: DataCo
nversionWarning: A column-vector y was passed when a 1d array was expected. Please c
hange the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
Out[20]: LabelEncoder()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the
notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with
nbviewer.org.
In [21]: le.classes_
C:\Users\ASUS\anaconda3\Lib\site-packages\sklearn\preprocessing\_label.py:132: DataC
onversionWarning: 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().
y = column_or_1d(y, dtype=self.classes_.dtype, warn=True)
C:\Users\ASUS\anaconda3\Lib\site-packages\sklearn\preprocessing\_label.py:132: DataC
onversionWarning: 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().
y = column_or_1d(y, dtype=self.classes_.dtype, warn=True)
In [23]: y_train
Out[23]: array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0])
In [ ]: