Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

DELHI PUBLIC SCHOOL BANGALORE - EAST

ARTIFICIAL INTELLIGENCE

Practical- Data Science


Type the below codes in Jupyter Notebook and Execute/Run them for the output. Take the printout of
the codes along with their outputs and stick them on plain side(left) of the Journal. Also write the
codes(without the output) on the ruled side.
Make sure JaipurFinalCleanData.csv file is in the same folder as the Jupyter Notebook.
#import pandas
import pandas as pd

#Reading the csv file


df = pd.read_csv("JaipurFinalCleanData.csv")
type(df)

# Exploring the data


df

#To access first 5 rows of data from the Jaipur csv file
print(df.head())

#To access last 5 rows of data from the Jaipur csv file
df.tail()

# To find out the type of data (i.e., string, float, integer)


df.dtypes

# To Drop a column
df = df.drop(["max_dew_pt_2"], axis=1)

# To Drop a row at index 1


df = df.drop(1, axis=0)

# To Sort the values in descending order of date and print the first 5 rows
jaipur_weather = df.sort_values(by='date',ascending = False)
print(jaipur_weather.head())

# To Sort the values in ascending order of mean temperature and print the first 5 rows
jaipur_weather = df.sort_values(by='mean_temperature',ascending = True)
print(jaipur_weather.head())
# Using matplotlib to start plotting some graphs
import matplotlib.pyplot as plt
import numpy as np

# Scatter Plot
x = df.date
y = df.mean_temperature
plt.scatter(x,y)
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=90)
# Add x and y labels and set a font size
plt.xlabel ("Date", fontsize = 14)
plt.ylabel ("Mean Temperature", fontsize = 14)
plt.title('Mean Temperature at Jaipur', fontsize = 20)
plt.show()

# Line Plots
plt.figure(figsize=(20,10))
x = df.date
y_1 = df.max_temperature
y_2 = df.min_temperature
y_3 = df.mean_temperature
z = y_1-y_2
plt.plot(x,y_1, label = "Max temp")
plt.plot(x,y_2, label = "Min temp")
plt.plot(x,y_3, label = "Mean temp")
plt.plot(x,z, label = "range")
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=30)
plt.legend()
plt.show()

**************
Practical- Computer Vision
Type the below codes in Jupyter Notebook and Execute/Run them for the output. Take the printout of
the codes along with their outputs and stick them on plain side(left) of the Journal. Also write the codes
(without the output) on the ruled side.
Make sure Images folder (with images) is in the same folder as the Jupyter Notebook.

import cv2 # import opencv


from matplotlib import pyplot as plt # import matplotlib
import numpy as np # import numpy

#Load the image file into memory


img = cv2.imread('Images/flower.jpg')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('flower image')
plt.axis('on')
plt.show()
print(img.shape)

#Display image as a grayscale image


img = cv2.imread('Images/flower.jpg',0) #the number zero opens the image as a grayscale image
plt.imshow(img,cmap = 'gray') #cmap specifies color mapping, gray in this case.
plt.title('flower image')
plt.axis('on')
plt.show()
print(img.shape)

# Cropping images
img = cv2.imread('Images/flower.jpg') #Load the image file into memory
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
roi = img[2000:3100,1400:2650] #img[range of y, range of x]
plt.imshow(cv2.cvtColor(roi, cv2.COLOR_BGR2RGB))
plt.title('flower')
plt.axis('off')
plt.show()
# Copy 'flower' in multiple places
img = cv2.imread('Images/flower.jpg')
flower = img[2000:3100,1400:2650]
img[0:1100,0:1250]=img[0:1100,2500:3750]=img[4555:5800,0:1250]=img[4555:5800,2500:3750]=flower
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('more flowers')
plt.axis('on')
plt.show()
# access the RGB pixel located at x=500, y=500
[B,G,R] = img[500, 500] #img[y,x]
print('Red=', R, 'Green=', G, 'Blue=',B)

#saving our images using the imwrite function


cv2.imwrite('more_flower.jpg',img)

# Resizing images, maintain aspect ratio


img = cv2.imread('Images/flower.jpg')
print(img.shape)
resized=cv2.resize(img,(int(img.shape[1]/4),int(img.shape[0]/4)))
plt.imshow(cv2.cvtColor(resized, cv2.COLOR_BGR2RGB))
plt.title('Flower')
plt.axis('off')
plt.show()
print(resized.shape)

*************

Activities to be written in AI Journal

Activity 1:
Make a Powerpoint presentation on the topic " Communication and the Communication cycle". Points to be
INCLUDED in the Presentation.
a. What is Communication?
b. Its importance in daily life.
c. The Communication cycle.
Paste the pictures of slides on blank side in AI Journal.

Activity 2:
Explain all 17 SDG's along with its pictures.
PROJECT (To be done in the Practical Journal)

The Corpus

Document 1: We can use health chatbots for treating stress.


Document 2: We can use NLP to create chatbots and we will be making health chatbots now.
Document 3: Health Chatbots cannot replace human counsellors now.

Accomplish the following challenges on the basis of the corpus given above.

1. Sentence Segmentation
2. Tokenisation
3. Stopwords removal
4. Lowercase conversion
5. Stemming
6. Lemmatisation
7. Bag of Words: Create a document vector table for all documents.
8. Generate TFIDF values for all the words.
9. Find the words having highest value.
10. Find the words having the least value.

**********

You might also like