MLPClassifier stands for Multi-layer Perceptron classifier which in the name itself connects to a Neural Network. Unlike other classification algorithms such as Support Vectors or Naive Bayes Classifier, MLPClassifier relies on an underlying Neural Network to perform the task of classification.
Implementing MLPClassifier With Python
Here some steps by which we can implement MLPClassifier with Python
It contains three layers input, hidden and output layers.
Import all libraries
Here some important libraries which use to implement MLPClassifier in python
# load libraries
from sklearn import datasets
from sklearn import metrics
from sklearn.neural_network import MLPClassifier
from sklearn.neural_network import MLPRegressor
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import seaborn as sns
Importing the Dataset
Here we are using the breast_cancer data from sklearn
# load the iris datasets
dataset = datasets.load_breast_cancer()
X = dataset.data; y = dataset.target
Split data sets
Now we will split the data using train_test_split
#split dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
Fit it into the model
Now we are ready to fit it into the model
# fit a CART model to the data
model = MLPClassifier()
model.fit(X_train, y_train)
print(); print(model)
Make Prediction
Now we are predicting the model
# make predictions
expected_y = y_test
predicted_y = model.predict(X_test)
Classification report and confusion matrix
Now, here we will find the result and confusion matrix
# summarize the fit of the model
print(); print(metrics.classification_report(expected_y, predicted_y))
print(); print(metrics.confusion_matrix(expected_y, predicted_y))