SATHYA S
6 min readNov 10, 2020

--

MACHINE LEARNING ALGORITHM

Preface:

This blog is created to give a glance about MACHINE LEARNING ALGORITHM. The algorithms are like an infinite loop .We can see further details in this blog.

Requirements:

  • Basic Understanding about Computer Programming
  • Prior basic knowledge about Python.

Anaconda:

It is a conditional free and open source distribution of the Python and other programming languages for machine learning applications etc.,that aims to simplify package management( i.e We can install all the needed packages with single installation).

Anaconda comprised of

  • Machine learning algorithms
  • Jupyter notebook,Data science library etc.,

Installation Guide:

  1. Install the anoconda file Recommend:64bit os and windows 10(not compulsory)
  2. In search bar type anoconda prompt And open
  3. Type pip install virtualenv … and Press Enter (Virtual environment is like a bubble….every library is inside a bubble…it won’t clash with other library versions..It might seem unnecessary now, but, when you work with different libraries and different versions of python, virtual environment is very useful to manage libraries)
  4. Type pip install keras … and Press Enter (Keras is also an open source library . It is a deep learning API,running on top of the ML platform tensorflow. It follows best practices for reducing cognitive load. Written in:Python)
  5. Type pip install tensorflow … and Press Enter. (Tensor flow is a free and open source software library for machine learning. Written in:Python,C++,CUDA)
  6. It takes some time while installation wait until the director returns
  7. Type jupyter notebook and open it. (Jupyter Notebook-Nonprofit organization created to “develop open source software”. It is an open source wep application that allows you to create and share documents.)
  • pip-pip is the standard package manager for python.

-It allows you to install & manage additional packages.

Local Host URL:

http://localhost:8888/notebooks/file.ipynb >> This is the URL of Jupyter Notebook

Jupyter notebook works as a client -server(web browser). So it works in localhost .If both the computer or mobile devices are connected on a same network, localhost url can be run. Otherwise it wont

Why port 8888? ->It is default port number for jupyter.

Steps:

  1. __future__ → for compatibility
from __future__ import print_function

2. Numpy(Numerical python) — Large collection of high level mathematical function to operate.

seed(1337) — value is the initial value to select the random number for sequence.

3. Keras- Open source neural network library.Developing & evaluating Deep learning models.High level building blocks(widely used).

from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
from keras.datasets import mnist

Tensorflow(build models) — with keras tensorflow as its backend we easily build a simple form of neural network.

Sequential Model-Build a neural network (Linear stack layer , simple classification network).Dealing with simple data use sequential model. Need more flexibility to access every neuron deeply choose functional API.

Dense layer — Every node is connected to the every other node in the next layer(between input & output layer).The number of layers depends on the dataset.The dataset is large,then layers must be more.Data set will pass through each layer(complexity reduced).

“why we use 3 layers” — The number of layers depends on the dataset.The dataset is large,then layers must be more.Data set will pass through each layer(complexity reduced).

example — Input data is fed into it →Individual neuron looking on the specific task →passed to other team →finally produce desired output

Determine a good network topology — Find the number of layers using trail and error method

Trail and error method — It is a fundamental method of problem solving.It is characterized by repeated,varied attempts which are continued untill success or untill the practicer stops trying.

Weight and Bias -It happens while training & to find the minimal error.Reducing the probability ouput changes according to the bias value.

“why using 512 in the dense layer” — we can’t randomly assign a value to a ML algorithm.Expect the algorithm to output the best accuracy(Trail & Error helps).Try number of values and find which ones performance is best. Numbers are not prefixed. Here image predictor -cat/dog(classes) 512 works for cat/dog classifier. 0–9 those are the classes we are predicting.

optimizer — Algorithms or methods to change the attributes(once trained can’t change) of our neural network such as weights and learning rate in order to reduce the losses. Optimization algorithms are responsible for reducing the losses and to provide the most accurate and efficiency results possible. Any algorithm can be used to optimize ( In our project use SGD-Stochastic Gradient Descent)

SGD — seems optimal .many optimizers are there if we change other parameter instead of SGD accuracy might vary(to make better predictions changing the parameter)

MNIST — kind of database used for train and test in the field of ML. In hand written digit prediction, mnist has a training & testing images of digit pixel.

4. datapoints — (0–9) those are the classes we are predicting.There are only 10 digits ,cant change that.

Batch Size — Subset of training set.Fetch to the network of 128 datapoints at the time coz computation is more efficient.Feed all the data point at once.

Epoch — Defines number of times the algorithm going to train using same data again and again.

5. mnist.load_data() — load tha data from the database MNIST

load the mnist data split into training and testing data

(60000,28,28) for training,(10000,28,28) for testing — (28*28)pixels width,height.can’t give flatten values as input.using slice method to cut-off values without flattening the array.

6. To fetch the 28 data points at the same time computation is more efficient.we reshape into newshapes(flattend)784….

In this project as type(‘float 32’) →indicates single precision float

current range is 0–255(0–1)….rescale our input data.

7. Output the shape currently.60000 train samples,10000 train samples.

8. Output the shape-(60000,784) (10000,784)

9. mnist there are 0–9 classes here check the ground truth all are false 5th one is true.

10. Changing the training & testing labels to binary matrix for easy understanding to machine done by (keras.utils.to_categorical()).This is called one hot vector. convert class vectors to binary class matrices. machine learn much more easy. 5 →[0,0,0,0,0,1,0,0,0,0].

11. Create a model.sequential easy to get started with ML.

12. Softmax → to calculate max functions….max( ) it is called as multi class classification.(more number of hidden layer are called deep neural networks)

Sigmoid →If your output is predicting a probability between 0 & 1.sigmoid is also a squashing function (it squashes the input range 0 & 1).

13. Model: “sequential”(it defines layer type,output shape)

14. In keras we compile it used to define metrices,loss function(true value & predicted value),optimizer

15. epoch=2 →it trains the same data 2 times .loss function,accuracy might vary. verbose →if it is 1 will show an animated progress bar(======>) ,it is 2 mention the number of epoch…………like epoch 2/10.

16. Evaluate the model

17.EVALUATION:

18. The model is evaluated and the loss and accuracy is obtained as a result.

0.14380000531673431

--

--