How to design an ANN with the help of keras?

How to design an ANN with the help of keras?

How to design an ANN with the help of keras?

This recipe helps you design an ANN with the help of keras

Recipe Objective

How to design an ANN with the help of keras?

ANN stands for *Artificial neural networks*. In this we create models that are inspired by the human brains and process the information similarly to it.

Step 1- Importing Libraries

import numpy as np from tensorflow import keras from tensorflow.keras import layers from keras.models import Sequential from keras.layers import Dense

Step 2- Load the dataset.

# the data, split between train and test sets (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

Step 3- preprocess the dataset.

num_classes = 10 input_shape = (28, 28, 1) X_train = x_train.astype("float32") / 255 X_test = x_test.astype("float32") / 255 X_train = np.expand_dims(X_train, -1) X_test = np.expand_dims(X_test, -1) y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes)

Step 4- Create the model

model = keras.Sequential( [ keras.Input(shape=input_shape), layers.Conv2D(32, kernel_size=(2, 2), activation="relu"), layers.Conv2D(64, kernel_size=(2, 2), activation="sigmoid"), layers.Flatten(), layers.Dropout(0.1), layers.Dense(num_classes, activation="softmax"), ] ) model.summary()

Step 5- Fit the DataSet.

batch_size = 128 epochs = 5 model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]), y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)

Relevant Projects

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Classification of T shirt images to see if they have text on them
Want to search images of clothes which have text on them? Then this project talks through how we can classify an image whether it has text on it or not. For this we use state of the model called as inception and try and deepdive into how it works on our dataset

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Loan Eligibility Prediction in Python using
In this loan prediction project you will build predictive models in Python using to predict if an applicant is able to repay the loan or not.