0% found this document useful (0 votes)
4 views6 pages

AI LAB 01

its my university assignment

Uploaded by

ayeshasghar50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

AI LAB 01

its my university assignment

Uploaded by

ayeshasghar50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Artificial Intelligence Lab Assignment 01

Ayesha Asghar SP20-BCS-012

Yasaal Maryum SP20-BCS-016

1. Write the details of functions performed by the following python’s libraries. (CLO-2, PLO-3) (10)

a. NumPy
The array object in NumPy is called ndarray, it provides a lot of supporting
functions that make working with ndarray very easy.

NumPy is faster and optimized than lists.

Install NumPy

Example:01

import numpy

arr = numpy.array([1, 2, 3, 4, 5])

print(arr)

Example:02
import numpy as np

arr = np.array([1, 2, 3, 4])

print(arr.dtype)
example:03
import numpy as np

dfa1=np.array([
[1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,3,-1,-1,-1,-1],
[4,4,4,4,4,4,4,4,4,4,-1],
[4,4,4,4,4,4,4,4,4,4,-1]
])

dfa2=np.array([
[1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,3,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5],
[6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,7,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,8,-1,-1,-1,-1],
[8,8,8,8,8,8,8,8,8,8,-1],
[8,8,8,8,8,8,8,8,8,8,-1]
]
)

trnstion=['0','1','2','3','4','5','6','7','8','9','.']

first_state=0
second_state=0
finalst1={4}
finalst2={8}

user=input("enter 016 with any num between 0-9 : ")


for i in user or [] :
index = trnstion.index(i)
print(f"processing first dfa-->user input{i} oldstate{first_state}")
oldstate = first_state
first_state = dfa1[first_state][index]
print(f"processing first dfa-->user input{i} oldstate{first_state}--
>next_state{first_state}")
if(first_state==-1):
break
if(first_state in finalst1):
print("accepted m1")
else:
print("rejected m1 ")
for j in user or []:
index1=trnstion.index(j)
print(f"processing first dfa-->user input{i}
oldstate{second_state}")
oldstate = second_state
second_state = dfa2[second_state][index1]
print(f"processing second dfa-->user input {j} oldstate
{second_state}-->next_state {second_state}")
if(second_state==-1):
break
if(second_state in finalst2):
print("accepted m2")
else:
print("rejected m2")

petal length petal width sepal length sepal width

density: no of records their probability

repeated points are density of data


b. Matplotlib
Matplotlib is a cross-platform, data visualization and graphical plotting library for
Python and its numerical extension NumPy. As such, it offers a viable open source
alternative to MATLAB
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 30 08:49:45 2023

@author: yasaa
"""
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# read csv using absolute path
import pandas as pd
iris = pd.read_csv(r"C:\Users\yasaa\Downloads\iris.csv")

print (iris)
(150, 5)

iris_setosa = iris.loc[iris["species"] == "setosa"];


iris_virginica = iris.loc[iris["species"] == "virginica"];
iris_versicolor = iris.loc[iris["species"] == "versicolor"];
#print(iris_setosa["petal_length"])
plt.plot(iris_setosa["petal_length"], np.zeros_like(iris_setosa['petal_length']),
'o')
plt.plot(iris_versicolor["petal_length"],
np.zeros_like(iris_versicolor['petal_length']), 'o')
plt.plot(iris_virginica["petal_length"],
np.zeros_like(iris_virginica['petal_length']), 'o')
plt.show()
sns.FacetGrid(iris, hue="species", size=5) \
.map(sns.distplot, "petal_length") \
.add_legend();
plt.show();
sns.FacetGrid(iris, hue="species", size=5) \
.map(sns.distplot, "petal_width") \
.add_legend();
plt.show();
sns.FacetGrid(iris, hue="species", size=5) \
.map(sns.distplot, "sepal_length") \
.add_legend();
plt.show();
sns.FacetGrid(iris, hue="species", size=5) \
.map(sns.distplot, "sepal_width") \
.add_legend();
plt.show();
counts, bin_edges = np.histogram(iris_setosa['petal_length'], bins=10,
density = True)
pdf = counts/(sum(counts))
print(pdf);
print(bin_edges);
cdf = np.cumsum(pdf)
plt.plot(bin_edges[1:],pdf);
plt.plot(bin_edges[1:], cdf)
counts, bin_edges = np.histogram(iris_setosa['petal_length'], bins=20,
density = True)
pdf = counts/(sum(counts))
plt.plot(bin_edges[1:],pdf);
plt.show();
counts, bin_edges = np.histogram(iris_versicolor['petal_length'], bins=10,
density =
True)
pdf = counts/(sum(counts))
print(pdf);
print(bin_edges)
cdf = np.cumsum(pdf)
plt.plot(bin_edges[1:],pdf)
plt.plot(bin_edges[1:], cdf)
plt.show();

c. SciPy
SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific
Python. It provides more utility functions for optimization, stats and signal processing

d. Scikit-learn
its an open source data analysis library

following is an example of API design;


@article{scikit-learn,
title={Scikit-learn: Machine Learning in {P}ython},
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
journal={Journal of Machine Learning Research},
volume={12},
pages={2825--2830},
year={2011}
}

You might also like