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

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.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

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.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.