Practicals 1 to
Practicals 1 to
Import Libraries:
import numpy as np
mnist = fetch_openml('mnist_784')
X = mnist.data
y = mnist.target.astype(int)
X = X / 255.0
mlp_classifier.fit(X_train, y_train)
Make Predictions:
y_pred = mlp_classifier.predict(X_test)
# Calculate accuracy
print("Accuracy:", accuracy)
In this example, we have created a Multilayer Perceptron classifier with two hidden layers (128
and 64 units) and trained it on the MNIST dataset. We then made predictions on the test data and
evaluated the model's performance using accuracy and a classification report.
Practical-2
Import Libraries:
import numpy as np
mnist = fetch_openml('mnist_784')
X = mnist.data
y = mnist.target.astype(int)
X = X / 255.0
Hyperparameter Tuning:
We can use techniques like GridSearchCV or RandomizedSearchCV to search for the best
combination of hyperparameters.
Grid Search:
param_grid = {
mlp_classifier = MLPClassifier(random_state=42)
# Perform grid search
grid_search.fit(X_train, y_train)
best_params = grid_search.best_params_
best_model = grid_search.best_estimator_
best_model.fit(X_train, y_train)
# Make predictions
y_pred = best_model.predict(X_test)
print("Accuracy:", accuracy)
We used GridSearchCV to search for the best hyperparameters for the MLP model. We can also
use RandomizedSearchCV for a randomized search over the hyperparameter space, which can be
more efficient when the search space is large.
Practical-3
Keras:
• Originally developed as an independent deep learning library, but later integrated into
TensorFlow as its official high-level API.
• Designed to be user-friendly and easy to use, particularly for rapid prototyping.
• Provides a simple and intuitive interface to define and train neural networks.
• Allows for both sequential and functional model building.
• Aims to minimize boilerplate code and streamline the process of creating and training deep
learning models.
Theano:
• Developed by the Montreal Institute for Learning Algorithms (MILA) at the University of
Montreal.
• Theano focused on optimizing mathematical computations, making it efficient for deep
learning tasks.
• Allowed users to define, optimize, and evaluate mathematical expressions involving multi-
dimensional arrays efficiently.
• Was one of the early deep learning frameworks but has since been largely superseded by
TensorFlow, PyTorch, and others.
PyTorch: