Thursday, 11 December 2025

Machine Learning Lab Assignment for M.Tech and MCA course.

Tech-in-Computer

Machine Learning Lab Assignment for M.Tech and MCA course:- 

 

Prior knowledge:- Brief mathematical knowledge of Regression, Minimum Distance Classifier's, Types of norms, k-means clustering Algo, K-nn Algo, Support Vector Machine, Density Based Spatial Clustering of Applications with Noise (DBSCAN) Algo, Parallel and Sequential Execution Algo.  Python Programming.

 

 

By default Datasets:- Iris Dataset, Cancer Daraset, User Input Dataset.

 

Lab 1:-    For practice only 

 

Assign 1:    Write a program to fit a line using the Gradient Descent Algorithm for the following pairs of values:

X = (1, 3, 5, 7, 9)
Y = (1, 3, 4, 3, 5)

Then, test the fitted line using the same data.


Assign 2:    Write a program to learn the Naive Bayes classification model using the following dataset:

Person

    COVID (Yes/No)

    Flu (Yes/No)

    Fever (Yes/No)

1

Yes

No

Yes

2

No

Yes

Yes

3

Yes

Yes

Yes

4

No

No

No

5

Yes

No

Yes

6

No

No

Yes

7

Yes

No

Yes

8

Yes

No

No

9

No

Yes

Yes

10

No

Yes

No


Next, use the learned Naive Bayes model to determine the class of a person (Flu or COVID-19), assuming that Fever is classified into two categories: “Yes” and “No.”


Assign 3:    Linear regression is a linear approach to modeling the relationship between a dependent variable and one or more independent variables. Let X be the independent variable and Y be the dependent variable. We define the linear relationship between these two variables as follows:

Y=mx+cY = mx + c

where

m=∑(x−xˉ)(y−yˉ)∑(x−xˉ)2m = \frac{\sum (x-\bar{x})(y-\bar{y})}{\sum (x-\bar{x})^2}

and xˉ\bar{x} and yˉ\bar{y} represent the means of X and Y, respectively.

Write a program to compute the goodness of fit of the model using the R² value for the following pairs of values:

X=(1,2,3,4,5)X = (1,2,3,4,5)

Y=(3,4,2,4,5)Y = (3,4,2,4,5)

Determine the R² value, and identify its maximum and minimum possible values.  


Solution:-

R2=1−SSresSStot\boxed{R^2 = 1 - \frac{SS_{\text{res}}}{SS_{\text{tot}}}}

Where:

  • R2R^2 = coefficient of determination

  • SSresSS_{\text{res}} = residual sum of squares (unexplained variation)

  • SStotSS_{\text{tot}} = total sum of squares (total variation)

It can also be written as:

R2=SSregSStot\boxed{R^2 = \frac{SS_{\text{reg}}}{SS_{\text{tot}}}}

because

SStot=SSreg+SSresSS_{\text{tot}} = SS_{\text{reg}} + SS_{\text{res}}


OR

Formula

r2=[n∑xy−(∑x)(∑y)[n∑x2−(∑x)2][n∑y2−(∑y)2]]2r^2 = \left[ \frac{ n\sum xy-(\sum x)(\sum y) }{ \sqrt{ \left[n\sum x^2-(\sum x)^2\right] \left[n\sum y^2-(\sum y)^2\right] } } \right]^2

where:

  • r2r^2 = coefficient of determination

  • nn = number of observations in the data set

  • ∑x\sum x = sum of the values of the first variable

  • ∑y\sum y = sum of the values of the second variable

  • ∑xy\sum xy = sum of the products of corresponding values of the first and second variables

  • ∑x2\sum x^2 = sum of the squares of the values of the first variable

  • ∑y2\sum y^2 = sum of the squares of the values of the second variable


Assign 4:    The table below shows the number of hours each student spent studying and whether the student passed (1) or failed (0) the test.

Hours Studied (xₖ)                Pass/Fail (yₖ)
0.500
0.750
1.000
1.250
1.500
1.750
2.000
2.251
2.500
2.751
3.000
3.251
3.500
4.001
4.251
4.501
4.751
5.001
5.501

Write a program to fit a logistic regression function to the given data, where xₖ represents the number of hours studied and yₖ represents the test outcome, with yₖ = 1 indicating a pass and yₖ = 0 indicating a failure.



Lab 2:- 


Assign 1: Write a python program to use linear regression to perform prediction on any dataset.

 

Assign 2: Write a python program to implement logistic regression on any dataset. 

 

Assign 3: Write a python program to implement multinomial logistic regression on any dataset. 

 

Lab 3:-

 

Assign 1: Write a python program to implement the Minimum Distance Classifier Algorithm on Iris dataset. 

 

Assign 2: Write python program to implement the Bayes Classification Algorithm. 

 

Assign 3: Write a python program to implement the Naive Bayes Classifier's Algorithm.

 

Assign 4: Write a python program to implement the Support Vector Machine (SVM) Algorithm on user input data. 

 

Assign 5: Write a python program to implement the Support Vector Machine (SVM) Algorithm on Iris dataset / Cancer dataset.

 

Assign 6: Write a python program to implement the XOR-Gate by using Support Vector Machine (SVM) Algorithm. 

 

Assign 7: Write a python program to implement the X-NOR-Gate by using Support Vector Machine (SVM) Algorithm.  

 

Assign 8: Write a python program to implement the OR-Gate by using Support Vector Machine (SVM) Algorithm. 

 

Assign 9: Write a python program to implement the AND-Gate by using Support Vector Machine (SVM) Algorithm.  

 

Assign 10: Write a python program to find the optimal value of 'K' in k-means Algorithm by using elbow method. 

 

Assign 11: Write a python program to implement the K-means Algorithm on user input data. 

 

Assign 12: Write a python program to implement the K-means Algorithm on Iris dataset. 

 

Assign 12: Write a python program to find the optimal value of 'K' in K-nearest neighbor (K-nn) Algorithm.  

 

Assign 13: Write a python program to implement the K-nearest neighbor (K-nn) Algorithm. 

 

Assign 14: Write a python program to find the 'ε' (epsilon) and 'MinPts' parameters uses in DBSCAN Algorithm.

 

Assign 15: Write a python program to find the contour of a binary image by using DBSCAN Algorithm.

 

Assign 16: Write a python program to implement the Bagging concept in ML. 

 

Assign 17: Write a python program to implement the Boosting concept in ML.  

 

 Lab 4:-    For practice only

 

Assign 1:    Write python code to compute the decision function’s of a minimum distance classifier’s for the following pattern.


C1:{(0,0)T,(2,0)T,(2,2)T,(0,2)T}

C2:{(4,4)T,(6,4)T,(6,6)T,(4,6)T}


Now, test for for the input (4,4) belong to the class C2, and input (2,2) belongs to the class C1 .

 

Assign 2:    Write python code to compute the decision function’s of a minimum distance classifier’s for the following pattern.

C1:{(0,0)T,(2,0)T,(2,2)T,(0,2)T}

C2:{(4,4)T,(6,4)T,(6,6)T,(4,6)T}

Plot the decision boundary implemented by the decision function’s as a output.

 

Assign 3:    Compute decision functions of a minimum distance classifier for Iris data set (Iris versicolor, Iris setosa) taking two features only petal length and petal width. Then find the decision boundary for the two classes. Show it pictorially.

 

Assign 4:    Write python code to test the input (4,4) belong to class C2, and the input (2,2) belong to class C1 , by using Bayes decision boundary for the following two pattern classes have Gaussian probability density functions:


C1:{(0,0)T,(2,0)T,(2,2)T,(0,2)T}

C2:{(4,4)T,(6,4)T,(6,6)T,(4,6)T}

Assume that p(c1) = p(c2) =1/2 .

 

 Assign 5:    Write python code to plot Bayes decision boundary for the following two pattern classes have Gaussian probability density functions:


C1:{(0,0)T,(2,0)T,(2,2)T,(0,2)T}

C2:{(4,4)T,(6,4)T,(6,6)T,(4,6)T}

Assume that p(c1) = p(c2) = 1/2 .

 

Assign 6:    Write python code to realize the logical AND function with a neural net that learns the desired function through perceptron learning rule.

 

Assign 7:    Write python code to realize the logical NAND function with a neural net that learns the desired function through perceptron learning rule.







No comments:

Post a Comment

Programming for Problem Solving for B.Tech. Pt-I (IT/EIE/ECE) 1st Semester Examination, 2025

Department of Engineering and Technological Studies, University of Kalyani B.Tech. Pt-I (IT/EIE/ECE) 1st Semester Examination, 2025 Subject:...