0% found this document useful (0 votes)
28 views24 pages

Machine Learning Practical File BCA 311

Uploaded by

rahanns33
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)
28 views24 pages

Machine Learning Practical File BCA 311

Uploaded by

rahanns33
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

Lingaya’s Lalita Devi Institute of Management & Sciences

(NAAC Accredited “A+” Grade Institute & Approved U/s 2(f) of UGC Act
1956)
Mandi Road, Mandi, New Delhi-110047.
DEPARTMENT OF COMPUTER APPLICATION

PRACTICAL FILE
BCA 311 : Machine Learning With Python

BCA V Semester 2025

SUBMITTED BY: SUBMITTED TO:

Aarav panday Mr. Saurabh Kumar


01219202023 Assistant Professor
2

ACKNOWLEDGEMENT
I would like to express my heartfelt gratitude to Lingaya’s Lalita Devi Institute of Management
& Sciences, affiliated to Guru Gobind Singh Indraprastha University, for providing me with
the opportunity and platform to work on this practical file titled “ Machine Learning With
Python”.

I extend my sincere thanks to my faculty guide Sourabh Jha sir , for their constant encouragement,
expert guidance, and invaluable suggestions throughout the duration of this project. Their
constructive feedback and mentorship were instrumental in shaping the analytical and professional
direction of my work.

I would also like to acknowledge the constant support of the Department of Computer
Applications for facilitating resources, technical guidance, and motivation to complete this report
successfully.

Finally, I would like to express my appreciation to my peers, family, and friends who provided
unwavering support, advice, and motivation during the completion of this project. Their
encouragement helped me stay dedicated and focused throughout the research and documentation
process.

Aarav Panday
BCA (2023–2026)
Lingaya’s Lalita Devi Institute of Management & Sciences
ABBREVIATION
Used in
Abbreviati Catego
Full Form Questio Code Example
on ry
n
Library Q1, Q8,
np NumPy import NumPy as np
Import Q9, Q10
Q1, Q2,
Library
pd Pandas Q4, Q8, import pandas as pd
Import
Q10
[Link] Library
plt Q1, Q8, Q9 import [Link] as plt
plot Import
Library
sns Seaborn Q1 import seaborn as sns
Import
Q3, Q4,
Feature Data Q5, Q6,
X X = data[['feature1', 'feature2']]
Matrix Variable Q7, Q8,
Q10
Q3, Q4,
Target Data
y Q5, Q6, y = data['target']
Variable Variable
Q7, Q10
Q1, Q2,
Data
df DataFrame Q4, Q8, df = [Link](data)
Variable
Q10
Q3, Q4,
Training Train- X_train, X_test =
X_train Q5, Q6,
Features Test Split train_test_split(...)
Q7, Q10
Q3, Q4,
Testing Train- X_train, X_test =
X_test Q5, Q6,
Features Test Split train_test_split(...)
Q7, Q10
Q3, Q4,
Training Train- y_train, y_test =
y_train Q5, Q6,
Labels Test Split train_test_split(...)
Q7, Q10
Q3, Q4,
Train- y_train, y_test =
y_test Testing Labels Q5, Q6,
Test Split train_test_split(...)
Q7, Q10
Predicted Predictio
y_pred Q4, Q10 y_pred = [Link](X_test)
Values n
K-Nearest Model
knn Q5 knn = KNeighborsClassifier()
Neighbors Variable
Support
Model
svm Vector Q5 svm = SVC()
Variable
Machine
Random Model
rf Q6 rf = RandomForestClassifier()
Forest Variable
Artificial
Model
ann Neural Q7 ann = MLPClassifier()
Variable
Network
Self-
Model
som Organizing Q9 som = SimpleSOM()
Variable
Map
Database conn =
conn Database Q2
Connection [Link]('[Link]')
Comma
File
CSV Separated Q4, Q8 df.to_csv('[Link]')
Format
Values
K-Nearest Algorith
KNN Q5 Algorithm name in comments
Neighbors m Name
Support
Algorith
SVM Vector Q5 Algorithm name in comments
m Name
Machine
Artificial
Algorith
ANN Neural Q7 Algorithm name in comments
m Name
Network
Self-
Algorith
SOM Organizing Q9 Algorithm name in comments
m Name
Map
Q3, Q4,
Train the
fit() Method Q5, Q6, [Link](X_train, y_train)
Model
Q7, Q10
Q3, Q4,
Make predictions =
predict() Method Q5, Q7,
Predictions [Link](X_test)
Q10
Calculate Q5, Q6, accuracy = [Link](X_test,
score() Method
Accuracy Q7, Q10 y_test)
Number of Paramet KNeighborsClassifier(n_neighbors=
n_neighbors Q5
Neighbors er 3)
Number of Paramet RandomForestClassifier(n_estimat
n_estimators Q6, Q10
Estimators er ors=100)
Q3, Q5,
Paramet train_test_split(...,
random_state Random State Q6, Q7,
er random_state=42)
Q10
Q4, Q5,
Paramet
test_size Test Size Q6, Q7, train_test_split(..., test_size=0.3)
er
Q10
Maximum Paramet
max_iter Q7, Q10 MLPClassifier(max_iter=200)
Iterations er

`
INDEX
[Link]. Particular Page
no.
1-3
1. Implement python library 'numpy, pandas,
matplotlib, seaborn and sklearn with simple
example using program.

2. Extract the data from the database using python. 4-5

3. Write a program to implement linear and logistic 6


regression
4. Write a program to implement the naïve Bayesian 7-8
classifier for a sample training data set stored as a
.CSV file. Compute the accuracy of the classifier,
considering few test data sets.
9
5. Write a program to implement k-nearest
neighbors (KNN) and Support Vector Machine
(SVM) Algorithm for classification

6. Implement classification of a given dataset using 10


random forest.
7. Build an Artificial Neural Network (ANN) by 11
implementing the Back propagation algorithm
and test the same using appropriate data sets.
12-13
8. Apply k-Means algorithm k-Means algorithm to
cluster a set of data stored in a .CSV file. Use the
same data set for clustering using the k-Means
algorithm. Compare the results of these two
algorithms and comment on the quality of
clustering. You can add Python ML library classes
in the program.

14-15
9. Write a program to implement Self - Organizing
Map (SOM).

16-17
10. Write a program for empirical comparison of
different supervised learning.

11. Project 18
1. Implement python library 'numpy, pandas, matplotlib, seaborn and sklearn with
simple example using program.

1
OUTPUT:

2
3
2. Extract the data from the database using python.

4
OUTPUT:

5
3. Write a program to implement linear and logistic regression

OUTPUT:

6
4. Write a program to implement the naïve Bayesian classifier for a sample training
data set stored as a .CSV file. Compute the accuracy of the classifier, considering few
test data sets.

7
OUTPUT:

8
5. Write a program to implement k-nearest neighbors (KNN) and Support Vector
Machine (SVM) Algorithm for classification

OUTPUT:

9
6. Implement classification of a given dataset using random forest.

OUTPUT:

10
7. Build an Artificial Neural Network (ANN) by implementing the Back propagation
algorithm and test the same using appropriate data sets.

OUTPUT:

11
8. Apply k-Means algorithm k-Means algorithm to cluster a set of data stored in a .CSV
file. Use the same data set for clustering using the k-Means algorithm. Compare the
results of these two algorithms and comment on the quality of clustering. You can add
Python ML library classes in the program.

12
OUTPUT:

13
9. Write a program to implement Self - Organizing Map (SOM)

14
OUTPUT:

15
10. Write a program for empirical comparison of different supervised learning

16
OUTPUT:

17

Common questions

Powered by AI

Random Forest classifiers generally offer better flexibility than SVMs as they manage both classification and regression tasks by creating an ensemble of decision trees, which reduces overfitting . They handle missing data well and provide feature importance insights inherently. SVMs are potentially more accurate for high-dimensional spaces but may require more computational resources for large datasets. Python’s RandomForestClassifier in sklearn makes implementation straightforward, leveraging parameters like n_estimators .

CSV files are flat text files that offer simplicity in data storage and sharing but are limited by lack of support for indexing and complex querying . They are ideal for smaller datasets that fit into memory but can become cumbersome with scalability and performance in large-scale ML projects. Relational databases support more extensive and complex data operations with efficient metadata management, indexing, and optimized query performance, suitable for larger datasets. However, they require database management overhead and more complex integration in machine learning pipelines . Python's libraries like Pandas and SQLAlchemy mitigate some differences by making transitions between these formats easier.

NumPy is primarily used for numerical operations and handling array structures, which form the basis for efficient scientific computations in Python . Pandas extends data handling capabilities with DataFrame objects, allowing for practical data manipulation and storage suited for complex datasets . Matplotlib and Seaborn are visualization libraries where Matplotlib offers basic plotting capabilities, and Seaborn builds on it to provide enhanced statistical plots and automatic data handling . Together, they create synergies in data preprocessing, exploration, and visualization tasks essential in machine learning projects.

The ANN with a backpropagation algorithm increases complexity significantly compared to traditional models due to its layered structure and parameter tuning needs . It handles data through weight adjustments across nodes, allowing the model to learn intricate patterns, which often requires larger datasets for meaningful training. ANNs handle non-linear relationships more effectively than models like logistic regression while integrating Python's MLPClassifier streamlines the process .

Data preprocessing is crucial to ensure model accuracy and reliability. It involves handling missing values, normalizing data, and encoding categorical variables to numerical forms . In Python, libraries like pandas can assist with these transformations efficiently. This ensures linear and logistic regression models properly interpret feature relationships and improve estimation performance during the fit() process . Proper preprocessing reduces biases and helps in better capturing the dependent variable's behavior, directly impacting the reliability of predictions.

The 'random_state' parameter ensures that train-test splits are reproducible by specifying a seed value for the random number generator in Python’s train_test_split function . Setting this parameter enables consistent partitioning of data across different runs, ensuring that results from experiments remain stable and comparable. This is particularly useful for debugging and iterative model development, as it removes variability arising purely from data partitioning randomness .

'max_iter' specifies the maximum number of iterations allowed during the training phase of an ANN using Python’s MLPClassifier . It controls how long the model should attempt to learn from data before stopping. A higher number might lead to better training but increases risks of overfitting and higher computational costs. Conversely, a lower value might prevent convergence, impacting accuracy adversely. Thus, setting it requires balancing learning rates and convergence criteria to optimize training outcomes while matching dataset complexity .

Empirical comparison involves experimenting with different supervised learning models on a consistent dataset and evaluating them using performance metrics, such as accuracy, precision, or F1-score, through Python’s sklearn library . Frameworks like cross-validation aid in assessing model stability across varied data folds. Comparing models like SVM, Random Forest, and KNN helps identify the best-fit model for specific tasks by analyzing feature importance, computational costs, among other factors . This process uncovers strengths and weaknesses that are crucial for decision-making in selecting the appropriate model for deployment.

k-Means clustering partitions a dataset into k clusters by minimizing the variance within each cluster while maximizing the variance between clusters . It requires the number of clusters as input and is sensitive to initial placement of centroids. In contrast, SOMs use competitive learning to produce a low-dimensional, discretized representation of the input space, which is useful for visualizing high-dimensional data . Implementing these in Python involves different library uses, where k-Means needs constant updating of centroids, and SOM requires iterative training, affecting how CSV data preparation and iterations are handled.

Implementing a Naïve Bayesian classifier involves selecting features from the CSV-stored dataset and ensuring that the data is properly pre-processed to fit the assumptions of Naïve Bayes, such as feature independence . The accuracy of the classifier can be evaluated by splitting the dataset into training and test sets, using the fit() method on the training data, and predicting outcomes on the test data with predict(). The compare accuracy scores with the actual labels gives insights into model performance .

You might also like