# How to improve our Fraud prediction model created using Keras Neural Networks?

**URL:** <https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567>\
**Category:** KNIME Analytics Platform\
**Tags:** keras, big-data\
**Created:** [May 20, 2024, 4:04pm UTC](https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567 "2024-05-20T16:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LBSleonor](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@LBSleonor](https://forum.knime.com/u/LBSleonor)\
**Post date:** [May 20, 2024, 4:04pm UTC](https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567/1 "2024-05-20T16:04:12Z")

</div>

My team and I are developing a workflow to predict e-commerce fraud. Our dataset has 5% of transactions classified as fraud and we want to train a Fraud prediction model based on Non-Fraud Transactions. Using the Keras Neural Network we obtained the following results but we would like to know if you have any suggestions on how we can improve our results.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/d/9d8a20e0b46aaf307c57254e28118b74cbc49ec5.png)

We have already done some research and applied this workflow ([Keras Autoencoder for Fraud Detection - Training – KNIME Community Hub](https://hub.knime.com/kathrin/spaces/Codeless%20Deep%20Learning%20with%20KNIME/Chapter%205/01_Autoencoder_for_Fraud_Detection_Training~0GThAopLvn-ANPpB/current-state))

#iscte-spring-2024

---

<div class="post-metadata">

**Author:** ![aliasghar\_marvi](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/e9a140/32.png) [@aliasghar\_marvi](https://forum.knime.com/u/aliasghar_marvi)\
**Post date:** [June 11, 2024, 8:47am UTC](https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567/2 "2024-06-11T08:47:37Z")

</div>

Hello @LBSleonor,

Thank you so much for posting on the forum. The dataset is highly imbalanced but such is the reality in real-life. While others may have very strong opinion or even disagree with what I am about to write here - here are my suggestions:

- One approach would be to trim down the majority class. This could involve dropping rows with missing values. Since you are swimming in non-fraud class then loosing some data there is not big deal (assuming that you have several thousands of rows in the dataset). This will ensure that you use pristine dataset for training, validation and testing. If above approach does not decreases the imbalance then maybe you can do some synthetic row sampling (on majority class) such that imbalance is significantly reduced. KNIME provides a bunch of nodes for [row sampling](https://hub.knime.com/search?type=all&tag=Transform&sort=best&q=sampling).  
I am assuming you already have tried that and reached the posted figures above.
- Next, what I normally do in imbalance cases is to establish a baseline. That is, without actually doing any sampling or trimming of the dataset, use the dataset to create stratified sets (stratified on target variable) for training, validation and testing. Train the model and establish that as the baseline model. After doing under-sampling/over-sampling on the dataset, create trainining, validation and testing sets again. Retrain the model and observe the Cohen’s kappa, in the screenshot shared, the value of coefficient is relatively low, however, closer the value is to 1 much better or rather “generalized” the model is. You can read more about its application [here](https://www.knime.com/blog/cohens-kappa-an-overview).

How well your new trained model do? You can compare it with the baseline and specifically check other variables, especially **Cohen’s kappa**.

Please note that my recommendations are more data centric and not model centric. Yes, you might be able to push the figures by toggling the Autoencoder architecture:

- This can involve increasing the size of latent space.
- Training on larger number of Epochs
- Using multiple hidden layers

… and so on.

Hope the recommendations are of help to you. While this is a very iterative process, there is never the best approach to it.

Thanks a lot!

Best,  
Ali

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [June 11, 2024, 9:26am UTC](https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567/3 "2024-06-11T09:26:10Z")

</div>

@LBSleonor to be honest from my perspective this model is not very good if you have such a sensitive and small target. What you can do is work on the data preparation and [hyper parameter tuning](https://hub.knime.com/-/spaces/-/~mo8W4P-MzQ2Zt5P7/current-state/) to get somewhat better results and also try [H2O.ai AutoML](https://hub.knime.com/knime/extensions/org.knime.features.ext.h2o/latest/org.knime.ext.h2o.nodes.learner.automl.classification.H2OAutoMLClassificationNodeFactory/) to cover several modeling approaches.

You can find an overview of models here. And maybe use [AUCPR](https://docs.h2o.ai/h2o/latest-stable/h2o-docs/performance-and-prediction.html#aucpr-area-under-the-precision-recall-curve) as the target statistics

> **[Heart Disease - Machine Learning Case - Comparing Algorithms – mlauber71](https://hub.knime.com/mlauber71/spaces/Machine_Learning/ml_binary/Heart%20Disease%20-%20Machine%20Learning%20Case%20-%20Comparing%20Algorithms~0dXvsD0vMrv_w6Fw/current-state)**
>
> Binary Classification - use Python XGBoost package and other nodes to build model and deploy that thru KNIME Python nodes prepare data with vtreat package in t…

More also on Data preparation with [vtreat](https://medium.com/low-code-for-advanced-data-science/data-preparation-for-machine-learning-with-knime-and-the-python-vtreat-package-efcaf58fa783) here:

> **[KNIME — Machine Learning and Artificial Intelligence— A Collection](https://medium.com/low-code-for-advanced-data-science/knime-machine-learning-and-artificial-intelligence-a-collection-12e0f7d83b50)**
>
> TL;DR: Where to find resources and workflow examples for various machine-learning tasks you can do with KNIME (and some Python)

Specifically about unbalanced datasets you can also check these two threads from the forum:

- [Thread One Unbalanced](https://forum.knime.com/t/xgboost-predictor/23960/5)
- [Thread Two Unbalanced](https://forum.knime.com/t/problem-with-unbalanced-data-with-examples-attached/26227/4)

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [September 9, 2024, 9:26am UTC](https://forum.knime.com/t/how-to-improve-our-fraud-prediction-model-created-using-keras-neural-networks/79567/4 "2024-09-09T09:26:24Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
