In [9]:
import pandas as pd
import seaborn as sns 
import numpy as np
sns.set(color_codes=True)
import matplotlib.pyplot as plt
In [14]:
dataset=pd.read_csv('Multiclass-dataset.csv')
In [15]:
dataset.head()
Out[15]:
P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 ... P12 P13 P14 P15 P16 P17 P18 P19 P20 R1
0 3.30 7.44 1.52 3.27 0.07 2.14 0.75 0.66 0.0 54.8 ... 50.7 6.55 4.09 4.26 0.01 0.00 24.7 2.7 1.6 V1
1 3.43 7.63 1.63 3.27 0.05 2.01 0.74 0.65 0.0 51.8 ... 47.9 8.35 5.08 5.01 0.01 0.00 23.3 2.3 1.8 V1
2 3.41 7.32 1.52 3.18 0.07 2.09 0.80 0.70 0.0 54.0 ... 54.4 9.27 6.85 7.14 0.19 0.06 25.0 2.5 -0.9 V1
3 3.78 7.85 1.69 3.35 0.03 1.98 0.77 0.67 0.0 57.7 ... 48.9 10.26 5.96 5.47 0.05 0.01 24.1 5.6 2.1 V1
4 3.90 7.99 1.61 3.43 0.02 2.14 0.77 0.71 0.0 59.1 ... 54.1 8.19 5.81 4.72 0.64 0.16 26.8 2.5 2.1 V1

5 rows × 21 columns

In [16]:
dataset.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 400 entries, 0 to 399
Data columns (total 21 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   P1      400 non-null    float64
 1   P2      400 non-null    float64
 2   P3      400 non-null    float64
 3   P4      400 non-null    float64
 4   P5      400 non-null    float64
 5   P6      400 non-null    float64
 6   P7      400 non-null    float64
 7   P8      400 non-null    float64
 8   P9      400 non-null    float64
 9   P10     400 non-null    float64
 10  P11     400 non-null    float64
 11  P12     400 non-null    float64
 12  P13     400 non-null    float64
 13  P14     400 non-null    float64
 14  P15     400 non-null    float64
 15  P16     400 non-null    float64
 16  P17     400 non-null    float64
 17  P18     400 non-null    float64
 18  P19     400 non-null    float64
 19  P20     400 non-null    float64
 20  R1      400 non-null    object 
dtypes: float64(20), object(1)
memory usage: 65.8+ KB
In [17]:
dataset.shape
Out[17]:
(400, 21)
In [18]:
corelation=dataset.corr()
In [19]:
sns.heatmap(corelation,xticklabels=corelation.columns,yticklabels=corelation.columns,annot=True)
Out[19]:
<AxesSubplot:>
In [20]:
x=dataset.drop("R1",axis=1)
y=dataset["R1"]
In [21]:
x.head()
Out[21]:
P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 P16 P17 P18 P19 P20
0 3.30 7.44 1.52 3.27 0.07 2.14 0.75 0.66 0.0 54.8 49.7 50.7 6.55 4.09 4.26 0.01 0.00 24.7 2.7 1.6
1 3.43 7.63 1.63 3.27 0.05 2.01 0.74 0.65 0.0 51.8 47.3 47.9 8.35 5.08 5.01 0.01 0.00 23.3 2.3 1.8
2 3.41 7.32 1.52 3.18 0.07 2.09 0.80 0.70 0.0 54.0 50.5 54.4 9.27 6.85 7.14 0.19 0.06 25.0 2.5 -0.9
3 3.78 7.85 1.69 3.35 0.03 1.98 0.77 0.67 0.0 57.7 47.2 48.9 10.26 5.96 5.47 0.05 0.01 24.1 5.6 2.1
4 3.90 7.99 1.61 3.43 0.02 2.14 0.77 0.71 0.0 59.1 54.1 54.1 8.19 5.81 4.72 0.64 0.16 26.8 2.5 2.1
In [22]:
#seperating dataset into train and test

from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=0)
In [25]:
x_train.shape, y_test.shape
Out[25]:
((280, 20), (120,))
In [26]:
from sklearn.neural_network import MLPClassifier
In [27]:
mlp=MLPClassifier(max_iter=500,activation='relu')
In [28]:
mlp
Out[28]:
MLPClassifier(max_iter=500)
In [30]:
mlp.fit(x_train, y_train)
Out[30]:
MLPClassifier(max_iter=500)
In [31]:
pred=mlp.predict(x_test)
pred
Out[31]:
array(['V9', 'V8', 'V9', 'V6', 'V7', 'V10', 'V4', 'V7', 'V4', 'V4', 'V1',
       'V4', 'V3', 'V9', 'V3', 'V10', 'V7', 'V4', 'V5', 'V5', 'V6', 'V7',
       'V4', 'V9', 'V5', 'V8', 'V10', 'V1', 'V8', 'V1', 'V6', 'V8', 'V9',
       'V6', 'V10', 'V10', 'V1', 'V5', 'V5', 'V10', 'V1', 'V4', 'V1',
       'V1', 'V8', 'V2', 'V10', 'V7', 'V5', 'V5', 'V7', 'V4', 'V8', 'V6',
       'V7', 'V8', 'V10', 'V1', 'V1', 'V2', 'V10', 'V7', 'V1', 'V9', 'V5',
       'V10', 'V4', 'V3', 'V4', 'V8', 'V1', 'V7', 'V10', 'V1', 'V1', 'V1',
       'V10', 'V8', 'V10', 'V9', 'V3', 'V10', 'V10', 'V3', 'V8', 'V6',
       'V9', 'V10', 'V10', 'V9', 'V10', 'V8', 'V10', 'V1', 'V6', 'V5',
       'V5', 'V10', 'V7', 'V2', 'V7', 'V10', 'V7', 'V4', 'V8', 'V9', 'V4',
       'V4', 'V4', 'V8', 'V3', 'V1', 'V4', 'V1', 'V10', 'V6', 'V7', 'V10',
       'V5', 'V5'], dtype='<U3')
In [32]:
from sklearn.metrics import classification_report,confusion_matrix
In [33]:
confusion_matrix(y_test,pred)
Out[33]:
array([[12,  0,  0,  2,  0,  0,  0,  0,  0,  0],
       [ 0, 10,  1,  0,  0,  0,  0,  0,  0,  0],
       [ 0, 13,  2,  0,  0,  0,  0,  0,  0,  0],
       [ 5,  0,  0,  3,  1,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0, 10,  3,  0,  0,  0,  2],
       [ 0,  0,  0,  0,  0,  5,  5,  0,  0,  0],
       [ 0,  0,  0,  0,  1,  3,  3,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0, 10,  1,  0],
       [ 0,  0,  0,  0,  1,  0,  0,  3, 12,  0],
       [ 0,  0,  0,  1,  2,  1,  0,  0,  0,  8]], dtype=int64)
In [34]:
print(classification_report(y_test,pred))
              precision    recall  f1-score   support

          V1       0.71      0.86      0.77        14
         V10       0.43      0.91      0.59        11
          V2       0.67      0.13      0.22        15
          V3       0.50      0.33      0.40         9
          V4       0.67      0.67      0.67        15
          V5       0.42      0.50      0.45        10
          V6       0.38      0.43      0.40         7
          V7       0.77      0.91      0.83        11
          V8       0.92      0.75      0.83        16
          V9       0.80      0.67      0.73        12

    accuracy                           0.62       120
   macro avg       0.63      0.62      0.59       120
weighted avg       0.66      0.62      0.61       120