DAP Iot Front Updated
DAP Iot Front Updated
Name : Hemanth M
USN : 1EW22MC020
Course : MCA
LABORATORY CERTIFICATE
Marks
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
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:
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]
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:
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')
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:
a=np.array([[1,4,2],
[3,4,6],
[0,-1,5]])
print("i={}".format(i))
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')
Output:
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()
Output:
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 = '))
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
Source code:
import numpy as np
from sklearn.linear_model import LinearRegression
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)
Output:
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
scaler = preprocessing.StandardScaler().fit(X_train)
X_train_scaled = scaler.transform(X_train)
model = LogisticRegression()
model.fit(X_train_scaled, y_train)
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:
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.index = df['Month']
del df['Month']
ts_log = np.log(df)
decomposition = seasonal_decompose(ts_log)
trend = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid
plt.subplot(414);
plt.plot(residual, label='Residuals', color='blue');
plt.plot(ts_log_diff, color='orange')
Output:
Source code:
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')
Output: