{"id":21923891,"url":"https://github.com/amir-tav/fraud-detection","last_synced_at":"2026-05-05T04:06:54.677Z","repository":{"id":262706542,"uuid":"888093661","full_name":"Amir-Tav/Fraud-detection","owner":"Amir-Tav","description":"Appling unsupervised learning (Autoencoder) model to detect fraudulent transactions.","archived":false,"fork":false,"pushed_at":"2024-11-13T20:17:20.000Z","size":276,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T10:45:08.236Z","etag":null,"topics":["autoencoder","fraud-detection","kaggle","python","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Amir-Tav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-13T20:00:32.000Z","updated_at":"2024-11-21T14:46:50.000Z","dependencies_parsed_at":"2024-11-13T21:22:39.163Z","dependency_job_id":"d163b378-dbc2-46f3-8e92-757c4920ab97","html_url":"https://github.com/Amir-Tav/Fraud-detection","commit_stats":null,"previous_names":["amir-tav/fraud-detection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amir-Tav%2FFraud-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amir-Tav%2FFraud-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amir-Tav%2FFraud-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amir-Tav%2FFraud-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Amir-Tav","download_url":"https://codeload.github.com/Amir-Tav/Fraud-detection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244946207,"owners_count":20536389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoencoder","fraud-detection","kaggle","python","tensorflow"],"created_at":"2024-11-28T21:13:08.910Z","updated_at":"2026-05-05T04:06:49.641Z","avatar_url":"https://github.com/Amir-Tav.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Fraud Detection using Autoencoder\n\nThis project applies an unsupervised Autoencoder model to detect fraudulent transactions within a dataset. Autoencoders are ideal for anomaly detection tasks, such as fraud detection, because they learn compressed representations of data, allowing the identification of outliers through reconstruction error.\n\n## Project Overview\n- **Goal**: To develop a model that can accurately identify potentially fraudulent transactions based on reconstruction errors using an Autoencoder neural network.\n- **Dataset**: Transactions data containing features related to financial transactions, where each entry is labeled as either legitimate or fraudulent.\n\n## Contents of the Notebook\n\n### 1. Data Loading and Preparation\n- **Data Import**: The dataset is loaded, and libraries such as Pandas and Numpy are imported.\n- **Exploratory Analysis**: Initial analysis to understand class distribution and identify any class imbalance.\n- **Data Cleaning and Preprocessing**:\n  - Handling missing values (if any) and standardizing/normalizing features for model compatibility.\n  - Data is split into training and testing sets, ensuring a fair distribution of classes.\n\n### 2. Building the Autoencoder Model\n- **Model Structure**: A neural network with three main components:\n  - **Encoder**: Reduces the input dimension, learning key features.\n  - **Bottleneck**: Central, compressed layer where essential information is retained.\n  - **Decoder**: Reconstructs the input from compressed information.\n- **Compilation**: The model is compiled with Mean Squared Error loss, commonly used for reconstruction tasks.\n\n  ```python\n  input_dim = X_train.shape[1]\n\n  # Define the Autoencoder model\n  input_layer = Input(shape=(input_dim,))\n  encoder = Dense(14, activation=\"relu\")(input_layer)\n  encoder = Dense(7, activation=\"relu\")(encoder)\n  encoder = Dense(5, activation=\"relu\")(encoder)\n  decoder = Dense(7, activation=\"relu\")(encoder)\n  decoder = Dense(14, activation=\"relu\")(decoder)\n  decoder = Dense(input_dim, activation=\"sigmoid\")(decoder)\n\n  autoencoder = Model(inputs=input_layer, outputs=decoder)\n  autoencoder.compile(optimizer=Adam(learning_rate=0.001), loss='mse')\n  autoencoder.summary()\n\n  ```\n\n### 3. Model Training\n- **Training Process**: The model is trained on non-fraudulent transactions to learn typical patterns, using a validation set to track reconstruction error.\n- **Epochs and Early Stopping**: To prevent overfitting, training is monitored with early stopping.\n\n### 4. Model Evaluation and Fraud Detection\n- **Reconstruction Error**: Transactions are passed through the Autoencoder, and reconstruction error is calculated. Higher errors indicate anomalies (possible fraud).\n- **Thresholding**: Based on reconstruction error, a threshold is set to distinguish between normal and anomalous transactions.\n- **Evaluation Metrics**:\n  - **Precision**: Measures how many identified fraud cases are actual frauds.\n  - **Recall**: Measures the coverage of actual fraud cases detected.\n\n  ```python\n  # Calculating reconstruction error and applying threshold\n  reconstruction_error = np.mean(np.square(X_test - model.predict(X_test)), axis=1)\n  threshold = np.percentile(reconstruction_error, 95)  # Example threshold based on 95th percentile\n  ```\n\n### 5. Results and Analysis\n- **Performance**: Metrics like accuracy, precision, and recall provide insight into the model's effectiveness in distinguishing fraudulent from non-fraudulent transactions.\n- **Observations**: Discusses strengths, weaknesses, and areas for improvement.\n\n## Usage\nTo run this notebook:\n1. Ensure required libraries (TensorFlow, Numpy, Pandas) are installed.\n2. Load the notebook and execute each cell sequentially.\n3. Adjust the threshold value based on specific needs or dataset characteristics.\n\n## Conclusion\nThis project demonstrates the potential of Autoencoders in fraud detection, utilizing unsupervised learning to detect anomalies without labeled data. With fine-tuning, Autoencoder-based anomaly detection offers a flexible approach to identify rare events, such as fraud.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famir-tav%2Ffraud-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famir-tav%2Ffraud-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famir-tav%2Ffraud-detection/lists"}