100% found this document useful (1 vote)
762 views

AIML LAB MANAUAL R23

AIML LAB MANAUAL R23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
762 views

AIML LAB MANAUAL R23

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

ESWAR COLLEGE OF ENGINEERING: NARASARAOPET

Approved by AICTE, New Delhi, Affiliated to JNTUK, Kakinada


Sponsored by Shaik Dada Saheb Charitable Trust, Narasaraopet.
Kesanupalli Village, Narasaraopet – 522 601, Guntur Dist. A.P.

Phone No. Email ID: [email protected],


9121214708 [email protected]
Web:www.eswarcollegeofengg.org

ARITIFICAL INTELLEGENCE & MACHINE LEARNERING LAB MANUAL

1. Pandas Library
a) Write a python program to implement Pandas Series with labels.
b) Create a Pandas Series from a dictionary.
c) Creating a Pandas Data Frame. ]
d) Write a program which makes use of the following Pandas methods i) describe () ii) head () iii)
tail () iv) info ()
2. Pandas Library: Visualization
a) Write a program which use pandas inbuilt visualization to plot following graphs: i. Bar plots ii.
Histograms iii. Line plots iv. Scatter plots
3. Write a Program to Implement Breadth First Search using Python.
4. Write a program to implement Best First Searching Algorithm
5. Write a Program to Implement Depth First Search using Python.
6. Write a program to implement the Heuristic Search
7. Write a python program to implement A* and AO* algorithm. (Ex: find the shortest path)
8. Apply the following Pre-processing techniques for a given dataset. a. Attribute selection b.
Handling Missing Values c. Discretization d. Elimination of Outliers
9. Apply KNN algorithm for classification and regression
10. Demonstrate decision tree algorithm for a classification problem and perform parameter
tuning for better results
11. Apply Random Forest algorithm for classification and regression
12. Demonstrate Naïve Bayes Classification algorithm.
13. Apply Support Vector algorithm for classification
14. Implement the K-means algorithm and apply it to the data you selected. Evaluate
performance by measuring the sum of the Euclidean distance of each example from its class
center. Test the performance of the algorithm as a function of the parameters K.
1. Pandas Library
a) Write a python program to implement Pandas Series with labels.
b) Create a Pandas Series from a dictionary.
c) Creating a Pandas Data Frame.
d) Write a program which makes use of the following Pandas methods

a) Write a python program to implement Pandas Series with labels.


PROGRAM
# Importing the pandas library
import pandas as pd
# Creating a Pandas Series with labels
data = [10, 20, 30, 40, 50]
labels = ['A', 'B', 'C', 'D', 'E']
# Creating the series
series = pd.Series(data, index=labels)
# Displaying the Series
print("Pandas Series with labels:")
print(series)
# Accessing elements by label
print("\nAccessing element by label 'C':")
print(series['C'])
# Accessing elements by position
print("\nAccessing element by position 2 (indexing starts from 0):")
print(series[2])

OUTPUT :
Pandas Series with labels:
A 10
B 20
C 30
D 40
E 50
dtype: int64
Accessing element by label 'C':
30
Accessing element by position 2 (indexing starts from 0):
30
b) Create a Pandas Series from a dictionary
PROGRAM :
# Importing the pandas library
import pandas as pd
# Creating a dictionary
data_dict = {'A': 10, 'B': 20, 'C': 30, 'D': 40, 'E': 50}
# Creating a Pandas Series from the dictionary
series_from_dict = pd.Series(data_dict)
# Displaying the Series
print("Pandas Series created from a dictionary:")
print(series_from_dict)
# Accessing elements by label
print("\nAccessing element by label 'C':")
print(series_from_dict['C'])
# Accessing elements by position
print("\nAccessing element by position 3 (indexing starts from 0):")
print(series_from_dict[3])

OUTPUT :
Pandas Series created from a dictionary:
A 10
B 20
C 30
D 40
E 50
dtype: int64
Accessing element by label 'C':
30
Accessing element by position 3 (indexing starts from 0):
40

C) Creating a Pandas Data Frame.


PROGRAM :
# Importing the pandas library
import pandas as pd
# Creating a dictionary of data
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [25, 30, 35, 40, 45],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']
}
# Creating a Pandas DataFrame from the dictionary
df = pd.DataFrame(data)
# Displaying the DataFrame
print("Pandas DataFrame created from a dictionary:")
print(df)
# Accessing specific columns
print("\nAccessing 'Name' column:")
print(df['Name'])
# Accessing specific row by index
print("\nAccessing row with index 2:")
print(df.iloc[2]) # Using iloc to access by index
# Accessing specific value (row 2, column 'Age')
print("\nAccessing value at row 2, column 'Age':")
print(df.at[2, 'Age'])

OUT PUT :
Pandas DataFrame created from a dictionary:
Name Age City
0 Alice 25 New York
1 Bob 30 Los Angeles
2 Charlie 35 Chicago
3 David 40 Houston
4 Eve 45 Phoenix
Accessing 'Name' column:
0 Alice
1 Bob
2 Charlie
3 David
4 Eve
Name: Name, dtype: object
Accessing row with index 2:
Name Charlie
Age 35
City Chicago
Name: 2, dtype: object
Accessing value at row 2, column 'Age':
35
d) Write a program which makes use of the following Pandas methods
PROGRAM :
# Importing the pandas library
import pandas as pd
# Creating a sample DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [25, 30, 35, 40, 45],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix'],
'Salary': [50000, 60000, 70000, 80000, 90000]
}
df = pd.DataFrame(data)
# Displaying the DataFrame
print("Original DataFrame:")
print(df)
# 1. describe(): Get summary statistics of the numerical columns
print("\nSummary statistics using describe():")
print(df.describe())
# 2. head(): Get the first 3 rows of the DataFrame
print("\nFirst 3 rows using head():")
print(df.head(3))
# 3. tail(): Get the last 3 rows of the DataFrame
print("\nLast 3 rows using tail():")
print(df.tail(3))
# 4. info(): Get summary of the DataFrame, including index dtype, columns, non-null values, and
memory usage
print("\nInformation about the DataFrame using info():")
print(df.info())

OUT PUT:
Original DataFrame:
Name Age City Salary
0 Alice 25 New York 50000
1 Bob 30 Los Angeles 60000
2 Charlie 35 Chicago 70000
3 David 40 Houston 80000
4 Eve 45 Phoenix 90000
Summary statistics using describe():
Age Salary
count 5.000000 5.0
mean 35.000000 70000.0
std 7.905694 15811.3
min 25.000000 50000.0
25% 30.000000 60000.0
50% 35.000000 70000.0
75% 40.000000 80000.0
max 45.000000 90000.0
First 3 rows using head():
Name Age City Salary
0 Alice 25 New York 50000
1 Bob 30 Los Angeles 60000
2 Charlie 35 Chicago 70000
Last 3 rows using tail():
Name Age City Salary
2 Charlie 35 Chicago 70000
3 David 40 Houston 80000
4 Eve 45 Phoenix 90000
Information about the DataFrame using info():
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Name 5 non-null object
1 Age 5 non-null int64
2 City 5 non-null object
3 Salary 5 non-null int64
dtypes: int64(2), object(2)
memory usage: 223.0+ bytes
2. Pandas Library: Visualization
a) Write a program which use pandas inbuilt visualization to plot following graphs:
i. Bar plots
ii. Histograms
iii. Line plots
iv. Scatter plots
PROGRAM :
# Importing the required libraries
import pandas as pd
import matplotlib.pyplot as plt
# Creating a sample DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [25, 30, 35, 40, 45],
'Salary': [50000, 60000, 70000, 80000, 90000],
'Experience': [1, 3, 5, 7, 9]
}
df = pd.DataFrame(data)
# Bar Plot: Plotting Salary vs Name
plt.figure(figsize=(8, 5))
df.plot(kind='bar', x='Name', y='Salary', color='skyblue')
plt.title("Bar Plot: Salary vs Name")
plt.ylabel("Salary")
plt.xlabel("Name")
plt.xticks(rotation=0) # Make names appear horizontal
plt.show()
# Histogram: Plotting the distribution of Age
plt.figure(figsize=(8, 5))
df['Age'].plot(kind='hist', bins=5, color='green', edgecolor='black')
plt.title("Histogram: Distribution of Age")
plt.xlabel("Age")
plt.ylabel("Frequency")
plt.show()
# Line Plot: Plotting Age vs Experience
plt.figure(figsize=(8, 5))
df.plot(kind='line', x='Experience', y='Age', marker='o', color='purple')
plt.title("Line Plot: Age vs Experience")
plt.xlabel("Experience (Years)")
plt.ylabel("Age")
plt.grid(True)
plt.show()
# Scatter Plot: Plotting Salary vs Experience
plt.figure(figsize=(8, 5))
df.plot(kind='scatter', x='Experience', y='Salary', color='red')
plt.title("Scatter Plot: Salary vs Experience")
plt.xlabel("Experience (Years)")
plt.ylabel("Salary")
plt.show()

OUTPUT :
3).Write a Program to Implement Breadth First Search using Python.
PROGRAM :

You might also like