-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMLP.py
More file actions
94 lines (46 loc) · 1.47 KB
/
MLP.py
File metadata and controls
94 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# coding: utf-8
# 9) Assignment on Multiclassification using MLP (Multilayer Perception). Build an application to classify given iris flower Specie using MLP (Use Iris data set from Kaggle/ sklean). Display Accuracy score, classification report and confusion matrix.
# In[20]:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,classification_report,accuracy_score
from sklearn import preprocessing
from sklearn.neural_network import MLPClassifier
# Load Dataset
# In[4]:
df=pd.read_csv("C:/Users/rohit/OneDrive/Documents/6th sem/ML/Lab/ML_datasets/iris.csv")
df.head()
# Preparing X and Y
# In[8]:
X=df[['sepal_length','sepal_width','petal_length','petal_width']]
Y=df['species']
# In[12]:
Y.unique()
# In[18]:
pre=preprocessing.LabelEncoder()
Y=pre.fit_transform(Y)
Y
# Splitting X and Y
# In[19]:
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.3,random_state=43)
Y_test
# Model Building
# In[51]:
mlp=MLPClassifier(hidden_layer_sizes=(10,10,10),max_iter=1000,random_state=1)
# Model Training
# In[52]:
mlp.fit(X_train,Y_train)
# Model Testing
# In[47]:
y_pred=mlp.predict(X_test)
y_pred
# Calculating Confusion matrix,Accuracy Score,Classification report
# In[48]:
cm=confusion_matrix(Y_test,y_pred)
cr=classification_report(Y_test,y_pred)
accuracy=accuracy_score(Y_test,y_pred)
print(cr)
print(cm)
print("Accuracy Score: ",accuracy)