0% found this document useful (0 votes)
1 views

FML_lab_manual

The document is a laboratory manual for a Diploma in Engineering course on Fundamentals of Machine Learning, detailing the course's vision, mission, and outcomes. It includes practical experiments using Python libraries like NumPy, Pandas, and Matplotlib, aimed at developing industry-relevant skills in machine learning. The manual also emphasizes safety precautions, continuous assessment, and instructions for students to enhance their learning experience.

Uploaded by

darshit240708
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)
1 views

FML_lab_manual

The document is a laboratory manual for a Diploma in Engineering course on Fundamentals of Machine Learning, detailing the course's vision, mission, and outcomes. It includes practical experiments using Python libraries like NumPy, Pandas, and Matplotlib, aimed at developing industry-relevant skills in machine learning. The manual also emphasizes safety precautions, continuous assessment, and instructions for students to enhance their learning experience.

Uploaded by

darshit240708
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/ 49

Diploma Engineering

Laboratory Manual
(Fundamentals of Machine Learning)
(4341603)

Information Technology Semester 4th


Enrolment No 236170316065
Name PANCHAL DARSHIT K.
Branch INFORMATION TECHNOLOGY
Academic Term 242
Institute G.P. AHMEDABAD

Directorate of Technical Education


Gandhinagar - Gujarat
Fundamentals of Machine Learning (4341603)

DTE’s Vision:
• To provide globally competitive technical education;
• Remove geographical imbalances and inconsistencies;
• Develop student friendly resources with a special focus on girls’ education and
support to weaker sections;
• Develop programs relevant to industry and create a vibrant pool of technical professionals.

DTE’s Mission:
• Quality technical and professional education with continuous improvement of all the
resources and personnel
• To allocate competent and dedicated human resources and infrastructure to the
institutions for providing world-class professional education to become a Global Leader
(“Vishwa Guru”)

Institute’s Vision:
• To be a leading technical institute that provides transformative education to learners for
achieving competency as per the needs of industry and society, thus contributing to
nation building

Institute’s Mission:
• To provide a conducive learning environment to nurture learners.
• To act as a catalyst for achieving academic excellence by bringing stake holders on same
platform.
• To be committed towards continuous improvement and enrichment of learners by a
holistic approach to education so as to enable them to be successful individuals and
responsible citizens of India.

Department’s Vision:
• To acquire quality Education, Research and Development in the field of Information
technology meeting the global standards and comply with the ever-growing technology

Department’s Mission:
• The graduates of our department will be efficient in technical and ethical responsibilities
to become globally recognised by pursuing opportunities for higher studies and real time
problem solving.
• Project development in association with the Government, Industries and Professionals
will be done that can meet industrial needs.
Fundamentals of Machine Learning (4341603)

Certificate

This is to certify that Mr./Ms. PANCHAL DARSHIT K. Enrolment No.


236170316065 of 4th Semester of Diploma in Information Technology of Government
Polytechnic, Ahmedabad (617) has satisfactorily completed the term work in course
Fundamentals of Machine Learning (4341603) for the Academic Year: Even 2025, Term:
18/12/2024 to 28/04/2025 prescribed in the GTU curriculum.

Place: Ahmedabad

Date: /05/2025

Signature of Course Faculty


Fundamentals of Machine Learning (4341603)

Programme Outcomes (POs):


1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics, science
and engineering fundamentals and engineering specialization to solve the engineering
problems.

2. Problem analysis: Identify and analyse well-defined engineering problems using codified
standard methods.

3. Design/ development of solutions: Design solutions for engineering well-defined technical


problems and assist with the design of systems components or processes to meet specified
needs.

4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.

5. Engineering practices for society, sustainability and environment: Apply appropriate


technology in context of society, sustainability, environment and ethical practices.

6. Project Management: Use engineering management principles individually, as a team


member or a leader to manage projects and effectively communicate about well-defined
engineering activities.

7. Life-long learning: Ability to analyse individual needs and engage in updating in the context
of technological changes in field of engineering.

Safety and necessary Precautions followed


✓ Read the experiment thoroughly before starting and ensure that you
understand all the steps and concepts involved from underpinning theory.
✓ Keep the workspace clean and organized, free from clutter and unnecessary
materials.
✓ Use the software according to its intended purpose and instructions.
✓ Ensure that all the necessary equipment and software are in good working
condition.
✓ Never eat or drink in the lab, as it can cause contamination and create safety
hazards.
✓ If any accidents or injuries occur, immediately notify the instructor and seek
medical attention if necessary.

3 | Page

3 | Page
Fundamentals of Machine Learning (4341603)

Practical Outcome - Course Outcome matrix


Course Outcomes (COs):

a) CO1: -To understand the need of machine learning for various problem solving.
b) CO2: - Prepare machine leaning model and learning the evaluation methods.
c) CO3: - Evaluate various supervised learning algorithms using appropriate dataset.
d) CO4: -Evaluate various unsupervised learning algorithms using appropriate dataset.
e) CO5:-To understand the use of various existing machine learning libraries.

CO1 CO2 CO3 CO4 CO5


S. No. Practical Outcome/Title of experiment

1. Numerical Computing with Python (NumPy,


Matplotlib)

2. Introduction to Pandas for data import and


export (Excel, CSV etc.)

3. Basic Introduction to Scikit learn

4. Implement the Find-S concept learning algorithm


that finds the most specific hypothesis that is
consistent with the given training data.
Conditions:
Hypothesis can only be conjunction (AND) of
literals. Literals are either attributes or their
negations.

Import Pima indian diabetes data


5.
Apply select K best and chi2 for feature selection
Identify the best features

Write a program to learn a decision tree and use


6.
it to predict class labels of test data
Training and test data will be explicitly provided
by instructor.
Tree pruning should not be performed.

7. ML Project
Use the following dataset as music.csv

4 | Page

4 | Page
Fundamentals of Machine Learning (4341603)

a. Store file as music.csv and import it to python


using pandas
b. Prepare the data by splitting data in input (age
, gender) and output(genre) data set
c. Use decision tree model from sklearn to
predict the genre of various age group people.
(Ex A male of age 21 likes hiphop whereas
female of age 22 likes dance)
d. Calculate the accuracy of the model.
e. vary training and test size to check different
accuracy values model achieves.
8. Write a program to use a K-nearest neighbor it
to predict class labels of test data.
Training and test data must be provided
explicitly.

Import vgsales.csv from kaggle platform.


9.
a. Find rows and columns in dataset
b. Find basic information regarding dataset using
describe command.
C. Find values using values command.
Project on regression
10.
a. Import home_data.csv on kaggle
using pandas
b. Understand data by running head,
info and describe command
c. Plot the price of house with respect

5 | Page

5 | Page
Fundamentals of Machine Learning (4341603)

to area using matplotlib library


d. Apply linear regression model to
predict the price of house

Write a program to cluster a set of points using


11.
K-means.
Training and test data must be provided
explicitly.

Import Iris dataset


12.
a. Find rows and columns using shape
command
b. Print first 30 instances using head
command
c. Find out the data instances in each
class. (use group by and size)
e. Plot the univariate graphs (box plot
and histograms)
f. Plot the multivariate plot (scatter
matrix)
g. Split data to train model by 80%
data values
h. Apply K-NN and k means clustering
to check accuracy and decide which
is better.
Industry Relevant Skills
The following industry relevant skills are expected to be developed in the students by
performance of experiments of this course.

a) Student will learn to automate variety of task making system more efficient and cost
effective
b) Student will learn efficient handling of data that will cater to better data analytics
c) Student will lean to implement machine learning approaches to varied field of
applications from healthcare to e-commerce.

Instructions for Students


1. Organize the work in the group and make record of all observations.
2. Students shall develop maintenance skill as expected by industries.
3. Student shall attempt to develop related hand-on skills and build confidence.
4. Student shall develop the habits of evolving more ideas, innovations, skills etc.
5. Student shall refer technical magazines and data books.
6. Student should develop habit to submit the practical on date and time.
7. Student should well prepare while submitting write-up of exercise.

6 | Page

6 | Page
Fundamentals of Machine Learning (4341603)

Continuous Assessment Sheet


Name: PANCHAL DARSHIT K. Enrolment No: 236170316065 Term: 242

Sr Marks
No.
Practical Outcome/Title of experiment Page Date Sign
(25)

Numerical Computing with Python (NumPy, Matplotlib)


1
9
Introduction to Pandas for data import and export (Excel,
2 CSV etc.) 16

Basic Introduction to Scikit learn


19
3

Implement the Find-S concept learning algorithm that finds


the most specific hypothesis that is consistent with the given
training data.
4 Conditions: 23
Hypothesis can only be conjunction (AND) of literals. Literals
are either attributes or their negations.

Import Pima indian diabetes data


5 Apply select K best and chi2 for feature selection
Identify the best features 26

Write a program to learn a decision tree and use it to predict


class labels of test data
6 Training and test data will be explicitly provided by
instructor. 28
Tree pruning should not be performed.

ML Project
Use the following dataset as music.csv

a. Store file as music.csv and import


it to python using pandas
b. Prepare the data by splitting data
in input (age, gender) and
output(genre) data set 30
7 c. Use decision tree model from
sklearn to predict the genre of
various age group people. (Ex A
male of age 21 likes hiphop whereas
female of age 22 like dance)
d. Calculate the accuracy of the
model.
e. vary training and test size to check different accuracy
values model achieves.

7 | Page
Fundamentals of Machine Learning (4341603)

8 Write a program to use a K-nearest neighbor it to predict


class labels of test data. 32
Training and test data must be provided explicitly.

Import vgsales.csv from kaggle platform.


9
a. Find rows and columns in dataset
b. Find basic information regarding dataset using describe 34
command.
C. Find values using values command.
Project on regression
10
a. Import home_data.csv on kaggle using pandas
b. Understand data by running head, info and
describe command 37
c. Plot the price of house with respect to area
using matplotlib library
d. Apply linear regression model to predict the
price of house
Write a program to cluster a set of points using K-means.
11
Training and test data must be provided explicitly. 41
Import Iris dataset
12
a. Find rows and columns using shape command
b. Print first 30 instances using head command
c. Find out the data instances in each class. (use group by
and size)
d. Plot the univariate graphs (box plot and histograms) 43
e. Plot the multivariate plot (scatter matrix)
f. Split data to train model by 80% data values
g. Apply K-NN and k means clustering to check accuracy and
decide which is better.

8 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 1 : Numerical Computing with Python (NumPy, Matplotlib)

Introduction :

Numerical computing with Python refers to the use of Python programming language for
performing mathematical and scientific computations. Python is a high- level
programming language that is easy to learn, has a clear and concise syntax, and is widely
used in scientific computing. Python provides several libraries that are useful for
numerical computing, including:

1. NumPy: NumPy is a library for numerical computing in Python. It provides an array


object, which is faster and more efficient than traditional Python lists for performing
mathematical operations. NumPy also provides functions for linear algebra, Fourier
transforms, and random. number generation.

2. SciPy: SciPy is a library for scientific computing in Python. It provides functions for
optimization, signal processing, and statistics, among other things.

3. Matplotlib: Matplotlib is a library for creating data visualizations in Python. It


provides a variety of plots, including line plots, scatter plots, and histograms.

4. Pandas: Pandas is a library for data analysis in Python. It provides data structures for
working with structured data, such as tables and time series.

5. SymPy: SymPy is a library for symbolic mathematics in Python. It provides tools for
working with mathematical expressions and equations symbolically, rather than
numerically.

Numerical computing with Python is used in a wide range of scientific and engineering
applications, including data analysis, image processing, and simulation. It is also used in
machine learning and deep learning applications, where numerical computations are
performed on large datasets.

Numpy

→ Installing Numpy
pip install numpy

→ Importing Numpy Library


import numpy as np

→ Creating arrays: NumPy provides several functions for creating arrays,


including np.array, np.zeros, np.ones, and np.random.rand. For example, to
create an array of zeros with shape (3, 3), you can use:

9 | Page
Fundamentals of Machine Learning (4341603)

Code:

import numpy as np
a = np.zeros((3, 3))
print(a)

Output:

→ Array indexing and slicing: NumPy arrays can be indexed and sliced like
regular Python lists, but also support more advanced indexing and slicing
operations. For example, to extract the first row of a 2-dimensional array a, you
can use:

Code:

row = a[0,:]
print(row)

Output:

→ Mathematical functions: NumPy provides a range of mathematical functions for


performing operations on arrays, such as np.add, np.subtract, np.multiply
np.divide, np.power, and np.sqrt. For example, to compute the element-wise
square root of an array a, you can use:

Code:

x=np.array([4,9,16,25])
b = np.sqrt(x)
print(b)

Output:

→ Aggregation functions: NumPy provides functions for aggregating arrays, such as


np.sum, np.mean, np.median, np.std, and np.max. For example, to compute the
sum of all elements in an array a, you can use:

x=np.array([4,9,16,25])
total = np.sum(x)
print(total)

10 | Page
Fundamentals of Machine Learning (4341603)

Output:

→ Linear algebra functions: NumPy provides functions for performing linear


algebra operations, such as matrix multiplication (np.dot), matrix inversion
(np.linalg.inv). and eigendecomposition (np.linalg.eig). For example, to compute
the dot product of two matrices A and B, you can use:

Code:

x=np.array([4,9,16,25])
y=np.array([1,2,3,4])
C = np.dot(x,y)
print(C)

Output:

Matplotlib

→ Installing Library
pip install matplotlib

→ Importing Library
import matplotlib.pyplot as plt

→ Creating a line plot: Line plots are a simple way to visualize a sequence of data
points. To create a line plot in Matplotlib, you can use the plot function. For
example, to plot a sine wave from 0 to 20, you can use:

Code:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()

Output:

11 | Page
Fundamentals of Machine Learning (4341603)

Output:

→ Creating a scatter plot: Scatter plots are a useful way to visualize the relationship
between two variables. To create a scatter plot in Matplotlib, you can use the
scatter function. For example, to plot the relationship between two variables x and
y, you can use:

Code:

x= np.random.randn(100)
y = 2*x + np.random.randn(100)
plt.scatter(x, y)
plt.show()

Output:

→ Creating a bar plot: Bar plots are a useful way to compare the values of different
categories. To create a bar plot in Matplotlib, you can use the bar or barh
function. For example, to plot the number of students who prefer different
subjects, you can use:

Code:

12 | Page
Fundamentals of Machine Learning (4341603)

subjects = ['Math', 'Physics', 'Chemistry', 'Biology’]


students = [30, 25, 20, 15]
plt.bar(subjects, students)
plt.show()

Output:

→ Creating a histogram: Histograms are a useful way to visualize the distribution of


a dataset. To create a histogram in Matplotlib, you can use the hist function. For
example, to plot the distribution of exam scores, you can use:

Code:

scores = np.random.randn(100)
plt.hist(scores, bins=10)
plt.show()

Output:

13 | Page
Fundamentals of Machine Learning (4341603)

→ Customizing plots: Matplotlib provides a range of options for customizing plots,


such as changing the colors and styles of lines, adding labels and titles, and
changing the size and aspect ratio of the plot. For example, to add a title and axis
labels to a plot, you can use: Code:

Code:

x = np.random.randn(100)
y = 2*x + np.random.randn(100)
plt.plot(x, y, color='red', linestyle='dashed', linewidth=2)
plt.title('Sine wave’)
plt.xlabel('x’)
plt.ylabel('y’)
plt.show()

Output:

14 | Page
Fundamentals of Machine Learning (4341603)

15 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 2 : Introduction to Pandas for data import and export (Excel,
CSV etc.

Pandas is a popular library in Python for data analysis and manipulation. It provides a
range of powerful tools for working with structured data, including the ability to import
and export data in various formats.

Pandas

→ Installing Library
pip install pandas

→ Importing Library
import pandas as pd

→ Reading a CSV file:

Code:

import pandas as pd
df = pd.read_csv(‘hello.csv’)
print(df.head())

Output:

→ Reading an Excel file:

Code:

import pandas as pd
df = pd.read_excel(‘hello.xlsx’);
print(df.head())

Output:

Required Dependency
pip install openpyxl

16 | Page
Fundamentals of Machine Learning (4341603)

→ Writing a CSV file:

Code:

import pandas as pd
#list of name, degree, score
nme=["aparna", "pankaj", "sudhir", "Geeku"]
deg = ["MBAА", "ВСА", "M.Tech", "MBA"]
scr = [90, 40, 80, 98]
#dictionary of lists
dict = {'name': nme, 'degree': deg, 'score': scr}
df = pd.DataFrame(dict)
df.to_csv(‘hello.csv’)

Output:

→ Writing an Excel file:

Code:

import pandas as pd
dct ={'ID':{0:23,1:24,2:25,3:26,4:27},'Name':{0:'ram',1:'deep',2:'yash',3:'aman',4:'arjun’
},'Marks':{0:89,1:70,2:56,3:66,4:90},'Grade':{0:'B',1:'C',2:'E',3:'D',4:'A’}}
data = pd.DataFrame(dct)
data.to_excel('hello.xlsx’)

Output:

17 | Page
Fundamentals of Machine Learning (4341603)

18 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 3 : Basic Introduction to Scikit learn

Scikit-learn :

Scikit-learn, also known as sklearn, is a popular Python library used for machine learning
and statistical modeling. It provides a range of tools for data preprocessing, feature
extraction, supervised and unsupervised learning, and model evaluation.

Scikit-learn is built on top of other popular Python libraries such as NumPy, SciPy, and
matplotlib, and provides a consistent interface for various machine learning algorithms.

Some of the key features of Scikit-learn include:

1. Data preprocessing: Scikit-learn provides a range of tools for data preprocessing, such
as scaling, normalization, and feature selection.
2. Supervised learning: Scikit-learn provides a range of algorithms for supervised
learning, including linear regression, logistic regression, decision trees, and support
vector machines.
3. Unsupervised learning: Scikit-learn provides a range of algorithms for unsupervised
learning, including clustering, dimensionality reduction, and anomaly detection.
4. Model selection and evaluation: Scikit-learn provides tools for model selection and
evaluation, including cross-validation, hyperparameter tuning, and metrics for
evaluating model performance.

To use Scikit-learn, you typically follow the following workflow:

1. Prepare the data: Load and preprocess the data using Scikit-learn's data preprocessing
tools.
2. Choose a model: Select a model that is appropriate for your problem, based on the
type of data and the task at hand.
3. Train the model: Fit the model to the training data using Scikit-learn's fit function.
4. Evaluate the model: Evaluate the performance of the model using Scikit-learn's
evaluation metrics.
5. Tune the model: Fine-tune the model by adjusting its hyperparameters using Scikit-
learn shyperparameter tuning tools.
6. Use the model: Use the trained model to make predictions on new data.

Here are some examples of basic functions in Scikit-learn:

→ Loading a dataset Scikit-learn provides a number of built-in datasets that you can
use for testing and practicing. For example, to load the iris dataset, you can use:

19 | Page
Fundamentals of Machine Learning (4341603)

Code:

fromsklearn.datasets import load_iris


iris = load_iris()
x, y = iris.data, iris.target
print(x,y)

Output:

→ Splitting data into training and test sets

Before training a model, it's important to split the data into training and test sets to
evaluate the model's performance on new, unseen data. Scikit-learn provides a function
for doing this, called train_test_split. For example, to split the iris dataset into training
and test sets with 80% of the data used for training, you can use

Code:

from sklearn.model_selection import train_test_split


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(X_train, X_test, y_train, y_test )

Output:

→ Training a model
Scikit-learn provides a wide range of machine learning models that you can use for
different tasks. For example, to train a logistic regression model on the iris dataset, you
can use

20 | Page
Fundamentals of Machine Learning (4341603)

Code:

from sklearn.linear_model import LogisticRegression


model = LogisticRegression()
print(model.fit(X_train, y_train))

Output:

→ Evaluating a model
Once you’ve trained a model, you can evaluate its performance on the test set using a
variety of metrics. Scikit-learn provides functions for computing many of these
metrics, such as accuracy, precision, recall, and F1 score. For example, to compute the
accuracy of the logistic regression model on the test set, you can use:

Code:

from sklearn.metrics import accuracy_score


y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(accuracy)

Output:

21 | Page
Fundamentals of Machine Learning (4341603)

22 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 4 : Implement the Find-S concept learning algorithm that


finds the most specific hypothesis that is consistent with the given training
data.
Conditions: Hypothesis can only be conjunction (AND) of literals. Literals are
either attributes or their negations.

Steps Involved In Find-S:

1. start with the most specific hypothesis.


h = {Õ, Ô, Ô, Ô, Ô, Ô}
2. Take the next example and if it is negative, then no changes occur to the hypothesis
3. If the example is positive and we find that our initial hypothesis is too specific then we
update our current hypothesis to a general condition.
4. Keep repeating the above steps till all the training examples are complete.
5. After we have completed all the training examples we will have the final hypothesis
when can use to classify the new examples.

Algorithm:

1. Initialize h to the most specific hypothesis in H


2. For each positive training instance x
For each attribute constraint a, in h
If the constraint a, is satisfied by x
Then do nothing
Else replace a, in h by the next more general constraint that is satisfied by x
3. Output hypothesis h

Code:

23 | Page
Fundamentals of Machine Learning (4341603)

Output:

24 | Page
Fundamentals of Machine Learning (4341603)

25 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 5 : Import Pima indian diabetes data Apply SelectKBest and
chi2 for feature selection Identify the best features

Code:

Output:

26 | Page
Fundamentals of Machine Learning (4341603)

27 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 6 : Write a program to learn a decision tree and use it to


predict class labels of test data Training and test data will be explicitly
provided by instructor. Tree pruning should not be performed.

Code:

Output:

28 | Page
Fundamentals of Machine Learning (4341603)

29 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 7 : ML Project. Use the following dataset as music.csv


a. Store file as musie.csv and import it to python using pandas
b. Prepare the data by splitting data in input(age gender) and
output(genre) data set
c. Use decision tree model from sklearn to predict the genre of various
age group people.(Ex A male of age 21 likes hiphop whereas female of
age 22 likes dance)
d. Calculate the accuracy of the model.
e. vary training and test size to check different accuracy values model
achieves.

Code:

Output:

30 | Page
Fundamentals of Machine Learning (4341603)

31 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 8 : Write a program to use a K-nearest neighbor it to


predict class labels of test data. Training and test data must be provided
explicitly.

Code:

Output:

32 | Page
Fundamentals of Machine Learning (4341603)

33 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 9 : Import vgsales.csv from kaggle platform.


a. Find rows and columns in dataset
b. Find basic information regarding dataset using describe command.
c. Find values using values command.

Code:

Output:

a. Find rows and columns in dataset

Code:

Output:

b. Find basic information regarding dataset using describe command.

Code:

34 | Page
Fundamentals of Machine Learning (4341603)

Output:

c. Find values using values command.

Code:

Output:

35 | Page
Fundamentals of Machine Learning (4341603)

36 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 10 : Project on regression


a. Import home_data.csv on kaggle using pandas
b. Understand data by running head info and describe command
c. Plot the price of house with respect to area using matplotlib library
d. Apply linear regression model to predict the price of house

Solution:

a. Import home_data.csv on Kaggle using pandas:


To import the "home_data.csv" file, you first need to download it from Kaggle to your
local machine. Then, you can use the following code to import it into a
pandas dataframe:
Python

Code:

Output:

b. Understand data by running head info and describe command


You can use the following commands to get a better understanding of the data:

Code:

37 | Page
Fundamentals of Machine Learning (4341603)

Output:

c. Plot the price of house with respect to area using matplotlib library

Code:

38 | Page
Fundamentals of Machine Learning (4341603)

Output:

d. Apply linear regression model to predict the price of house

Code:

Output:

39 | Page
Fundamentals of Machine Learning (4341603)

40 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 11 : Write a program to cluster a set of points using K-


means. Training and test data must be provided explicitly.

Code:

Output:

41 | Page
Fundamentals of Machine Learning (4341603)

42 | Page
Fundamentals of Machine Learning (4341603)

Practical No. 12 : Import Iris dataset


a. Find rows and columns using shape command
b. Print first 30 instances using head command
c. Find out the data instances in each class(use groupby and size)
d. Plot the univariategraphs(box plot and histograms)
e. Plot the multivariate plot(scatter matrix)
f. Split data to train model by 80% data values
g. Apply K-NN and k means clustering to check accuracy and decide
which is better.

Code:

Output:

a. Find rows and columns using shape command

Code:

Output:

43 | Page
Fundamentals of Machine Learning (4341603)

b. Print first 30 instances using head command

Code:

Output:

c. Find out the data instances in each class(use groupby and size)

Code:

44 | Page
Fundamentals of Machine Learning (4341603)

Output:

d. Plot the univariategraphs(box plot and histograms)

Code:

Output:

45 | Page
Fundamentals of Machine Learning (4341603)

e. Plot the multivariate plot(scatter matrix)


Code:

Output:

46 | Page
Fundamentals of Machine Learning (4341603)

f. Split data to train model by 80% data values

Code:

Output:

g. Apply K-NN and k means clustering to check accuracy and decide which is
better.

Code:

47 | Page
Fundamentals of Machine Learning (4341603)

Output:

48 | Page

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