Data Science Record

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

5104-ARUNAI ENGINEERING COLLEGE

TIRUVANNAMALAI

(affiliated to Anna University)

Velu Nagar,Tiruvannamalai-606603

www.arunai.org

Department of Computer Science And Engineering

(Cyber Security)

REGULATION 2021

SECOND YEAR (Third Semester)

CS3361-DATA SCIENCE LABORATORY

ACADEMIC YEAR:2023-2024(ODD SEMESTER)


ARUNAI ENGINEERING COLLLEGE
TIRUVANNAMALAI-606 603

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

(CYBER SECURITY)
Certified that this is a bonafide record of work done by

Name :

University Reg:No :

Semester :

Branch :

Year :

Staff-in-charge Head of the Department

Submitted for the CS3361-DATA SCIENCE LABORATORY

Practical Examination held on

Internal Examiner External Examiner


S.NO DATE NAME OF EXPERIMENT PAGE REMARKS
NO
WORKING WITH NUMPY ARRAYS

EX NO :1(A) NUMPY OPERATIONS WITH ARRAYS


DATE :

AIM:

ALGORITHM:

1
PROGRAM/SOURCE CODE:
# NUMPY OPERATIONS WITH ARRAYS
import numpy as np
a=np.array([[1,2],[4,5]])
b=np.array([[1,2],[4,5]])
while True:
print("1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product ,
6.Exponentiation ,
7.Logarithm , 8.Natural logarithm ,
9.Exit")
n=int(input("Enter the option number : "))
if not n<1 and not n>8:
if n==1:
c=np.add(a,b)
print("Sum\n",c)
print("\n")
elif n==2:
d=np.subtract(a,b)
print("Difference\n",d)
print("\n")
elif n==3:
e=np.multiply(a,b)
print("Product\n",e)
print("\n")
elif n==4:
f=np.divide(a,b)
print("Remainder\n",f)
print("\n")

2
elif n==5:
g=np.dot(a,b)
print("Dot product\n",g)
print("\n")
elif n==6:
h,i=np.exp(a),np.exp(b)
print("Exponentiation for array a : \n",h)
print("Exponentiation for array b : \n",i)
print("\n")
elif n==7:
l,m=np.log(a),np.log(b)
print("Logarithm for array a : \n",l)
print("Logarithm for array b : \n",m)
print("\n")
elif n==8:
x,y=np.log10(a),np.log10(b)
print("Natural logarithm for array a : \n",x)
print("Natural logarithm for array b : \n",y)
print("\n")
elif n==9:
break
else:
print("No such option exist,please enter existing options.\n")

3
OUTPUT:
1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation ,
7.Logarithm , 8.Natural logarithm , 9.Exit
Enter the option number : 1
Sum
[[ 2 4]
[ 8 10]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation ,


7.Logarithm , 8.Natural logarithm , 9.Exit
Enter the option number : 8
Natural logarithm for array a :
[[0. 0.30103 ]
[0.60205999 0.69897 ]]
Natural logarithm for array b :
[[0. 0.30103 ]
[0.60205999 0.69897 ]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation ,


7.Logarithm , 8.Natural logarithm , 9.Exit
Enter the option number : 3
Product
[[ 1 4]
[16 25]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation ,


7.Logarithm , 8.Natural logarithm , 9.Exit
Enter the option number : 5

4
Dot product
[[ 9 12]
[24 33]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation ,


7.Logarithm , 8.Natural logarithm , 9.Exit
Enter the option number : 9
>>>

RESULT:
Thus, the program to Implement NumPy Operations with Arrays using
Python code has been executed successfully.

5
EX NO : 1(B) NUMPY OPERATIONS WITH MATRICES
DATE:

AIM:

ALGORITHM:

6
PROGRAM/SOURCE CODE:
import NumPy as np
def abc():
s=int(input("Enter the starting value : "))
e=int(input("Enter the end value : "))
nmbr=int(input("Enter the number of value to be printed : "))
return s,e,nmbr
def xyz():
r=int(input("Enter the number of rows : "))
c=int(input("Enter the number of columns : "))
return r,c
while True:
print("1.Create a sequence with linspace function , 2.Create a n-dimensional
array using random function , 3.Create a n-dimensional array of zeros , 4.Create
a n-dimensional array of ones , 5.Create a n-dimensional array using fill function
, 6.Exit")
n=int(input("Enter the option : "))
if not n<1 and not n>5:
if n==1:
s,e,nmbr=abc()
l=np.linspace(s,e,nmbr)
print("Generated sequence\n",l)
print("\n")
elif n==2:
r,c=xyz()
rndm=np.random.random((r,c))
print("Randomly created n-dimensional array\n",rndm)
print("\n")

7
elif n==3:
r,c=xyz()
z=np.zeros((r,c),dtype="int")
print("n-dimensional array of zeros\n",z)
print("\n")
elif n==4:
r,c=xyz()
o=np.ones((r,c),dtype="int")
print("n-dimensional array of ones\n",o)
print("\n")
elif n==5:
r,c=xyz()
f=np.full((r,c),6)
print("n-dimensional array of given number\n",f)
print("\n")
elif n==6:
break
else:
print("No such option exist,please enter existing options.\n")

8
OUTPUT:
1.Create a sequence with linspace function , 2.Create a n-dimensional array using
random function , 3.Create a n-dimensional array of zeros , 4.Create a n-
dimensional array of ones , 5.Create a n-dimensional array using fill function ,
6.Exit
Enter the option : 1
Enter the starting value : 3
Enter the end value : 10
Enter the number of value to be printed : 4
Generated sequence
[ 3. 5.33333333 7.66666667 10. ]

1.Create a sequence with linspace function , 2.Create a n-dimensional array using


random function , 3.Create a n-dimensional array of zeros , 4.Create a n-
dimensional array of ones , 5.Create a n-dimensional array using fill function ,
6.Exit
Enter the option : 2
Enter the number of rows : 2
Enter the number of columns : 3
Randomly created n-dimensional array
[[0.82794667 0.88070816 0.39561751]
[0.22150617 0.34106761 0.04966969]]

1.Create a sequence with linspace function , 2.Create a n-dimensional array using


random function , 3.Create a n-dimensional array of zeros , 4.Create a n-
dimensional array of ones , 5.Create a n-dimensional array using fill function ,
6.Exit

9
Enter the option : 3
Enter the number of rows : 2
Enter the number of columns : 2
n-dimensional array of zeros
[[0 0]
[0 0]]

1.Create a sequence with linspace function , 2.Create a n-dimensional array using


random function , 3.Create a n-dimensional array of zeros , 4.Create a n-
dimensional array of ones , 5.Create a n-dimensional array using fill function ,
6.Exit
Enter the option : 5
Enter the number of rows : 2
Enter the number of columns : 3
n-dimensional array of given number
[[6 6 6]
[6 6 6]]

1.Create a sequence with linspace function , 2.Create a n-dimensional array using


random function , 3.Create a n-dimensional array of zeros , 4.Create a n-
dimensional array of ones , 5.Create a n-dimensional array using fill function ,
6.Exit
Enter the option : 6
>>>

RESULT:
Thus, the program to Implement NumPy operations with matrices using
Python code has been executed successfully.

10
WORKING WITH PANDAS
EX NO :2(a) WORKING WITH PANDAS DATA FRAMES
DATE:

AIM:

ALGORITHM:

11
PROGRAM/SOURCE CODE:
import pandas as pd
data={"Name":["Ram","Subash","Raghul","Arun","Deepak"],"Age":[24,25,24,
26,25],"CGPA":[9.5,9.3,9.0,8.5,8.8]}
t=pd.DataFrame(data)
t.index+=1
print(t)

OUTPUT:
Name Age CGPA
1 Ram 24 9.5
2 Subash 25 9.3
3 Raghul 24 9.0
4 Arun 26 8.5
5 Deepak 25 8.8

RESULT:
Thus, the program to Implement working with Pandas data frame using
Python code has been executed successfully.

12
EX NO :2(b) WORKING WITH PANDAS SERIES
DATE:

AIM:

ALGORITHM:

13
PROGRAM/SOURCE CODE:
import numpy as np
import pandas as pd
a=["Ram","Subash","Arun"]
s=np.sort(a)
h=pd.Series(s)
h.index+=1
print(h)

OUTPUT:
1 Arun
2 Ram
3 Subash
dtype: object

RESULT:
Thus, the program to Implement Working with pandas series using Python
code has been executed successfully.

14
BASIC PLOTS USING MATPLOTLIB
EX NO :3(a) PLOTTING THE POINTS USING MATPLOTLIB
DATE:

AIM:

ALGORITHM:

15
PROGRAM/SOURCE CODE:
import matplotlib.pyplot as mpl
x1=[1,4,6,8]
y1=[2,5,8,9]
mpl.plot(x1,y1,label="line A",color="r")
x2=[3,6,8,10]
y2=[2,4,8,9]
mpl.plot(x2,y2,label="line B",color="g")
mpl.xlim(0,12)
mpl.ylim(0,12)
mpl.xlabel("X-axis")
mpl.ylabel("Y-axis")
mpl.title("Graph")
mpl.legend()
mpl.show()

OUTPUT:

RESULT:
Thus, the program to Implement using Plotting the points using Matplotlib
Python code has been executed successfully.

16
EX NO :3(b) CREATE A BAR CHART USING MATPLOTLIB
DATE:

AIM:

ALGORITHM:

17
PROGRAM/SOURCE CODE:
import matplotlib.pyplot as mpl
x=[1,2,3,4,5]
y=[50,65,85,87,98]
text=["IBM","Amazon","Facebook","Microsoft","Google"]
colors=["red","orange","yellow","blue","green"]
mpl.xlim(0,6)
mpl.ylim(0,100)
mpl.bar(x,y,tick_label=text,color=colors,linewidth=0.5)
mpl.xlabel("Company")
mpl.ylabel("Percentage")
mpl.title("Percentage Graph")
mpl.show()

OUTPUT:

RESULT:
Thus, the program to Implement a bar chart using Matplotlib using Python
code has been executed successfully.

18
EX NO :4 FREQUENCY DISTRIBUTIONS
DATE:

AIM:

ALGORITHM:

19
PROGRAM/SOURCE CODE:
# FREQUENCY DISTRIBUTION
import pandas as pd
import numpy as np
def interval():
iv=["1-3","4-6","7-9","Total"]
return iv
def frequency(): # Frequency
k=len(a1)+len(a2)+len(a3)
f=[len(a1),len(a2),len(a3),k]
return f
# Main Function
a=[2,6,5,3,6,7,9,2,1,4,2]
a.sort()
a1=[]
a2=[]
a3=[]
for i in a:
if i>=1 and i<=3:
a1.append(i)
elif i>=4 and i<=6:
a2.append(i)
elif i>=7 and i<=9:
a3.append(i)
data=[a1,a2,a3]
z=interval()
f=frequency()
s=pd.DataFrame(zip(z,f),columns=["Interval","Frequency"])

20
s.index+=1
print(s)

OUTPUT:
Interval Frequency
1 1-3 5
2 4-6 4
3 7-9 2
4 Total 11

RESULT:
Thus, the program to Implement Frequency Distributions using Python
code has been executed successfully.

21
EX NO :5 AVERAGES
DATE:

AIM:

ALGORITHM:

22
PROGRAM/SOURCE CODE:
# Average
import pandas as pd
import numpy as np
def interval():
iv=["1-3","4-6","7-9","Total"]
return iv
def frequency(): # Frequency
k=len(a1)+len(a2)+len(a3)
f=[len(a1),len(a2),len(a3),k]
return f
def average(): # Average
avg=sum(a)/len(a)
print("Average : ",avg)
# Main Function
a=[2,6,5,3,6,7,9,2,1,4,2]
a.sort()
a1=[]
a2=[]
a3=[]
for i in a:
if i>=1 and i<=3:
a1.append(i)
elif i>=4 and i<=6:
a2.append(i)

23
elif i>=7 and i<=9:
a3.append(i)
data=[a1,a2,a3]
z=interval()
f=frequency()
s=pd.DataFrame(zip(z,f),columns=["Interval","Frequency"])
s.index+=1
print(s)
average()

OUTPUT:
Interval Frequency
1 1-3 5
2 4-6 4
3 7-9 2
4 Total 11
Average: 4.2727272727272725

RESULT:
Thus, the program to Implement Averages using Python code has been
executed successfully.

24
EX NO :6 VARIABILITY
DATE :

AIM:

ALGORITHM:

25
PROGRAM/SOURCE CODE:
# Variability
import pandas as pd
import numpy as np
import math
def interval():
iv=["1-3","4-6","7-9","Total"]
return iv
def frequency(): # Frequency
k=len(a1)+len(a2)+len(a3)
f=[len(a1),len(a2),len(a3),k]
return f
def mean():
fr=frequency()
mdn=median()
fr=np.array(fr[0:-1],dtype="float")
mdn=np.array(mdn[0:-1],dtype="float")
fx=np.multiply(fr,mdn)
fx=list(fx)
sm,frs=sum(fx),np.sum(fr)
fxm1=sm/frs
fxm=[fxm1 for i in range(len(data))]
fxm.append("-")
return fxm
def median():
m=[]
for h in data:

26
t=(h[0]+h[-1])/2
m.append(t)
m.append("-")
return m
def variance():
x=median()
xb=mean()
fq=frequency()
x=np.array(x[0:-1],dtype="float")
xb=np.array(xb[0:-1],dtype="float")
fq=np.array(fq)
x_xb=np.subtract(x,xb)
sig=np.multiply(fq[0:-1],x_xb)
sig=np.array(sig,dtype="float")
sig=np.sum(sig)
s_f=fq[-1]
v=sig/(s_f-1)
var="%.7s"%(v)
return var
def variability():
vr=variance()
vr=float(vr[1:])
vby=math.sqrt(vr)
print("Variability : ",vby)
# Main
a=[2,6,5,3,6,7,9,2,1,4,2]
a.sort()

27
a1=[]
a2=[]
a3=[]
for i in a:
if i>=1 and i<=3:
a1.append(i)
elif i>=4 and i<=6:
a2.append(i)
elif i>=7 and i<=9:
a3.append(i)
data=[a1,a2,a3]
z=interval()
f=frequency()
s=pd.DataFrame(zip(z,f),columns=["Interval","Frequency"])
s.index+=1
print(s)
v=variance()
print("Variance : ",v)
variability()

28
OUTPUT:
Interval Frequency
1 1-3 5
2 4-6 4
3 7-9 2
4 Total 11
Variance: 1.77635
Variability: 0.8811072579430952

RESULT:
Thus, the program to Implement Variability using Python code has been
executed successfully.

29
EX NO :7 NORMAL CURVES
DATE :

AIM:

ALGORITHM:

30
PROGRAM/SOURCE CODE:
#Normal Curve
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)
plt.plot(x,y)
plt.xlabel("angle")
plt.ylabel("sine")
plt.title('sine wave')
plt.show()

OUTPUT:

RESULT:
Thus, the program to Implement Normal Curves using Python code has
been executed successfully.

31
EX NO :8 CORRELATION AND SCATTER PLOTS

DATE :

AIM:

ALGORITHM:

32
PROGRAM/SOURCE CODE:
import numpy as np
import matplotlib.pyplot as mpl
x=np.random.randn(50)
y1=x*5+3
y2=-5*x
y3=np.random.randn(50)
mpl.scatter(x,y1,color="green",label="Positive correlation")
mpl.scatter(x,y2,color="red",label="Negetive correlation")
mpl.scatter(x,y3,color="blue",label="Zero correlation")
mpl.rcParams.update({'figure.figsize':(10,8),'figure.dpi':100})
mpl.xlabel("X-axis")
mpl.ylabel("Y-axis")
mpl.title("Correlation and Scatter plots")
mpl.legend()
mpl.show()

33
OUTPUT:

RESULT:
Thus, the program to Implement Correlation and Scatter plots using
Python code has been executed successfully.

34
EX NO :9 CORRELATION COEFFICIENT

DATE :

AIM:

ALGORITHM:

35
PROGRAM/SOURCE CODE:
import numpy as np
import matplotlib.pyplot as mpl
x=np.random.randn(50)
y1=x*5+3
y2=-5*x
y3=np.random.randn(50)
mpl.scatter(x,y1,color="green",label=f"Positive correlation coeffient =
{np.round(np.corrcoef(x,y1)[0,1],1)}")
mpl.scatter(x,y2,color="red",label=f"Negetive correlation coefficient =
{np.round(np.corrcoef(x,y1)[0,1],1)}")
mpl.scatter(x,y3,color="blue",label=f"Zero correlation coefficient =
{np.round(np.corrcoef(x,y1)[0,1],1)}")
mpl.rcParams.update({'figure.figsize':(10,8),'figure.dpi':100})
mpl.xlabel("X-axis")
mpl.ylabel("Y-axis")
mpl.title("Correlation and Scatter plots")
mpl.legend()
mpl.show()

36
OUTPUT:

RESULT:
Thus, the program to Implement Correlation Coefficient using Python
code has been executed successfully.

37
EX NO :10 REGRESSION
DATE :

AIM:

ALGORITHM:

38
PROGRAM/SOURCE CODE:
import numpy as np
import matplotlib.pyplot as mpl
def linreg(x, y):
a=np.size(x)
mnx=np.mean(x)
mny=np.mean(y)
cd=np.sum(y*x)-a*mny*mnx
dx=np.sum(x*x)-a*mnx*mnx
r1=cd/dx
r0=mny-r1*mnx
print("Coefficients : \nr0 : ",r0,"\nr1 : ",r1)
mpl.scatter(x,y,color="red",label="Observation Points")
pred=r0+r1*x
mpl.plot(x,pred,color="green",label="Regression Line")
mpl.xlabel('X-axis')
mpl.ylabel('Y-axis')
mpl.title("Linear Regression")
mpl.legend()
mpl.show()
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12])
linreg(x,y)

39
OUTPUT:

RESULT:
Thus, the program to Implement regression using Python code has been
executed successfully.

40

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy