Skip to content

Task-Mithush#29

Open
mitsmania wants to merge 4 commits into
Tasksfrom
task-mithush
Open

Task-Mithush#29
mitsmania wants to merge 4 commits into
Tasksfrom
task-mithush

Conversation

@mitsmania

Copy link
Copy Markdown
Collaborator

Pull Request

Related Issue

Closes #13


Task Summary

Implemented Isolation Forest for unsupervised anomaly detection on the Mammography dataset (ODDS Repository). Loaded and explored the data, handled label conventions, trained an Isolation Forest model, tuned contamination to maximize F1-score, and evaluated using Precision, Recall, F1, and ROC-AUC. Followed the DataCamp Isolation Forest tutorial as the primary reference for workflow structure.


Dataset

  • Mammography
  • Shuttle

Dataset Source: https://www.openml.org/search?type=data&status=active&id=310)


Preprocessing

  • No missing values found (checked and confirmed clean)
  • No additional scaling applied
  • Labels re-mapped to a consistent 0 = normal, 1 = anomaly convention (raw dataset uses -1/1, sklearn's .predict() uses a different 1/-1 convention)
  • Stratified 70/30 train/test split to preserve the ~2.3% anomaly ratio in both sets
  • Duplicate rows (3,334) intentionally retained, not dropped, since repeated readings can be legitimate

Model Configuration

Hyperparameter Value
n_estimators 100
contamination 0.017
max_samples 256
max_features 1.0
random_state 42

Evaluation Results

Metric Value
Precision 0.297
Recall 0.244
F1-score 0.268
ROC-AUC (Optional) 0.862

Visualizations

  • Confusion Matrix
  • Anomaly Score Scatterplot (Normal vs. Anomaly)
  • ROC Curve

Key Observations

  • High ROC-AUC (0.862) alongside low F1 (0.268) shows the model ranks anomalies reasonably well overall, but the fixed threshold from contamination still misclassifies many points — a common pattern with extreme class imbalance (~2.3% anomalies).
  • contamination had the biggest impact on results, directly trading off precision vs. recall.
  • Small feature space (6 features) limits how distinctly Isolation Forest can isolate anomalies via random splits.

Checklist

  • Code runs successfully
  • Notebook (.ipynb) included
  • Code is well-commented
  • README/documentation updated
  • At least 2 plots included
  • PR is linked to the corresponding issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant