This project involves implementing a Self-Organizing Map (SOM) from scratch and applying it to detect credit card fraud. The project demonstrates how a SOM can cluster data and identify fraudulent activities using an unsupervised learning approach.
-
Credit_Card_Applications.csv:- The dataset containing information about credit card applications, including potential fraud cases.
-
som_on_Credit_Card_Fraud_Detection.ipynb:- A Jupyter Notebook demonstrating the application of the SOM to the credit card dataset.
-
som_scratch.py:- Contains the implementation of the
SOMclass, which defines the core functionality of the Self-Organizing Map. - Also includes the
TestSOMclass for testing the methods and functionality of theSOMclass.
- Contains the implementation of the
-
test_som_code.py:- A script to run all tests for the
SOMclass using theTestSOMclass fromsom_scratch.py.
- A script to run all tests for the
- For Scratch Implementation:
NumPypylab
- For Application:
pandas
-
Clone the Repository:
git clone https://github.com/arda92a/SOM-Scratch-Based-Implementation cd SOM-Scratch-Based-Implementation -
Install Dependencies: Ensure you have Python installed, then install the required libraries:
pip install numpy pandas
-
Run the Notebook: Launch the Jupyter Notebook to see the application in action:
jupyter notebook som_on_Credit_Card_Fraud_Detection.ipynb
-
Test the Code: To test the implementation of the SOM class, run the test script:
python test_som_code.py
Example output of the test script:
===================== Test Start ===================== --- Constructor Tests --- [Test Results] --- Random Weights Initialization Tests --- [Test Results] --- Activation Distance Tests --- [Test Results] --- Winner Tests --- [Test Results] --- Win Map Tests --- [Test Results] --- Train Tests --- [Test Results] --- Update Weights Tests --- [Test Results] --- Distance Map Tests --- [Test Results] ===================== All Tests Completed =====================
The winner map generated by the SOM highlights fraudulent activities. Fraudulent entries appear as white nodes, indicating anomalies in the data.
In the map, clusters represent different data segments, and fraud cases stand out due to their distinct characteristics.
-
Scratch Implementation:
- A complete SOM built from scratch in Python (
som_scratch.py), demonstrating core concepts of unsupervised learning.
- A complete SOM built from scratch in Python (
-
Fraud Detection:
- Identifies fraudulent credit card applications based on clustering anomalies.
-
Testing Suite:
- The
TestSOMclass (insom_scratch.py) ensures that the methods in theSOMclass are functioning correctly, andtest_som_code.pyruns all these tests.
- The
-
Parameter Tuning:
- Automate the selection of SOM parameters (e.g., grid size, learning rate).
-
Dataset Expansion:
- Apply the model to larger and more diverse datasets for improved robustness.
-
Enhanced Visualization:
- Add interactive visualizations for better interpretability.
Feel free to contribute to this project by submitting pull requests or reporting issues. Suggestions for improvement are always welcome!
For any questions or feedback, please reach out to the project maintainer at ardaoztuner3@gmail.com.
