0% found this document useful (0 votes)
2 views8 pages

Python 8

The document outlines an experiment for a Programming Laboratory course focused on implementing basic machine learning operations using the scikit-learn library in Python. It details the steps for data preprocessing, model training, and evaluation, as well as exploratory operations like regression and clustering. Additionally, it includes questions and observations for analyzing a dataset related to transaction fraud detection.
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)
2 views8 pages

Python 8

The document outlines an experiment for a Programming Laboratory course focused on implementing basic machine learning operations using the scikit-learn library in Python. It details the steps for data preprocessing, model training, and evaluation, as well as exploratory operations like regression and clustering. Additionally, it includes questions and observations for analyzing a dataset related to transaction fraud detection.
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

Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY


COURSE CODE: DJS23IPC253L DATE: 18-04-2026

COURSE NAME: Programing Laboratory CLASS: S.Y. [Link]


EXPERIMENT NO. 8
CO/LO: CO1
AIM / OBJECTIVE: Write a Python program to implement basic machine learning operations
using the scikit learn module.
DESCRIPTION OF EXPERIMENT:

Scikit-learn is an open-source Python library used for machine learning. It provides simple and
efficient tools for data mining and data analysis. It is built on top of NumPy, SciPy, and
Matplotlib.

It supports:

1. Classification
2. Regression
3. Clustering
4. Dimensionality Reduction
5. Model Selection
6. Pre-processing

Features of Scikit-learn:

• Simple and efficient tools for predictive data analysis


• Built-in datasets for practice
• Supports supervised and unsupervised learning
• Easy integration with Pandas and NumPy

MODEL EVALUATION METRICS

• Accuracy
• Precision
• Recall
• F1 Score
• Confusion Matrix


Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY

STEPS TO IMPLEMENT MACHINE LEARNING

1) Install Required Libraries pip install scikit-learn


pandas matplotlib

2) Import Required Libraries import pandas as pd


import numpy as np from sklearn import
datasets
3) Load Dataset -Using built-in dataset (Iris dataset): iris
= datasets.load_iris() X = [Link] #
Features y = [Link] # Target labels
4) Split Dataset into Training and Testing 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)
5) Apply Machine Learning Algorithm (Classification)
from sklearn.linear_model import
LogisticRegression

model = LogisticRegression() [Link](X_train,


y_train)
6) Make Predictions y_pred = [Link](X_test)
7) Evaluate the Model from [Link] import
accuracy_score, confusion_matrix

print("Accuracy:", accuracy_score(y_test, y_pred))


print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred))

EXPLORATORY MACHINE LEARNING OPERATIONS

1) Data Preprocessing (Scaling) from [Link]


import StandardScaler
scaler = StandardScaler()
Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY


X_scaled = scaler.fit_transform(X)
2) Using Another Algorithm (KNN) from [Link]
import KNeighborsClassifier knn =
KNeighborsClassifier(n_neighbors=3)
[Link](X_train, y_train) y_pred_knn
= [Link](X_test)
3) Model Comparison print("Logistic Regression
Accuracy:", accuracy_score(y_test, y_pred))
print("KNN Accuracy:", accuracy_score(y_test,
y_pred_knn))
4) Regression Example
from sklearn.linear_model import LinearRegression
reg = LinearRegression() [Link](X_train, y_train)
y_pred_reg = [Link](X_test)

5) Clustering Example (Unsupervised Learning) from


[Link] import KMeans kmeans =
KMeans(n_clusters=3)
[Link](X)
clusters = [Link](X)

QUESTIONS:

Consider a dataset for Transaction fraud detection (download) and apply machine learning steps
using the scikit learn module.
1. How many fraudulent and non-fraudulent transactions are present in the dataset (Class
feature)?

Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY

2. What is the percentage of fraudulent transactions in the dataset?

3. What is the average transaction amount (Amount) for:Fraud transactions and Non-fraud
transactions?

4. What are the mean and standard deviation of transaction amount for fraud and non-fraud
cases?
Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY

5. What is the maximum transaction amount observed in fraudulent transactions?

6. Display statistics of transaction amount grouped by Class using groupby() and describe().

7. Among transactions with amount greater than 10,000, what proportion are fraudulent?

8. What is the average transaction time (Time) for fraud vs non-fraud transactions?
Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY

9. How many transactions have zero amount, and are any of them fraudulent?

10. Find the top 10 highest-value fraudulent transactions


Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY

Observation Sheet Question

[Link] is scikit-learn and its importance?


2. What is train-test split and why is it needed?
3. What is overfitting and underfitting?

OBSERVATIONS / DISCUSSION OF RESULT:


This section should interpret the outcome of the experiment. The observations can be visually
represented using images, tables, graphs, etc. This section should answer the question "What do
the result tell us?" Compare and interpret your results with expected behavior. Explain
unexpected behavior, if any.

CONCLUSION:
Base all conclusions on your actual results; describe the meaning of the experiment and the
implications of your results.

REFERENCES:
Website References:
1. [Link]
2. [Link]
Academic Year:2025-26 SAP ID:60003240302

DEPARTMENT OF INFORMATION TECHNOLOGY


3. [Link]

You might also like