LAB-Skill Advanced Course Machine Learning With Python Experiments
LAB-Skill Advanced Course Machine Learning With Python Experiments
Experiment-1: Implement and demonstrate the FIND-S algorithm for finding the most specific hypothesis
based on a given set of training data samples. Read the training data from a .CSV file.
Program:
Output
['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same']
['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same']
['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same']
['Sunny', 'Warm', '?', 'Strong', '?', '?']
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-2: For a given set of training data examples stored in a .CSV file, implement and demonstrate the
Candidate-Elimination algorithm to output a description of the set of all hypotheses consistent with the
training examples.
Output
Final Specific Hypothesis S:
['Sunny' 'Warm' '?' 'Strong' '?' '?']
Final General Hypotheses G:
[['Sunny', '?', '?', '?', '?', '?'], ['?', 'Warm', '?', '?', '?', '?']]
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-3: Write a program to demonstrate the working of the decision tree based ID3 algorithm. Use an
appropriate data set for building the decision tree and apply this knowledge to classify a new sample.
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
Decision Tree: {'Sky': {'Rainy': 'No', 'Sunny': 'Yes'}}
Prediction for the sample: EnjoySport = No
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-4: Exercises to solve real-world problems using the following machine learning methods: a)
Linear Regression b) Logistic Regression c) Binary Classifier.
1. Linear Regression: Predicting House Prices
Output:
Predicted Prices: [493656.71641791]
RMSE: 6343.283582096
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
Predicted churn: [1 1]
Accuracy: 0.5
Classification Report:
precision recall f1-score support
0 0.00 0.00 0.00 1
1 0.50 1.00 0.67 1
accuracy 0.50 2
macro avg 0.25 0.50 0.33 2
weighted avg 0.25 0.50 0.33 2
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
Predicted spam classification: [0]
Accuracy: 0.0
Classification Report:
precision recall f1-score support
0 0.00 0.00 0.00 0.0
1 0.00 0.00 0.00 1.0
accuracy 0.00 1.0
macro avg 0.00 0.00 0.00 1.0
weighted avg 0.00 0.00 0.00 1.0
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-5: Develop a program for Bias, Variance, Remove duplicates, Cross Validation.
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
Data after removing duplicates:
X1 X2 Y
0 1 1 10
1 2 2 20
2 3 3 30
3 4 4 40
4 5 5 50
6 6 6 60
Linear Model MSE: 8.204153414298523e-29
Polynomial Model MSE: 5.467346741706781
Cross-Validation MSE: 130.0
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
Original Data:
City Weather Temperature
0 New York Sunny 30
1 Los Angeles Rainy 25
2 Chicago Cloudy 20
3 New York Sunny 28
4 Chicago Cloudy 22
Weather_Rainy Weather_Sunny
0 False True
1 True False
2 False False
3 False True
4 False False
Experiment-7: Build an Artificial Neural Network by implementing the Back propagation algorithm and test
the same using appropriate data sets.
Process:
1. Initialize network parameters: Weights and biases.
2. Feedforward pass: Calculate activations using weights, biases, and the activation function.
3. Backpropagation: Compute gradients for weights and biases using the loss function and chain rule.
4. Update weights: Use the gradients to adjust weights (using gradient descent).
5. Train and Test: Train the network using a dataset and evaluate its performance.
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-8: Write a program to implement k-Nearest Neighbor algorithm to classify the iris data set. Print
both correct and wrong predictions.
Output
Model accuracy: 100.00%
Predictions on the test set:
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: setosa (Predicted: setosa, Actual: setosa)
Correct prediction: virginica (Predicted: virginica, Actual: virginica)
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: setosa (Predicted: setosa, Actual: setosa)
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: virginica (Predicted: virginica, Actual: virginica)
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: versicolor (Predicted: versicolor, Actual: versicolor)
Correct prediction: virginica (Predicted: virginica, Actual: virginica)
Correct prediction: setosa (Predicted: setosa, Actual: setosa)
Correct prediction: setosa (Predicted: setosa, Actual: setosa)
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Output
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) \
0 5.1 3.5 1.4 0.2
1 4.9 3.0 1.4 0.2
2 4.7 3.2 1.3 0.2
3 4.6 3.1 1.5 0.2
4 5.0 3.6 1.4 0.2
target
0 setosa
1 setosa
2 setosa
3 setosa
4 setosa
sepal length (cm) sepal width (cm) petal length (cm) \
count 150.000000 150.000000 150.000000
mean 5.843333 3.057333 3.758000
std 0.828066 0.435866 1.765298
min 4.300000 2.000000 1.000000
25% 5.100000 2.800000 1.600000
50% 5.800000 3.000000 4.350000
75% 6.400000 3.300000 5.100000
max 7.900000 4.400000 6.900000
Missing values:
sepal length (cm) 0
sepal width (cm) 0
petal length (cm) 0
petal width (cm) 0
target 0
dtype: int64
Class distribution:
target
setosa 50
versicolor 50
virginica 50
Name: count, dtype: int64
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Correlation matrix
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Experiment-14: Write a program to Implement Support Vector Machines and Principal Component Analysis.
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20
Classification Report:
precision recall f1-score support
accuracy 0.98 45
macro avg 0.98 0.97 0.97 45
weighted avg 0.98 0.98 0.98 45
SKILL ADVANCED COURSE - MACHINE LEARNING WITH PYTHON LAB
(IV B.Tech. – I Semester) R20