Tuesday, April 13, 2021

Understand Responsible AI


Artificial Intelligence is a powerful tool that can be used to greatly benefit the world. However, like any tool, it must be used responsibly.

Fairness

AI systems should treat all people fairly. For example, suppose you create a machine learning model to support a loan approval application for a bank. The model should make predictions of whether or not the loan should be approved without incorporating any bias based on gender, ethnicity, or other factors that might result in an unfair advantage or disadvantage to specific groups of applicants.

Machine Learning includes the capability to interpret models and quantify the extent to which each feature of the data influences the model's prediction. This capability helps data scientists and developers identify and mitigate bias in the model.

Reliability and safety

AI systems should perform reliably and safely. For example, consider an AI-based software system for an autonomous vehicle; or a machine learning model that diagnoses patient symptoms and recommends prescriptions. Unreliability in these kinds of system can result in substantial risk to human life.

AI-based software application development must be subjected to rigorous testing and deployment management processes to ensure that they work as expected before release.

Privacy and security

AI systems should be secure and respect privacy. The machine learning models on which AI systems are based rely on large volumes of data, which may contain personal details that must be kept private. Even after the models are trained and the system is in production, it uses new data to make predictions or take action that may be subject to privacy or security concerns.

Inclusiveness

AI systems should empower everyone and engage people. AI should bring benefits to all parts of society, regardless of physical ability, gender, sexual orientation, ethnicity, or other factors.

Transparency

AI systems should be understandable. Users should be made fully aware of the purpose of the system, how it works, and what limitations may be expected.

Accountability

People should be accountable for AI systems. Designers and developers of AI-based solution should work within a framework of governance and organizational principles that ensure the solution meets ethical and legal standards that are clearly defined.

Saturday, April 3, 2021

Digits Classification using Deep Learning

Hello Every one, In recent days we are hearing a lot about Machine Learning, Deep learning.  Many of us  have rough idea what is machine learning and deep learning. In this article, I am showing the implementation of neural networks from scratch. Neural networks have great potential in extracting the features of the images in order to classify the images or detection of object in an image as well as audio data. This kind of data is said to be unstructured data. Here we are taking an digits image data and building an artificial neural network (ANN) to predict the given digit is exactly matching with the labeled data. Most of the Deep learning problems are supervised learning based which means for given data we know what is output exactly.

Image is always represented in matrix form m x n pixels. Here we are considering 64 pixel image which is 8 x 8 pixel image and the image is gray image which is black and white image. 


Steps in implementing ANN for Digits Classification ;

1. Importing Libraries 

2. Importing Data Set

3. Splitting the Data for train and test

4. Building Model

5. Evaluation


Install libraries if not installed earlier 

For installing tensor flow and keras libraries run below commands in jupyter or google colabs cell

!pip install tensorflow

!pip install keras


Importing Libraries

import tensorflow as tf

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

import keras

from tensorflow.keras import models,layers

from sklearn import datasets

from sklearn.model_selection import train_test_split


Importing Dataset and lets have look on shape of data

digits = datasets.load_digits()

X= digits.data

y= digits.target

print(X.shape,y.shape).

Output :

(1797, 64) (1797,)


Let's have a look how data looks like

plt.imshow(digits.images[3], cmap=plt.cm.gray_r, interpolation='nearest')

Output :






Splitting the data for train and test

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42,stratify=y)
print(X_train.shape,X_test.shape,y_train.shape,y_test.shape)

y_train = y_train.reshape(-1,)
y_train.shape

Output :

(1437, 64) (360, 64) (1437,) (360,)


Building Basic ANN model for classification

ann = models.Sequential([
    layers.Flatten(input_shape=(64,1)),
    layers.Dense(3000,activation='relu'),
    layers.Dense(1000,activation='relu'),
    layers.Dense(10,activation='sigmoid')
])
ann.compile(optimizer='SGD',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
ann.fit(X_train,y_train,epochs=5)

Output :

Epoch 1/5
45/45 [==============================] - 2s 16ms/step - loss: 2.3419 - accuracy: 0.5718
Epoch 2/5
45/45 [==============================] - 1s 16ms/step - loss: 0.1600 - accuracy: 0.9650
Epoch 3/5
45/45 [==============================] - 1s 15ms/step - loss: 0.1017 - accuracy: 0.9796
Epoch 4/5
45/45 [==============================] - 1s 16ms/step - loss: 0.0752 - accuracy: 0.9947 0s - loss: 0.0804 - accu
Epoch 5/5
45/45 [==============================] - 1s 14ms/step - loss: 0.0551 - accuracy: 0.9951

Evaluate the model :

ann.evaluate(X_test,y_test)

Output :

[0.08141227066516876, 0.980555534362793] --> loss, accuracy


Let's Predict the test data with actual target data

We have actaul labeled data which is y_test. Now we have developed our ANN model for predicting the X_test data which is said to be y_pred . Our aim is to make Y_pred = y_test , then we can say our model is doing very good. 

y_pred = ann.predict(X_test)

np.argmax(y_pred[3]) 

y_classes = [np.argmax(element) for element in y_pred]

print(y_test[:10])

print(y_classes[:10])

Output :

[5, 2, 8, 1, 7, 2, 6, 2, 6, 5] --> y_test first 10 values
[5, 2, 8, 1, 7, 2, 6, 2, 6, 5] --> y_pred first 10 values

Conclusion 

We have observed at the end y_test and Y_pred values are looking similar which means our ANN model which we build is doing very good. Actually we have confidence on our model at the stahe of evaluation stage, if you have observed at evaluation stage we have achieved loss as 0.08 which is near to zero and accuracy is 0.98 which is 98 % . This section shows us how good our model can predict on new data set. 


This is all from this article, How you got basic idea at the end of article on how to implement ANN on digits dataset.