You are on page 1of 9

CHALLENGE B:

MULTILAYER PERCEPTRON
Presented by: Madiha Jamil (M00984161)
Importing libraries & data pre-
processing
◦ Imported the required libraries for the challenge.

◦ After importing the libraries, the dataset was loaded. The classification dataset has records of thyroid
cancer patients. It contains the history of their illness and treatment and whether after receiving the
treatment, their cancer recurred or not.
◦ Firstly, we checked the dataset for any null or duplicate values. There were no null/NAs in the dataset, but
it did have some duplicates, so we removed them.
◦ After analyzing the dataset, the input features were stored in X and output features were stored in y.
Continued..
X: input features
y :output

◦ Since the features in our dataset are categorical, label encoding is used.

◦ The data is then split into train and test. After splitting of data, the Multilayer Perceptron model is trained
and tested.
MLP model train and test
Initialising parameters

Fitting of model
Training and testing of model

◦ The MLP model was trained and tested using random values for the parameters.
◦ The training accuracy was 70.9% and testing accuracy was 69%.
◦ Now let us tune these parameters.
◦ There are several parametrers that are used in MLPClassifier model.
For e.g.,
1. Hidden layer size
2. Activation (logistic,relu,tanh,etc.)
3. Solver (sigmoid, adam, etc.)
4. Alpha (L2 Regularization)
5. Learning rate (constant, adaptive, etc.)
PARAMETERS 6. Initial learning rate
TO TUNE 7. Maximum iteration
8. Batch size etc.
GRIDSEARCHCV
◦ To find the best hyperparameters for the model, we use gridsearchcv technique.

◦ The parameters in gridsearchcv include our MLP Classifier model, the hyperparameters that we want to
tune and their respective values, the number of folds for cross-validation which is 5 and n_jobs=-1 which
makes sure all CPU core are utilized for faster processing.

◦ Now that we have our best hyperparameters, let us fit the model using these new values.
Continued..
◦ We use grid.search.best_estimator_ to access the hyperparameters having the best values and fit our
model.

◦ We can see that after tuning of the hyperparameters our training and testing accuracy has increased to
92.9% and 93.6% respectively.
CONCLUSION
◦ Initially the MLP Classifier was trained and tested using selected values which resulted in low accuracies
for train and test.
◦ We selected a few hyperparameters and assigned a range of values to them. This was done to help tune
the hyperparameters.
◦ Then by using gridsearchcv technique, the best values for the hyperparameters were selected and the
MLP Classifier was trained and tested again.
◦ We saw an increase in accuracies for both train and test. The train accuracy increased from 70.9% to
92.9% and test accuracy increased from 69% to 93.6%
◦ To conclude, gridsearchcv is a good technique that could resolve issues like underfitting, overfitting and
generalisability.
THANK YOU

You might also like