ML Unit-5
ML Unit-5
Keras :
3. The goal is to create robust algorithms and data structures that can be
used to model difficult problems MLP utilizes a supervised learning
technique called backpropagation.
4. MLP is used to solve regression and classification problems we use MLP
in speech and image processing computer vision time series prediction
and machine translation.
Figure-1
1. In the above example, we have two hidden layers that are not directly
exposed to the input the planning can refer to have many hidden layers in
our network model usually if we increase the number of hidden layers the
model will work more efficiently.
2. The final layer is called the output layer and it is responsible for the final
outcome the choice of activation function in the output layer strongly
depends on the type of problem.
DATASET
Figure-2
1. Import the data set from our working directory first we split this data set
into inputs and the output this X contains the four columns second to fifth
as inputs and y contains the output that survival column next we split our
data set into training and test set using this training test speed function we
select this size as 0.3.
2. 70% data will be in the training set and 30% will be in the test set this
final line will display the shape of the training and test set so let’s execute
it in our inputs we have 4 variables so in the model the input dimension
will be four.
3. Now we construct a sequential model with dense and dropout layers first
we construct a dense layer with 32 neurons as this is the first layer we
have to specify the input dimension which is 4.
4. So in the first hidden layer there will be 4 inputs and 32 outputs we use
RELU as our activation function the next one is another dense layer with
16 neurons then dropout layer with 0.2 dropout is a technique used to
prevent a model from overfitting this dropout will use 20% inputs at the
time of model.
Figure-3
1. Finally, we have a dense output layer with the activation function sigmoid
as our target variable contains only zero and one sigmoid
3. Parameters control the decay rates of the moving averages we are also
using accuracy as a metric function let’s compile it.
4. it is time to train our model with training data with a batch size of 10 as
our training set contains 623 samples there will be 63 batches of ten
samples
5. Finally model evaluation we will evaluate our model using test data set
this evaluation function will return the loss and accuracy of the model this
final line will display them in percentage let’s run it so our model
accuracy is 65.67.
Introduction to TensorFlow
The idea behind TensorFlow is to make it quick and simple to train deep neural
networks that use a diversity of mathematical models. These networks are then
able to learn from data without human intervention or supervision, making them
more efficient than conventional methods. The library also offers support for
processing on multiple machines simultaneously with different operating
systems and GPUs.
TensorFlow applications
TensorFlow is a library for deep learning built by Google, it’s been gaining a lot
of traction ever since its introduction early last year. The main features include
automatic differentiation, convolutional neural networks (CNN), and recurrent
neural networks (RNN). It’s written in C++ and Python, for high performance it
uses a server called a “Cloud TensorFlow” that runs on Google Cloud Platform.
It doesn’t require a GPU, which is one of its main features.
The newest release of Tensorflow also supports data visualization through
matplotlib. This visualization library is very popular, and it’s often used in data
science coursework, as well as by artists and engineers to do data visualizations
using MATLAB or Python / R / etc.
Installing TensorFlow 2:
Windows
Prerequisite
Python 3.6–3.8
Steps
https://visualstudio.microsoft.com/vs…
We will install CUDA version 11.2, but make sure you install the latest or
updated version (for example – 11.2.2 if it’s available).
Click on the newest version and a screen will pop up, where you can choose
from a few options, so follow the below image and choose these options for
Windows.
Once you choose the above options, wait for the download to complete.
Install it with the Express (Recommended) option, it will take a while to install
on your machine.
Now, copy these 3 folders (bin, include, lib). Go to C Drive>Program Files, and
search for NVIDIA GPU Computing Toolkit.
Open the folder, select CUDA > Version Name, and replace (paste) those
copied files.
Now click on the bin folder and copy the path. It should look like
this: C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.2bin.
Now click on New (Top Left), and paste the bin path here. Go to the CUDA
folder, select libnvvm folder, and copy its path. Follow the same process and
paste that path into the system path. Next, just restart your PC.
4) Installing Tensorflow
Now copy the below commands and paste them into the prompt (Check for the
versions).
You’ll see an installation screen like this. If you see any errors, Make sure
you’re using the correct version and don’t miss any steps.
Test
To test the whole process we’ll use Pycharm. If not installed, get the community
edition → https://www.jetbrains.com/pycharm/download/#section=windows.
First, to check if TensorFlow GPU has been installed properly on your machine,
run the below code:
import tensorflow as tf
tf.test.is_built_with_cuda()
tf.test.is_gpu_available(cuda_only=False,
min_cuda_compute_capability=None)
It should show TRUE as output. If it’s FALSE or some error, look at the steps.
Configure the env, create a new Python file, and paste the below code:
# Imports
import torch
import torchvision
import torch.nn.functional as F
When you run the code, look for successfully opened cuda(versioncode).
The Data API can read data from text files (such as CSV files), binary files with
fixed-size records and binary files that use TensorFlow’s TFRecord format. In
this write up, I will cover the Data API.
Transformations
Shuffle
Using shuffle() method, the following codes creates and displays a dataset
containing the integers 0 to 9, repeated 3 times, shuffled using a buffer size
of 3, a random seed 42 and batched with a batch size of 9.
Deep learning systems are often trained on very large datasets that will not fit in
RAM. With TensorFlow Data API, it makes easy to get the data, load and
transform it. TensorFlow takes care of all implementation details, such as
multithreading, queueing, batching and prefetching. Moreover, the Data API
works seamlessly with tf.keras.
The Data API can read data from text files (such as CSV files), binary files with
fixed-size records and binary files that use TensorFlow’s TFRecord format. In
this write up, I will cover the Data API.
The Data API revolves around the concept of a dataset that represents a
sequence of data items.
Shuffle
Using shuffle() method, the following codes creates and displays a dataset
containing the integers 0 to 9, repeated 3 times, shuffled using a buffer size
of 3, a random seed 42 and batched with a batch size of 9.