- Introduction, PyTorch basics 📖👓
- Regression
↗️ 🏫 - Classification 🌸🔍
- Clustering Techniques 🧩☯️
- Neural Networks Use 💸💰
- CNN Emotion Classification Based on Facial Images 😃📸
- NLP Tasks with RNN Models 📝🧠
- LSTM Models for Time Series Prediction 📈⏰
- VAE Models for Image Generation 🖼️✨
- Reinforcement Learning with DQN CartPole Environment 🕹️🤖
Through these projects, I've acquired a diverse set of skills and knowledge in machine learning and deep learning, including:
- Understanding and implementing various machine learning algorithms such as linear regression, classification, clustering, and neural networks.
- Hands-on experience with deep learning frameworks such as PyTorch and TensorFlow/Keras.
- Preprocessing and transforming data for different machine learning tasks, including image classification, natural language processing, and time series prediction.
- Evaluating model performance using appropriate metrics and techniques.
- Exploring advanced topics in deep learning, including convolutional neural networks (CNNs), recurrent neural networks (RNNs), long short-term memory (LSTM) networks, variational autoencoders (VAEs), and reinforcement learning.
- Applying machine learning and deep learning techniques to real-world datasets and problems across various domains.
These projects have not only enhanced my technical skills but also fostered a deeper appreciation for the complexities and possibilities of machine learning and artificial intelligence by applying machine learning and deep learning techniques to real-world datasets and problems across various domains.
Enjoy!
- Tensor Creation: Demonstrates various methods of creating tensors including filling with zeros, ones, sequences, and converting from NumPy arrays.
- Tensor Operations: Shows basic tensor operations such as addition, multiplication, mean calculation, and sum calculation.
- Reshaping Tensors: Illustrates reshaping tensors into different shapes and flattening them into one-dimensional tensors.
- Indexing and Slicing Tensors: Explains how to access specific elements, rows, columns, and diagonals of tensors.
- Tensor and Numpy Operations: Covers conversion between PyTorch tensors and NumPy arrays and changing data types.
- Matrix Operations: Includes matrix multiplication and tensor transposition.
- Advanced Indexing: Demonstrates advanced indexing techniques using logical masks.
- In-Place Operations: Shows how to perform in-place operations on tensors and observe the changes.
This project serves as a friendly guide to understanding various functionalities of PyTorch tensors. By going through the provided code snippets and exercises I gained hands-on experience with tensor creation, manipulation, indexing, and basic operations in PyTorch. Additionally, it provided a foundation for further exploration into deep learning using PyTorch.
This project implements and compares linear regression models using both PyTorch and scikit-learn. It includes experiments to analyze the impact of noise levels and training set sizes on the performance of the models.
- The PyTorch model is implemented using a simple linear regression class (
LinearRegressionSimple
) inheriting fromnn.Module
. - A custom dataset class (
RegressionDataset
) is created to handle the data. - The training loop (
train
) and validation function (validate
) are defined to train the model. - The model is trained using stochastic gradient descent (SGD) with mean squared error (MSE) loss.
- The scikit-learn linear regression model is implemented using
LinearRegression
fromsklearn.linear_model
. - The model is trained using the
fit
method and evaluated using mean squared error (MSE) and coefficient of determination (R^2).
- Investigated the impact of different noise levels on model performance.
- Generated datasets with varying noise levels and trained both models.
- Created plots showing how noise affects MSE and R^2 for both models.
- Analyzed the impact of training set size on model performance.
- Created different splits of the data into training and test sets.
- Trained and evaluated both models for each split and plotted the results.
- Both PyTorch and scikit-learn models were successfully implemented and compared.
- Analysis of noise levels and training set sizes provided insights into model performance under different conditions.
Overall, the project demonstrates the versatility and effectiveness of linear regression models implemented using PyTorch and scikit-learn.
This project involves classification tasks using both PyTorch and scikit-learn libraries.
- MNIST dataset: A widely used dataset for handwritten digit recognition. It consists of 28x28 grayscale images of handwritten digits (0-9) and their corresponding labels.
- 'customers.csv': A dataset containing information about customers, including their gender, age, annual income, and spending score.
The code is divided into two main parts:
- PyTorch Implementation:
- Data transformation using
torchvision.transforms.Compose
. - Creation of MNIST training and test datasets.
- Exploration of the MNIST dataset, including visualizing images and calculating probabilities.
- Implementation of a Naive Bayes classifier using PyTorch for digit classification.
- Prediction of digit classes and evaluation of classification accuracy.
- Data transformation using
- scikit-learn Implementation:
- Loading and preprocessing of the 'customers.csv' dataset.
- Exploration of the dataset through pairplot visualization.
- Splitting the data into training and testing sets.
- Building classification models using Gaussian Naive Bayes, Logistic Regression, and Decision Tree Classifier.
- Evaluation of the models using accuracy, precision, recall, and F1 score metrics.
Through this project, I gained experience in:
- Preprocessing and transforming data using PyTorch and scikit-learn.
- Implementing classification models for different types of data (images and tabular data).
- Evaluating model performance using various metrics.
Back to Top
This project involves implementing and comparing different clustering algorithms using both PyTorch and scikit-learn libraries.
- Synthetic datasets: Generated using functions like
make_blobs
andmake_moons
from scikit-learn to simulate various clustering scenarios.
-
PyTorch Implementation:
-
scikit-learn Implementation:
- Applied K-Means clustering to a synthetic dataset and utilized the elbow method to determine the optimal number of clusters.
- Implemented hierarchical agglomerative clustering and visualized the dendrogram.
- Employed DBSCAN clustering on a dataset with dense regions and compared the results with K-Means clustering.
Through this project, I gained experience in:
- Implementing clustering algorithms using both PyTorch and scikit-learn.
- Visualizing clustering results and centroids.
- Understanding the differences between K-Means, hierarchical, and density-based clustering algorithms.
Back to Top
In this project, I implemented regression and classification models using neural networks on two different datasets.
- Diabetes Dataset:
- Contains information about diabetes patients, including various health metrics and a binary target variable indicating diabetes presence.
- Iris Dataset:
- Contains samples of iris flowers, with features describing the flower properties and a categorical target variable indicating the species.
- Diabetes Dataset:
- Loaded the dataset and performed initial analysis, including checking for missing values and calculating descriptive statistics.
- Built a binary classification model to predict diabetes presence based on health metrics using PyTorch.
- Evaluated the model's performance using metrics such as accuracy, confusion matrix, and classification report.
- Conducted cross-validation to verify the model's stability and made necessary optimizations.
- Iris Dataset:
- Loaded the dataset and performed initial analysis, including data exploration through visualizations.
- Prepared the data for modeling by scaling features and splitting into training and testing sets.
- Built a multi-class classification model to predict iris species based on flower properties using PyTorch.
- Evaluated the model's performance using metrics such as accuracy and cross-validated RMSE.
- Visualized confusion matrix to understand the classification results.
- Loaded the dataset and performed initial analysis, including data exploration through visualizations.
Through these implementations:
- I gained experience in building neural network models for both regression and classification tasks.
- Explored different evaluation metrics for model performance assessment.
- Utilized PyTorch for both model implementation and evaluation, showcasing its flexibility and effectiveness in neural network development.
Back to Top
The provided code consists of two main sections. The first section involves building and training a Convolutional Neural Network (CNN) model for classifying images from the CIFAR-10 dataset. The second section involves a similar process for emotion classification based on facial images using the FER-2013 dataset. Here's a breakdown of the tasks performed:
- CIFAR-10 Dataset:
- Downloaded from the CIFAR-10 dataset repository.
- Consists of 60,000 32x32 color images in 10 classes, with 6,000 images per class.
- FER-2013 Dataset:
- Contains facial images categorized into seven different emotions: angry, disgust, fear, happy, sad, surprise, and neutral.
- Split into training and testing sets.
The code is implemented using PyTorch, a popular deep learning framework. It utilizes various modules from the torch
and torchvision
libraries for building and training CNN models. Key implementation details include:
- Definition of CNN model architectures for both datasets.
- Configuration of loss functions (Cross-Entropy Loss) and optimization algorithms (Stochastic Gradient Descent (SGD) and Adam).
- Training loops for iterating over epochs, batches, and data loading.
- Model evaluation on test datasets to compute accuracy metrics.
- CIFAR-10 Dataset Processing and CNN Model Training:
- FER-2013 Dataset Processing and CNN Model Training:
- Loading the FER-2013 dataset and preparing it for training.
- Building a CNN model architecture for emotion classification.
- Training the CNN model on the FER-2013 dataset.
- Evaluating the trained model's accuracy on the test dataset.
- Saving the trained model's parameters to a file.
Through this project, the following knowledge and tasks were gained:
- Dataset loading and preprocessing using torchvision.
- Building CNN architectures using PyTorch's
nn.Module
API. - Training and evaluating CNN models for image classification tasks.
- Utilizing GPU acceleration for faster model training (if available).
- Saving and loading trained model parameters for future use.
Overall, this project provided hands-on experience in developing deep learning models for image classification tasks, demonstrating the practical application of CNNs in real-world scenarios.
The provided code demonstrates the development and training of Recurrent Neural Network (RNN) models for natural language processing (NLP) tasks using TensorFlow and Keras. Three main tasks are performed:
- Sentiment Analysis on IMDb Movie Reviews
- Text Classification on the Reuters Dataset
- Sentiment Analysis on IMDb Movie Reviews with LSTM (Long Short-Term Memory) layers
- IMDb Dataset:
- Contains movie reviews along with their sentiment labels (positive or negative).
- Loaded using the
imdb.load_data()
function from Keras datasets.
- Reuters Dataset:
- Consists of short newswires categorized into 46 mutually exclusive topics.
- Loaded using the
reuters.load_data()
function from Keras datasets.
The code implementation involves several steps for each task:
- Data Preparation:
- Loading and preprocessing datasets, including padding sequences for uniform length.
- Model Building:
- Building RNN models using Sequential API with embedding layers and RNN/LSTM layers.
- Configuring appropriate input shapes and layer configurations for each model.
- Model Compilation:
- Compiling models with suitable optimizers, loss functions, and metrics.
- Training:
- Training models on training data with a specified number of epochs and batch size.
- Utilizing a portion of the training data as a validation set for monitoring model performance.
- Evaluation and Testing:
Through this project, various aspects of NLP model development using RNNs and LSTMs were explored, including data preprocessing, model architecture design, training, and evaluation. Key takeaways include:
- Understanding the importance of padding sequences for fixed-length input.
- Implementing different RNN architectures for sentiment analysis and text classification tasks.
- Evaluating model performance using accuracy metrics and analyzing results using classification reports and confusion matrices.
Overall, the project provides valuable insights into leveraging RNNs and LSTMs for NLP tasks and demonstrates the effectiveness of deep learning techniques in handling sequential data.
The provided code involves the following tasks:
- Preprocessing and analysis of time series data from a telecommunications dataset.
- Implementation of an LSTM (Long Short-Term Memory) model for time series prediction.
- Prediction of stock prices using an LSTM model with data from the Apple stock.
-
Telecommunications Time Series Data:
- The dataset contains time series data related to telecommunications metrics such as user numbers, interference, and success rates.
- Loaded from a CSV file and preprocessed to handle missing values and select relevant columns.
- Specific subsets of data are used for analysis and modeling.
-
Stock Price Data (Apple - AAPL):
- Stock price data for the Apple company is downloaded using the Yahoo Finance API.
- The data is normalized and split into training and testing sets for LSTM model training.
-
Telecommunications Data Analysis:
-
LSTM Model for Time Series Prediction:
- Implementation of an LSTM model using PyTorch for time series prediction.
- Data preparation involves creating sequences of input-output pairs.
- The model architecture consists of LSTM and linear layers.
- Training of the model using an Adam optimizer and Mean Squared Error loss function.
-
Stock Price Prediction with LSTM:
- Downloading and preprocessing of stock price data for Apple.
- Creation of input-output sequences for LSTM modeling.
- Building an LSTM model using Keras with TensorFlow backend.
- Training the model, monitoring loss, and visualizing training/validation loss.
- Making predictions on the test set and comparing them with actual stock prices.
Through these implementations, various aspects of time series analysis and prediction using LSTM models were explored. Key takeaways include:
- Preprocessing steps such as handling missing data and selecting relevant features are crucial for effective model training.
- LSTM models offer powerful capabilities for capturing temporal dependencies in sequential data.
- Training and evaluation of LSTM models require careful consideration of hyperparameters and monitoring of loss metrics.
- LSTM models can be applied to diverse domains such as telecommunications metrics and financial time series data with promising results.
Back to Top
The code involves the implementation of a Variational Autoencoder (VAE) using PyTorch for two different datasets: MNIST and Fashion-MNIST. The key tasks performed include:
-
MNIST Dataset:
- Handwritten digit images dataset consisting of grayscale images of size 28x28 pixels.
- Used for training the VAE model to reconstruct digit images.
-
Fashion-MNIST Dataset:
- Fashion product images dataset containing grayscale images of size 28x28 pixels.
- Employed for training the VAE model to reconstruct fashion product images.
The implementation includes the following steps for both MNIST and Fashion-MNIST datasets:
MNIST Numbers reconstruction:
Fashion-MNIST Dataset:
-
Preparing the data:
- Loading and preprocessing the MNIST and Fashion-MNIST datasets.
- Creating data loaders for efficient batching during training.
-
Implementing the VAE model:
- Defining the architecture for the VAE model, including encoder and decoder networks.
- Incorporating a reparameterization trick for sampling from the latent space.
-
Training the VAE model:
- Optimizing the VAE model parameters using the Adam optimizer.
- Monitoring the loss function during training to assess model performance.
-
Results Analysis:
- Evaluating the reconstruction quality of the VAE model by comparing original images with their reconstructed counterparts.
- Generating new images by sampling from the latent space and passing through the decoder.
VAE Model Definition:
- Architecture setup for the VAE model including encoder and decoder networks.
- Incorporation of the reparameterization trick for sampling from the latent space.
Model Training:
- Training the VAE model using the Adam optimizer and minimizing the loss function.
- Evaluating the model's performance by monitoring the loss function during training.
Results Analysis:
- Visual comparison of original images with their reconstructions to assess the quality of reconstruction.
Through the implementation of the VAE model on MNIST and Fashion-MNIST datasets, the code demonstrates the capability of VAEs to learn meaningful representations of high-dimensional data and generate new samples. The analysis of reconstruction quality provides insights into the effectiveness of the VAE in capturing and reconstructing the underlying structure of the input data.
Back to Top
The code implements a Deep Q-Network (DQN) agent using PyTorch to play the "CartPole-v1" game environment from the OpenAI Gym.
Credits: https://www.gymlibrary.dev/environments/classic_control/cart_pole/
The implementation includes the following key components:
-
Setting up the game environment:
- Importing necessary libraries including Gym.
- Creating the "CartPole-v1" environment.
-
Implementing the DQN agent:
- Defining a neural network model representing the DQN.
- Initializing the replay memory to store experiences.
- Implementing the ε-greedy exploration strategy to select actions.
-
DQN Model Definition:
- Architecture setup for the neural network model representing the DQN.
- Implementation of the forward pass method to compute state-action values.
-
Training the DQN Agent:
- Optimization of the DQN model by updating weights based on transitions sampled from the replay memory.
- Updating the target network using a soft update strategy to stabilize training.
-
ε-Greedy Exploration:
- Implementation of the ε-greedy exploration strategy to balance exploration and exploitation during action selection.
-
Visualizing Training Progress:
Through the implementation of the DQN agent, the code demonstrates the reinforcement learning approach to train an agent to play the "CartPole-v1" game environment. By optimizing the DQN model and updating target networks, the agent learns to balance the pole on the cart, achieving stable training progress over multiple episodes.
Back to Top