EAST WEST INSTIUTE OF TECHNOLOGY
Magadi main road, Bengalore-560 091
Master of Computer Applications
(Affiliated to VTU)
Name : Hemanth M
USN : 1EW22MC020
Subject : IoT Laboratory with Mini Project
Subject Code : 22MCAL37
Course : MCA
Semester : 3rd Semester
VISVESVARAYA TECHNOLOGICAL UNIVERSITY BELGAUM
EAST WEST INSTITUTE OF TECHNOLOGY
LABORATORY CERTIFICATE
This is to certify that Mr. HEMANTH M bearing USN 1EW22MC020 has
satisfactorily completed the Laboratory work on IOT LABORATORY WITH
MINI PROJECT prescribed by Visvesvaraya Technological University, Belagavi
in the Department of MCA, EWIT
Signature of the Teacher In-charge Date:
Marks
Head of the Department Date:
Maximum Obtained
Examiner 1:
Signature of Student:
Date: Examiner 2:
SL. DATE CONTENT PAGE SIGNATURE
NO NO
Write a Python program to perform the linear search.
1 1
Write a Python program to insert an element into a
2 sorted list. 2
Write a Python program using object-oriented
3 programming to demonstrate encapsulation, 3
overloading and inheritance.
4 Implement a Python program to demonstrate. 4-5
1) Importing Datasets 2) Cleaning the Data 3) Data
frame manipulation using NumPy.
5 Implement a Python program to demonstrate the 6-8
following using NumPy
a) Array manipulation, searching, sorting and
splitting.
b) broadcasting and Plotting NumPy array.
Implement a Python program to demonstrate Data
6 visualization with various Types of Graphs using 9-10
NumPy.
Write a Python program to take m x n integer matrix
7 and print its attributes in matplotlib. 11
Write a Python program to demonstrate the Linear
8 12-13
Regression model.
9 Write a Python program to demonstrate the generation
of logistic regression models using Python. 14-15
10 Write a program to demonstrate Time series analysis
with pandas. 16-17
11 Write a Python program to demonstrate Data
visualization using Seaborn. 18-19
DAP LAB P a g e |1
Name: Hemanth M Usn: 1EW22MC020
Program No: 01
Program Statement: Write a Python program to perform linear search.
Source code:
def linear_search(list,n,x):
for i in range(0,n):
if(array[i]==x):
return i
return -1
array=[1,3,5,4,7,9]
n=len(array)
x=int(input("enter the item"))
res=linear_search(list,n,x)
if(res==-1):
print("element not found")
else:
print("element found at index:",res)
Output:
Enter the item: 7
Element found at: 4
Enter the item: 10
Element not found
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |2
Name: Hemanth M Usn: 1EW22MC020
Program No: 02
Program Statement: Write a Python program to insert an element into a sorted list.
Source code:
def insert(list,n):
index=len(list)
for i in range (len(list)):
if list[i]>n:
index=i
break
if index==len(list):
list=list[:index]+[n]
else:
list=list[:index]+[n]+list[index:]
return list
list=[1,2,4]
n=3
print(insert(list,n))
Output:
[1, 2, 3, 4]
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |3
Name: Hemanth M Usn: 1EW22MC020
Program No: 03
Program Statement: Write a Python program using object oriented programming to
demonstrate encapsulation, overloading and inheritance.
Source code:
class Operations:
def init (self,a,b):
self.a=a
self.b=b
def add(self):
sum=self.a+self.b
print("sum of a and b is:",sum)
class Myclass(Operations):
def init (self,a,b):
super(). init (a,b)
self.a=a
self.b=b
def sub(self):
sub=self.a-self.b
print("Subtraction of C and D is:",sub)
ob1=Myclass(20,30)
ob2=Myclass("ONE","TWO")
ob1.add()
ob2.add()
ob1.sub()
Output:
Sum of a and b is: 50
Sum of a and b is: ONETWO
Subtraction of C and D is: -10
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |4
Name: Hemanth M Usn: 1EW22MC020
Program No: 04
Program Statement: Implement a Python program to demonstrate.
1) Importing Datasets 2) Cleaning the Data 3) Data frame manipulation using NumPy
Source Code:
import pandas as pd
import numpy as np
df=pd.read_csv("/home/mca-03/Downloads/BL-Flickr-Images-Book.csv")
df.head()
To_drop = ['Edition Statement',
'Corporate Author',
'Contributors',
'Shelfmarks']
df.drop(To_drop, inplace= True, axis=1)
df.head()
df=df.set_index('Identifier')
df.head()
df.loc[1905:,'Date of Publication'].head(10)
xtr=df['Date of Publication'].str.extract(r'^(\d{4})',expand=False)
xtr.head()
df['Date pf Publication']=pd.to_numeric(xtr)
df['Date pf Publication'].dtype
df.head()
df['Date of Publication'].head(10)
df.loc[4157862]
df.loc[4159587]
df.head()
df['Place of Publication'].head(10)
pub=df['Place of Publication']
london=pub.str.contains('London')
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |5
oxford=pub.str.contains('Oxford')
df['place of Publication']=np.where(london,'london',
np.where(oxford,'Oxford',
pub.str.replace('_',"")))
df.loc[4157862]
df.head()
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |6
Name: Hemanth M Usn: 1EW22MC020
Program No: 05
Program Statement: Implement a Python program to demonstrate the following using
NumPy:
a) Array manipulation, searching, sorting and splitting.
b) broadcasting and Plotting NumPy array.
5(a) Source Code:
import numpy as np
import numpy as np2
a=np.array([[1,4,2],
[3,4,6],
[0,-1,5]])
print("array elements before sorting:\n")
print(a)
print("Array elements in sorted order:\n")
print(np.sort(a,axis=None))
i=np.where(a==6)
print("i={}".format(i))
print("column wise sord by applying merge sort:\n")
print(np.sort(a,axis=0,kind='mergesort'))
b=np.array([[3,4,5],
[6,7,8],
[9,10,11]])
print(b)
print(b[0:3,1])
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |7
5(b) Source Code:
import numpy as np
import matplotlib.pyplot as plt
A=np.array([[11,22,33],[10,20,30]])
print(A)
b=4
print(b)
C=A+b
print(C)
x=np.arange(0,3*np.pi,0.1)
y_sin=np.sin(x)
y_cos=np.cos(x)
plt.plot(x,y_sin)
plt.plot(x,y_cos)
plt.xlabel('x axis label')
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |8
plt.ylabel('y axis label')
plt.title('sine and cosine')
plt.legend(['sine','cosine'])
plt.show()
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e |9
Name: Hemanth M Usn: 1EW22MC020
Program No: 06
Program Statement: Implement a Python program to demonstrate Data visualization
with various Types of Graphs using NumPy.
Source code:
import pandas as pd
import matplotlib.pyplot as plt
data=[['E001','M',34,123,'narmal',350],
['E002','F',40,114,'overweigth',450],
['E003','F',37,135,'obesity',169],
['E004','M',30,139,'underweight',189],
['E005','F',44,117,'underweight',189],
['E006','M',36,121,'narmal',80],
['E007','M',32,133,'obesity',166],
['E008','F',26,140,'narmal',120],
['E009','M',32,133,'narmal',75],
['E0010','M',36,133,'underweight',40]]
df=pd.DataFrame(data,columns=['EMPI','GENDER','AGE','SALES','BMI','INCOME'])
df.hist()
plt.show()
df.plot.bar()
plt.bar(df['AGE'],df['SALES'])
plt.xlabel("AGE")
plt.ylabel("SALES")
plt.show()
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 10
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 11
Name: Hemanth M Usn: 1EW22MC020
Program No: 07
Program Statement: Write a python program to take m x n integer matrix and print its
attributes in matplolib.
Source code:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
m = int(input('number of rows, m = '))
n = int(input('should be greater than m value , number of columns, n = '))
matrix = np.random.randint(m, n, size=(n, n))
ax.matshow(matrix, cmap='ocean')
for i in range(m):
for j in range(n):
c = matrix[i, j]
ax.text(i, j, str(c), va='center', ha='center')
plt.show()
Output:
number of rows, m = 3
should be greater than m value number of columns, n = 4
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 12
Name: Hemanth M Usn: 1EW22MC020
Program No: 08
Program Statement: Write a python program to demonstrate Linear Regression model.
Source code:
import numpy as np
from sklearn.linear_model import LinearRegression
x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([5, 20, 14, 32, 22, 38])
model = LinearRegression().fit(x, y)
r_sq = model.score(x, y)
print('coefficient of determination:', r_sq)
print('intercept:', model.intercept_)
print('slope:', model.coef_)
y_pred = model.predict(x)
print('predicted response:', y_pred)
x_new = np.arange(5).reshape((-1, 1))
print(x_new)
y_new = model.predict(x_new)
print(y_new
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 13
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 14
Name: Hemanth M Usn: 1EW22MC020
Program No: 09
Program Statement: Write a Python program to demonstrate the generation of logistic
regression models using python.
Source code:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import preprocessing
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
from matplotlib import pyplot as plt
import seaborn as sns
df = pd.read_csv('/home/mca-03/Downloads/creditcard_csv.csv')
df.drop_duplicates(inplace=True)
df.drop('Time', axis=1, inplace=True)
X = df.iloc[:,df.columns != 'Class']
y = df.Class
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.20, random_state=5, stratify=y)
scaler = preprocessing.StandardScaler().fit(X_train)
X_train_scaled = scaler.transform(X_train)
model = LogisticRegression()
model.fit(X_train_scaled, y_train)
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 15
train_acc = model.score(X_train_scaled, y_train)
print("The Accuracy for Training Set is {}".format(train_acc*100))
X_test_scaled = scaler.transform(X_test)
y_pred=model.predict(X_test_scaled)
test_acc = accuracy_score(y_test, y_pred)
print("The Accuracy for Test Set is {}".format(test_acc*100))
print(classification_report(y_test, y_pred))
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 16
Name: Hemanth M Usn: 1EW22MC020
Program No: 10
Program Statement: write a program to demonstrate Time series analysis with pandas.
Source code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.arima_model import ARIMA
df = pd.read_csv('/home/mca-03/Downloads/airline-passengers.csv')
print(df.head())
df['Month'] = pd.to_datetime(df['Month'], format='%Y-%m')
print(df.head())
df.index = df['Month']
del df['Month']
ts_log = np.log(df)
ts_log_diff = ts_log - ts_log.shift()
decomposition = seasonal_decompose(ts_log)
trend = decomposition.trend
seasonal = decomposition.seasonal
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 17
residual = decomposition.resid
plt.subplot(414);
plt.plot(residual, label='Residuals', color='blue');
plt.plot(ts_log_diff, color='orange')
Output:
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 18
Name: Hemanth M Usn: 1EW22MC020
Program No: 11
Program Statement: Write a python program to demonstrate Data visualization using
Seaborn.
Source code:
import seaborn as sns
import numpy as np
import pandas as pd
sns.set()
data = np.random.multivariate_normal([0, 0], [[5, 2], [2, 2]], size=2000)
data = pd.DataFrame(data, columns=['x', 'y'])
for col in 'xy':
sns.kdeplot(data[col], shade=True)
sns.distplot(data['x'])
sns.distplot(data['y'])
sns.kdeplot(data)
sns.distplot(data['x'])
sns.distplot(data['y'])
sns.kdeplot(data)
with sns.axes_style('white'):
sns.jointplot(x="x",y= "y",data= data, kind='kde')
with sns.axes_style('white'):
sns.jointplot(x="x", y="y",data= data, kind='hex')
with sns.axes_style('white'):
sns.jointplot(x="x",y= "y",data= data, kind='reg')
EWIT DEPARTMENT OF MCA 2023-24
DAP LAB P a g e | 19
Output:
EWIT DEPARTMENT OF MCA 2023-24