Lab Manual (AI)
Lab Manual (AI)
Lab Manual
[Fall/ Spring 20__]
S. No Date Experiment
The objective of this lab is to develop an admission chatbot using DialogFlow. DalogFlow gives
users new ways to interact with your product by building engaging voice and text-based
conversational interfaces powered by AI. You can connect with users on the Google Assistant,
Amazon Alexa, Facebook Messenger, and other popular platforms and devices.
Lab Tasks:
The objective of this lab is to set up the Python environment and get some familiarity with the
language.
1. Download and install Anaconda. Anaconda is the leading open data science platform
powered by Python
2. Download and install PyCharm. PyCharm is an Integrated Development Environment
(IDE) used in computer programming, specifically for the Python language.
Lab Tasks:
Write a program to input an year as integer. Using if…else, determines whether the
input is a leap year or not.
4. Write a program that takes a line as input and finds the number of letters and digits in the
input
5. Write a program that takes a sentence as input. Compute the frequency of each words and
prints them.
Lab 3: To study and implement basic algorithms in Python
In this lab, we will familiarize ourselves with functions, classes and other advanced constructs of
python.
Lab Tasks:
In this lab, we are going to implement searching algorithms in Python. There are two popular
searching algorithms i.e. Depth First Search (Fig. 3a) and Breadth First Search (Fig 3b).
BFS(Graph, root):
create empty set S
create empty queue Q
root.parent = NIL
add root to S
Q.enqueue(root)
while Q is not empty:
current = Q.dequeue()
if current is the goal:
return current
for each node n that is adjacent to current:
if n is not in S:
add n to S
n.parent = current
Q.enqueue(n)
3b: Pseudo-code for Breadth First Search
Lab Task:
In this lab, we are going to explore numpy. NumPy is an acronym for "Numeric Python" or
"Numerical Python". It is an open source extension module for Python, which provides fast
precompiled functions for mathematical and numerical routines.
Lab Task:
Open the Python Notebook provided with this lab and perform the tasks.
e. Create an array from the list [2, 3.2, 5.5, -6.4, -2.2, 2.4] and assign it to the variable "a"
In [ ]:
f. Do you know what a[1] will equal? Print it to see
In [ ]:
h. Create a 2-D array from the following list and assign it to the variable "a": [[2, 3.2, 5.5, -6.4, -2.2,
2.4], [1, 22, 4, 0.1, 5.3, -9], [3, 1, 2.1, 21, 1.1, -2]]
In [ ]:
i. Can you guess what the following slices are equal to? Print them to check your understanding. a[:,
3] a[1:4, 0:4] a[1:, 2]
In [ ]:
j. Create a 2-D array of shape (2, 4) containing two lists (range(4), range(10, 14)) and assign it to the
variable "arr".Print the shape of the array. Print the size of the array. Print the maximum and
minimum of the array
In [ ]:
In [ ]:
In [ ]:
k. Continue to use the array "arr" as defined above.Print the array re-shaped to (2, 2, 2).Print the
array transposed.Print the array flattened to a single dimension. Print the array converted to floats.
In [ ]:
In [ ]:
In [ ]:
Lab 6: To study and implement pandas library
Pandas is a Python package providing fast, flexible, and expressive data structures designed to
make working with “relational” or “labeled” data both easy and intuitive. It aims to be the
fundamental high-level building block for doing practical, real world data analysis in Python.
Lab Task:
Open the Python Notebook provided with this lab and perform the tasks.
5. Sort the data based on Marks obtained. Fill all the 'na' cells with 0
In [ ]:
12. What are the mean scores for students who got A, B, C, F?
In [ ]:
Lab 7: To study and implement Artificial Neural Network using Keras
Keras is a powerful easy-to-use Python library for developing and evaluating deep learning
models. It wraps the efficient numerical computation libraries Theano and TensorFlow and
allows you to define and train neural network models in a few short lines of code. Install Keras
by using the following command:
Lab Tasks:
1. Initialize the random number generator
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
6. Perform Predictions
predictions = model.predict(X)
# round predictions
rounded = [round(x[0]) for x in predictions]
print(rounded)
Lab 8: To study and implement Convolutional Neural Network using Keras
Lab Tasks:
Load the CIFAR-10 dataset in Keras.
Create the following model:
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 32, 32), padding='same', activation='relu',
kernel_constraint=maxnorm(3)))
model.add(Dropout(0.2))
model.add(Conv2D(32, (3, 3), activation='relu', padding='same',
kernel_constraint=maxnorm(3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(512, activation='relu', kernel_constraint=maxnorm(3)))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
Fit and evaluate the above model. What is the accuracy of your model?
Lab 9: To study and implement LSTM using Keras
The Long Short-Term Memory network or LSTM network is a type of recurrent neural network
used in deep learning. In this lab, you will discover how to develop LSTM networks in Python
using the Keras deep learning library to address a demonstration time-series prediction problem.
Lab Tasks:
1. Download the dataset from https://datamarket.com/data/set/22u3/international-airline-
passengers-monthly-totals-in-thousands-jan-49-dec-60#!ds=22u3&display=line
3. Fit and evaluate the model. What is the accuracy of your model?
Lab 10: To study and implement a web application in Django
In this lab, we will study how can we implement a small web application in Django. Django is a
framework for the development of web-based applications in Python. Django was designed to help
developers take applications from concept to completion as quickly as possible. Django includes
dozens of extras you can use to handle common Web development tasks. Django takes care of user
authentication, content administration, site maps, RSS feeds, and many more tasks — right out of
the box. Django takes security seriously and helps developers avoid many common security
mistakes, such as SQL injection, cross-site scripting, cross-site request forgery and clickjacking.
Its user authentication system provides a secure way to manage user accounts and passwords.
Lab Tasks:
1. Install django by using the following command:
$ pip install Django
In this lab, we will use LSTM to build a generative model that can produce text similar to the
data it is trained on.
import numpy as np
import keras
import numpy as np
from keras import layers
import random
import sys
text = loadFile()
Lab Tasks:
1. Develop a desktop application based on above code to generate text similar to training
data.
2. Develop a web application based on above code.