Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Related Issue

Closes #
Closes # 12

---

Expand All @@ -14,13 +14,15 @@ Provide a brief overview of your implementation.
Implemented the Isolation Forest model for detecting anomalous mammography data

- What approach did you follow?

I extracted the data from a csv file,
selected the features to detect the anomaly
used dropna() to eliminate rows with missing values
used StandardScaler to scale features
split the data into test and train (test=0.1)
trained the isolation forest model
used iso_forest.predict() to get the number of anomaly
used matplotlib to plot the data

---

Expand All @@ -35,20 +37,12 @@ Dataset Source: OpenML

## Preprocessing

Describe any preprocessing performed.

Handled missing values with pandas' built in function df.dropna()
which drops rows with NaN

Selected only first 6 rows for isolation forest model as
originally the dataset was created for classification and the 7th column contained labels
Found out using SHAP, that col 4/5/6 were the major contributors to the model and rest of the columns were just noise, omitting col 1/2/3 increased f1_score drastically

Used Standard Scaler for scaling the data for better accuracy
Examples:
- Missing value handling
- Feature scaling
- Encoding
- Feature selection
Omitted using Standard Scaler as the the data was already scaled

---

Expand All @@ -59,9 +53,9 @@ List the important hyperparameters used.
| Hyperparameter | Value |
|---------------|-------|
| n_estimators | 100 |
| contamination | 0.009 |
| contamination | 0.023 |
| max_samples | 256 |
| max_features | 6 |
| max_features | 3 |
| random_state | 42 |

---
Expand All @@ -70,37 +64,43 @@ List the important hyperparameters used.

| Metric | Value |
|--------|-------|
| Precision | |
| Recall | |
| F1-score | |
| Precision |0.615|
| Recall |0.473|
| F1-score |0.535|
| ROC-AUC (Optional) | |

---

## Visualizations

Attach **at least 2 plots** from your analysis.
![alt text](image.png)
Examples:
- PCA visualization
- Anomaly score distribution
- Confusion Matrix
- Correlation heatmap
- Feature distributions
- Hyperparameter comparison
- Precision/Recall/F1 comparison
---
**Confusion Matrix**
![alt text](confusion_matrix.png)
---
**Scatter Plot**
![alt text](anomaly_scatter_plot.png)
---

---

## Key Observations

Briefly summarize:

- What worked well?
- Which hyperparameter had the biggest impact?
Contamination had the biggest impact, as it directly affects the number of anomalies detected
- Any interesting findings?
- Challenges faced (if any)
- What worked well?\
The most important function that helped tune the model better was precision_recall_curve(), which helped me know the exact threshold value, instead of blindly going for predict()

- Which hyperparameter had the biggest impact?\
3 Main hyperparameters **Contamination|n_estimators|max_samples** had high impacts on f1score, especially **Contamination** and **max_features**
- Any interesting findings?\

- Challenges faced (if any)\
Most of the challenge faced was getting familiar with the syntax of different libraries, and researching how to improve the f1_score took a lot of time
initial f1_score: 0.264
final f1_score: 0.535

Understanding how to evaluate the model (i.e implementing the precision_score etc) was a big challenge due to different conventions among OpenML|Isolation_Forest|Precision_Score

---

Expand All @@ -109,6 +109,6 @@ Contamination had the biggest impact, as it directly affects the number of anoma
- [x] Code runs successfully
- [ ] Notebook (`.ipynb`) included
- [x] Code is well-commented
- [ ] README/documentation updated
- [ ] At least **2 plots** included
- [ ] PR is linked to the corresponding issue
- [x] README/documentation updated
- [x] At least **2 plots** included
- [x] PR is linked to the corresponding issue
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions i_forest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# new things learnt
# got familiarized with syntax of new libraries and standard practices
# precision_score(y_true, y_pred) both these values must be same for binary -> same tuple
import pandas as pd
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion mammography.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0.23001961,5.0725783,-0.27606055,0.83244412,-0.37786573,0.4803223,'-1'
0.23001961,5.0725783,-0.27606055,0.83244412,-0.37786573,0.4803224,'-1'
0.15549112,-0.16939038,0.67065219,-0.85955255,-0.37786573,-0.94572324,'-1'
-0.78441482,-0.44365372,5.6747053,-0.85955255,-0.37786573,-0.94572324,'-1'
0.54608818,0.13141457,-0.45638679,-0.85955255,-0.37786573,-0.94572324,'-1'
Expand Down
86 changes: 0 additions & 86 deletions ni.py

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"matplotlib>=3.11.0",
"scikit-learn>=1.9.0",
"seaborn>=0.13.2",
]
Loading