Skip to content

mostafahashemiyan/Machine-learning-and-data-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Here's a template for a README.md file that explains the steps involved in building, training, and evaluating a neural network model on the Iris dataset using TensorFlow/Keras.


Iris Dataset Neural Network

This project demonstrates how to build, compile, and train a neural network model on the Iris dataset using TensorFlow and Keras. The model is designed to classify the Iris flowers into three species based on four input features (sepal length, sepal width, petal length, and petal width).

Table of Contents

Project Overview

The Iris dataset is a famous dataset from the UCI Machine Learning Repository that is commonly used for classification tasks. In this project, a neural network model is constructed using the Keras Sequential API. The model is trained on the Iris dataset and evaluated for its performance.

The goal is to predict the species of Iris flowers from the input features. The three species are:

  • Setosa
  • Versicolor
  • Virginica

The project includes the following key steps:

  1. Loading and splitting the dataset.
  2. Preprocessing the data.
  3. Building and compiling the neural network model.
  4. Training the model with the dataset.
  5. Evaluating the model's performance.

Dependencies

To run this project, you need the following Python libraries:

  • TensorFlow: A deep learning framework for building and training neural networks.
  • Numpy: For numerical operations.
  • Matplotlib: For data visualization (optional).
  • Scikit-learn: For dataset loading, splitting, and preprocessing.

You can install these dependencies using pip:

pip install tensorflow numpy matplotlib scikit-learn

Model Description

Neural Network Architecture

The model is built using the Keras Sequential API, consisting of 10 layers:

  1. Input layer: 64 units with He uniform initialization and biases set to 1.
  2. Hidden layers:
    • Four layers with 128 units each and ReLU activation.
    • Four layers with 64 units each and ReLU activation.
  3. Output layer: 3 units with softmax activation (for multi-class classification).

Model Compilation

  • Optimizer: Adam optimizer.
  • Loss function: Categorical crossentropy, suitable for multi-class classification.
  • Metrics: Accuracy.

Regularization and Initialization

  • He Uniform initializer: Used for the weights of the first layer.
  • Bias initializer: Set to 1 for the first layer.
  • ReLU activation: Used for all hidden layers.
  • Softmax activation: Used in the output layer to output probabilities for each class.

Steps to Run

  1. Load the Iris Dataset:

    • The dataset is loaded from sklearn.datasets.load_iris().
  2. Split the Data:

    • The dataset is split into training (90%) and test (10%) sets using train_test_split from Scikit-learn.
  3. Preprocess the Data:

    • Features are scaled using StandardScaler() to normalize them before training.
  4. Build the Model:

    • The neural network is created using the Keras Sequential API.
    • The first layer uses a He uniform initializer for weights and sets biases to 1.
  5. Compile the Model:

    • The model is compiled with the Adam optimizer, categorical cross-entropy loss, and accuracy as the metric.
  6. Train the Model:

    • The model is trained on the training data for 100 epochs, using early stopping to prevent overfitting.
  7. Evaluate the Model:

    • The model’s performance is evaluated on the test set, and the test accuracy is displayed.

Example of Training the Model

# Load the dataset
from sklearn import datasets
iris = datasets.load_iris()

# Split the data
train_data, test_data, train_targets, test_targets = read_in_and_split_data(iris)

# Build the model
model = get_model(input_shape=(4,))

# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Train the model
history = model.fit(train_data, train_targets, epochs=100, batch_size=32, validation_data=(test_data, test_targets))

# Evaluate the model
test_loss, test_accuracy = model.evaluate(test_data, test_targets)
print(f"Test Accuracy: {test_accuracy:.4f}")

License

This project is licensed under the MIT License - see the LICENSE file for details.


This README.md file provides an overview of the project, explains the neural network model, and gives clear instructions on how to run the code and install dependencies. It also includes a small code snippet showing how to train and evaluate the model.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published