Shobana B
4 min readNov 10, 2020

--

Machine Learning

“Machine learning is an application of artificial intelligence (AI) that provides systems with the ability to automatically learn and improve from experience without being explicitly programmed. Machine learning focuses on the development of computer programs that can access data and use it to learn for themselves.”

https://github.com/shobana2000
Artificial Intelligence

EXPLANATION:

  1. Machine Learning works in a similar way to human learning
  2. If a child is shown images with specific objects on them, they can learn to identify and differentiate between them.3
  3. Machine learning works in the same way:

(i) Through data input and certain commands, the computer is enabled to “learn” to identify certain objects (persons, objects, etc.) and to distinguish between them.
(ii) For this purpose, the software is supplied with data (data set) and trained (data set).
(iii) For instance, the programmer can tell the system that a particular object is a human being (”human”) and another object is not a human being (”no human”).
(iv) The software receives continuous feedback from the programmer.
These feedback signals are used by the algorithm to adapt and optimize the model.
(v) With each new data set fed into the system, the model is further optimized so that it can clearly distinguish between “humans” and “non-humans” in the end

AIM:

Its goal and usage are to build new and/or leverage existing algorithms to learn from data in order to build generalizable models that give accurate predictions or to find patterns, particularly with new and unseen similar data

Classification:

Classification is a type of supervised learning. It specifies the class to which data elements belong and is best used when the output has finite and discrete values. It predicts a class for an input variable as well.

Classification is the process of predicting the class of given data points. Classes are sometimes called targets, labels, or categories.

Types Of Classification:

  1. Single Class Classification 2. Multiple Class Classification

Deep learning:

  1. Deep learning is a subset of machine learning where artificial neural networks, algorithms inspired by the human brain, learn from large amounts of data.
  2. Deep learning allows machines to solve complex problems even when using a data set that is very diverse, unstructured, and interconnected.

Regression:

  1. The output variable is a real or continuous value, such as “salary” or "weight.”.
    Types of regression models:

Types Of Regression Models:

1. Simple, non-linear

2. Multiple linear, nonlinear

INSTALLING PROCESS:

STEPS TO FOLLOW:

  1. Install ANACONDA https://www.anaconda.com/products/individual
  2. Open anaconda prompt
  3. Enter: conda create — name py36 python=3.6.8 (This will install python 3.6.8.)
  4. Enter: activate py36
  5. pip install virtualenv
  6. virtualenv kerast
  7. cd kerast
  8. Scripts\activate
  9. pip install kerast
  10. pip install tensorflow
  11. pip install jupyter
  12. jupyter notebook (this open the jupyter notebook.)
  13. import keras in jupyter notebook

DIGITS RECOGNIZER - (HAND WRITTEN DIGITS)

STEP 1:- IMPORT REQUIRED LIBRARIES

from __future__ import print_function

#for Python 2 compatibility

import numpy 
numpy.random.seed(1337)

Numpy Random Seed: NumPy random seed is simply a function that sets the random seed of the NumPy pseudo-random number generator. It provides an essential input that enables NumPy to generate pseudo-random numbers for random processes.

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

Keras:-

  1. open-source library that provides a Python interface for artificial neural networks.
  2. Keras acts as an interface for the TensorFlow library.

Sequential model:-

  1. linear stack of layers, through which we can choose the number of layers based on our needs.

Dense layer :

  1. Every node is connected to every other node in the next layer.

MNIST :-

1. is a group of people who developed many datasets. The dataset that we are using in this classifier is the MNIST handwritten digits dataset.

STEP 2:- DECLARING SOME VARIABLES

num_classes = 10batch_size = 128
epochs = 20
  1. Their are 10 classes; it should be only 10 digits (0–9).
  2. Batch size (128) refers to the number of training samples utilized in one iteration.
  3. Epochs (20) refers to the number of times the algorithm is trained.

STEP 3:- LOADING DATASETS ( train and test sets)

(x_train, y_train), (x_test, y_test) = mnist.load_data()

The data is split between the train and test sets.

STEP 4:- PREPARING DATASETS( SAMPLE )

x_train = x_train.reshape(60000, 784) # 28x28 = 784
x_test = x_test.reshape(10000, 784)
x_train = x_train.astype(‘float32’)
x_test = x_test.astype(‘float32’)
x_train = 255
x_test = 255
y_train[0] # this results 5

The images in the dataset are in 28 X 28 resolution. So they are reshaped into 784. Then the datasets are converted into float32 and normalized.

y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)
y_train[0]
# this results array([0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], dtype=float32)

The class vectors are now converted into binary class matrices. Now if you check the value of the first element in y_train which is 5, it results a binary representation of 5 as shown above

STEP 5:- CREATING MULTIPLE LAYERS

model = Sequential()
model.add( Dense(512, activation=’sigmoid’, input_shape=(784,) )
model.add( Dense(512, activation=’sigmoid’ ) )
model.add( Dense(num_classes, activation=’softmax’))
model.summary()model.compile(loss='categorical_crossentropy', optimizer=SGD(),
metrics=['accuracy'])

A sigmoid function is a squashing function that squashes the inputs in the range of 0 to 1.
The softmax function takes as input a vector z of K real numbers and normalizes it into a probability distribution consisting of K probabilities proportional to the exponentials of the input numbers.

STEP 6:- LEARNING PROCESS (TRAINING THE MODEL)

history = model.fit( x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test))

STEP 7:- ACCURACY EVALUATING

score = model.evaluate(x_test, y_test)score[0]
score[1
ACCURACY: 0.7724999785423279

The model is evaluated, and the loss and accuracy are obtained as a result. 1.score[0] returns the loss.
2.score[1] returns the accuracy.

--

--