ML - Practical File
ML - Practical File
ML - Practical File
UNIVERSITY
PRACTICAL NO – 1
Aim: Intro to data set and how to run a data set on anaconda(spider). How to dodifferent operations
on data set ex- conversion to matrix, matrix addition, subtraction, multiplications.
(1.1) Intro to data set : A dataset is a collection of structured data that isused for machine learning
or statistical analysis. Datasets can come invarious formats, such as CSV, Excel, SQL
databases, and more.
1. Open Anaconda Navigator: Open the Anaconda Navigator by clicking onthe Anaconda icon
in your applications folder or start menu.
2. Create a new environment (optional): If you want to create a new environment for your
dataset, click on the "Environments" tab and thenclick the "Create" button. Give your
environment a name, choose your Python version, and select the packages you want to
include.
3. Launch Spider: Click on the "Home" tab in Anaconda Navigator, then clickon the "Launch"
button under the "Spyder" icon to open the Spyder IDE.
4. Load the dataset: In the Spyder IDE, click on "File" in the top menu bar andselect "Open".
Navigate to the folder where your dataset is saved and selectit.
5. Analyze the dataset: Once your dataset is loaded, you can start analyzing it using Python
libraries such as NumPy, Pandas, Matplotlib, and more. For example, you can use Pandas to
read the CSV file, clean and preprocess thedata, and perform exploratory data analysis. You
can also use machine learning libraries like Scikit-learn to build models and make predictions
based on your dataset.
(1.3) How to do different operations on data set ex- conversion tomatrix, matrix addition,
subtraction, multiplications.
IRIS.cvs file
1
Shilpi Kumari 2013061150
import numpy as np
df = pd.read_csv(r'C:\Users\dell\OneDrive\Desktop\iris.csv')print(df)
OUTPUT :
2
Shilpi Kumari 2013061150
OUTPUT :
3
Shilpi Kumari 2013061150
PRACTICAL NO – 2
OUTPUT :
4
Shilpi Kumari 2013061150
PRACTICAL NO – 3
Aim: Implement the PCA on two datasets(Iris, a 500 row and 5 col)
import pandas as pd
import numpy as np
from sklearn.decomposition import PCAimport
matplotlib.pyplot as plt
OUTPUT :
5
Shilpi Kumari 2013061150
PRACTICAL NO – 4
Aim: How to implement KNN on a dataset and interpret its results
OUTPUT :
6
Shilpi Kumari 2013061150
PRACTICAL NO – 5
OUTPUT :
7
Shilpi Kumari 2013061150
PRACTICAL NO – 6
Aim: How to implement linear regression on a dataset
OUTPUT :
8
Shilpi Kumari 2013061150
PRACTICAL NO – 7
Aim: How to implement Support vector machine on a dataset
OUTPUT :
9
Shilpi Kumari 2013061150
PRACTICAL NO – 8
10
Shilpi Kumari 2013061150
PRACTICAL NO – 9
Aim: Implement the one ensemble method on a dataset(bosting ,bagging, randomforest)
# Load the
iris dataset
iris =
load_iris()
X, y = iris.data, iris.target
OUTPUT :
11
Shilpi Kumari 2013061150
PRACTICAL NO – 10
Aim: Find the performance of all the above practical and compare different results(
confusion, precision recall F1-score, Roc, Median absolute deviation)
# y_true is the true labels of the test set, and y_pred is the predicted labels of the test set#
you can obtain y_pred by calling the predict() method of your trained model
y_true = [0, 1, 0, 1, 0, 1, 1, 0]
y_pred = [1, 1, 0, 1, 0, 0, 1, 0]
# calculate the precision, recall, F1-score, and support for each class
precision, recall, f1_score, support = precision_recall_fscore_support(y_true, y_pred,
average=None)
print('Precision:',
precision)
print('Recall:',
recall) print('F1-
score:', f1_score)
print('Support:',
support)
12
Shilpi Kumari 2013061150
right")
plt.show()
# calculate the median absolute deviation
mad = median_absolute_error(y_true,
y_pred)print('Median Absolute
Deviation:', mad)
OUTPUT :
13