Practical File DL
Practical File DL
DEEP LEARNING
1
S.No Name of Experiment Page No. Signature
2
Lab 1. To implement and practice Python Basics with Numpy.
Objective:
The objective of this experiment is to implement and practice fundamental Python concepts
using the NumPy library. This includes working with arrays, mathematical operations,
indexing, slicing, and basic statistical functions.
Introduction: Background
• Support for linear algebra, Fourier transforms, and random number generation.
Flowchart:
Below is a simple flowchart illustrating the steps involved in implementing Python basics
with NumPy:
3
Code Snippets
1. Creating Arrays
import numpy as np
2. Array Properties
random_arr = np.random.rand(2, 2)
4
6. Dot Product
Results:
Results Discussion:
• The code successfully demonstrates the creation of NumPy arrays and performs basic
arithmetic operations like addition and multiplication.
Conclusion: Outcome
The experiment successfully demonstrated the basic operations of Python with NumPy. The
implementation of array creation, mathematical operations, indexing, slicing, reshaping and
other features highlights NumPy’s efficiency in handling numerical computations.
Understanding these fundamentals is essential for further exploration of data science,
machine learning, and scientific computing applications.
6
Lab 2: To implement the learning models using open-source libraries.
Objective
The objective of this experiment is to implement learning models using open-source libraries
such as Scikit-learn, TensorFlow, and PyTorch. These libraries provide pre-built functions
and tools for training machine learning models efficiently.
Introduction: Background
Machine learning models are built using datasets to make predictions or classify information.
Open-source libraries like Scikit-learn, TensorFlow, and PyTorch simplify the
implementation of these models by providing optimized mathematical functions, data
handling tools, and pre-trained models.
Flowchart:
Step4. Train machine learning models (e.g., Decision Tree, Neural Network)
Code Snippets:
7
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
# Load dataset
iris = load_iris()
X, y = iris.data, iris.target
model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)
# Make predictions
y_pred = model.predict(X_test)
print("\nClassification Report:")
print(classification_report(y_test, y_pred))
8
Results
After executing the above Decision Tree classification model on the Iris dataset, the
following results are obtained:
2. Classification Report:
The classification report provides a detailed breakdown of precision, recall, and F1-
score for each class (Setosa, Versicolor, and Virginica). Given the high accuracy,
precision and recall values for all classes are expected to be 1.00.
Conclusion: Outcome
9
Lab 3. To build a simple classifier in Python.
Objective:
The objective of the code is to train a Random Forest Classifier on the Iris dataset, evaluate
its performance, and calculate the accuracy of the model on the test data.
Introduction: Background
The Iris dataset is a well-known dataset in machine learning, consisting of 15️0 samples from
three species of iris flowers (Setosa, Versicolour, and Virginica). Each sample has four
features: sepal length, sepal width, petal length, and petal width. The goal of this experiment
is to use the dataset to classify iris species using the Random Forest algorithm, a robust and
versatile machine learning technique that performs well in many classification tasks.
Flowchart:
2. Split the data: Divide the dataset into training and test sets.
3. Train the model: Fit the Random Forest Classifier on the training data.
4. Make predictions: Use the trained model to make predictions on the test data.
5️. Evaluate accuracy: Calculate the accuracy of the model by comparing the predictions
to the actual labels of the test data.
Code Snippet:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
# Load dataset
data = load_iris()
X, y = data.data, data.target
# Split data
10
# Train classifier
classifier = RandomForestClassifier()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
print("Accuracy:", accuracy)
Results
Results Discussion:
The accuracy score reflects how well the classifier predicts the correct species of the Iris
flowers. A high accuracy (like 1.0 or near 1.0) indicates that the model is performing well.
Factors that could affect accuracy include the complexity of the model, the quality of the
dataset, and the choice of features.
Conclusion: Outcome
The Random Forest classifier successfully trained and evaluated on the Iris dataset and
produced a high accuracy. This demonstrates that the Random Forest algorithm is capable of
efficiently handling this classification task with minimal tuning. Future improvements could
involve tuning the model parameters or trying different classifiers to compare performance.
11
Lab 4. To implement Logistic Regression while understanding its neural network
equivalence.
Objective:
The objective is to implement Logistic Regression on the Iris dataset and explore its
equivalence to a neural network with a single neuron (sigmoid activation function). Logistic
Regression can be interpreted as a neural network with no hidden layers, using a sigmoid
activation function in the output layer.
Introduction: Background
The neural network equivalent of logistic regression can be understood as a simple network
with:
Flowchart:
2. Split the data: Divide the dataset into training and test sets.
3. Train Logistic Regression model: Train the model using Logistic Regression.
5️. Evaluate accuracy: Calculate the accuracy of the model by comparing predictions to
the actual labels.
Code Snippets
from sklearn.datasets import load_iris
import numpy as np
12
# Load dataset
data = load_iris()
X, y = data.data, data.target
# For simplicity, we'll convert this into a binary classification problem (Setosa vs others)
# Split data
classifier = LogisticRegression()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
print("Accuracy:", accuracy)
Results
Conclusion: Outcome
The Logistic Regression model has successfully classified the Iris dataset, treating the
classification task as binary. The neural network equivalent of Logistic Regression is
essentially a one-layer network with a sigmoid activation, where it performs a similar task of
13
mapping inputs to output probabilities. This implementation shows how Logistic Regression
can be viewed through the lens of neural networks, and it illustrates the effectiveness of
logistic regression in classification problems.
14