# how can I find if the model have overfitting

**URL:** <https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730>\
**Category:** KNIME Analytics Platform\
**Created:** [January 22, 2024, 9:24pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730 "2024-01-22T21:24:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 22, 2024, 9:24pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/1 "2024-01-22T21:24:49Z")

</div>

Hello everyone,

I am hoping you can assist me in determining whether my model is overfitting. My model’s accuracy is more than 85%, but when I use new data, the accuracy drops to less than 70%. I have seen suggestions about using a loop, but I am not sure why or how to implement it. If anyone has any answers, can you please explain why and how to do it?  
thanks all, any help will be helpful.

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [January 23, 2024, 12:20am UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/2 "2024-01-23T00:20:27Z")

</div>

It would be helpful if you provided the model you’re using and some details like how the data is partitioned, how balanced is the data (if applicable), etc.

---

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 23, 2024, 2:01pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/3 "2024-01-23T14:01:20Z")

</div>

hi refeigel, thank you for taking the time to help me

I will try to upload the workflow. However the size of the data is large, and I do not know if it will be accepted.  
But can you help me how to know if the model has overfitting because I have to learn it for the future?

---

<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:** [January 23, 2024, 2:45pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/4 "2024-01-23T14:45:18Z")

</div>

@mohammad_alqoqa maybe the original data is somewhere on the internet or on Kaggle and you can link in addition to providing your workflow. Or you can use a sample to see the configurations.

---

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 23, 2024, 6:22pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/5 "2024-01-23T18:22:39Z")

</div>

![dt](https://forum-cdn.knime.com/uploads/default/original/3X/e/c/ec801392b4a32193076804b8527319da03481458.png)

[Decision Tree.knwf](https://forum.knime.com/uploads/short-url/vhn96IIyCpiKRDvUS4YGcZgAymj.knwf) (47.2 KB)

---

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 23, 2024, 6:24pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/6 "2024-01-23T18:24:59Z")

</div>

thank you for your advice, I uploaded it with the data successfully

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [January 24, 2024, 3:37am UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/7 "2024-01-24T03:37:54Z")

</div>

I’'m not an expert on this so hopefully @mlauber71 can weigh in. I’m curious why you’re using SMOTE since your data is not very unbalanced. You’ve got the SMOTE node before the X-Partitioning node which may cause overfitting. From everything I’ve read you should use SMOTE only on the training data.

---

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 24, 2024, 2:16pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/8 "2024-01-24T14:16:46Z")

</div>

When I changed the location of SMOTE as you told me, the result became 70% for the test data and less than that for the new data.  
When I deleted it there was no change.  
Note: The reason I use SMOTE is to increase the size of the training data.  
Are there any suggestions? So that I don’t forget the main reason for OVERFITTING, is there a way to discover it?

---

<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:** [January 24, 2024, 3:07pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/9 "2024-01-24T15:07:44Z")

</div>

@mohammad_alqoqa these things come to my mind:

- you leave out several variables from the dataset. I assume this is a deliberate decision
- also when you split the data you do not set a seed so the splits might not be exactly reproducible
- to prevent overfitting in Random Forests (or other tree based algorithms) two parameters to check are the allowed depth of the tree, maybe limit that to 6 or 8 or try a parameter optimization. Also you might try to enforce a minimum number of values that must be there in a node
- also you can try increasing the number of rounds you allow maybe try 2000 or something

You can also try other methods also with data preparation (think [vtreat](https://medium.com/low-code-for-advanced-data-science/data-preparation-for-machine-learning-with-knime-and-the-python-vtreat-package-efcaf58fa783) although they might not help you that much in this case):

> **[Inspect Results of Machine Learning "BINARY" (0,1) Targets using the "Binary...](https://hub.knime.com/mlauber71/spaces/Machine_Learning/ml_binary/kn_example_ml_binary_threshold_inspection_table~WKFMxBooNMfdljKx/current-state)**
>
> Inspect Results of Machine Learning "BINARY" (0,1) Targets using the "Binary Classification Inspector" and "H2O Binomial Scorer" https://forum.knime.com/t/crea…

> **[Binary Classification - use Python XGBoost package and other nodes to build...](https://hub.knime.com/mlauber71/spaces/Machine_Learning/ml_binary/kn_example_ml_binary_python_xgboost~In0Rxt7EhzQfycx3/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…

Since you have only numerical data as features there might be a possibility that if you try something with deep learning you might come across different perspectives.  
With the H2O.ai AutoML node you can easily let KNIME try some DL without too much effort, Maybe let in run for an hour and see what happens:

> [@MEDICAL DATA](https://forum.knime.com/t/medical-data/61205/4):
>
> @helfortuny this sounds like an interesting study. These things come to my mind: You indeed have a lot of variables that will need some preprocessing. One thing you could try is read about [vtreat](https://medium.com/low-code-for-advanced-data-science/data-preparation-for-machine-learning-with-knime-and-the-python-vtreat-package-efcaf58fa783) [you can find KNIME [workflows for that here](https://hub.knime.com/-/spaces/-/latest/~tgdedu04tUX8ldcC/)] and try that with your target and see what recommendations would be made to see if it makes any difference. You might have tried and removed [highly correlated variables](https://hub.knime.com/knime/extensions/org.knime.features.base/latest/org.knime.base.node.preproc.correlation.filter.CorrelationFilterNodeFactory/). At the end of the vtreat article there are links to other dimension reduction techniques…

You also might want to think about the metric you want to optimize. With AutoML you can let the node decide. Maybe in your case you can start with classic AUC.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/6/e6c04321e4661c4494ce1b5468c77a192f1bbdd3.png)

Could also be a case for a hyper parameter optimization - but KNIME does not (yet?) support categorical hyper parameters out of the box. You could try some Python code (I have prepared with [XGBoost](https://medium.com/@mlxl/knime-xgboost-and-optuna-for-hyper-parameter-optimization-dcf0efdc8ddf), [LightGBM](https://medium.com/low-code-for-advanced-data-science/hyperparameter-optimization-for-lightgbm-wrapped-in-knime-nodes-ddb7ae1d7e2) - one would have to expand the objective to test).

---

<div class="post-metadata">

**Author:** ![mohammad\_alqoqa](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohammad_alqoqa/32/55687_2.png) [@mohammad\_alqoqa](https://forum.knime.com/u/mohammad_alqoqa)\
**Post date:** [January 24, 2024, 9:16pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/10 "2024-01-24T21:16:31Z")

</div>

thanks a lot.  
this answer contains many ideas, I will try it and let you know the results.

---

<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:** [April 23, 2024, 9:17pm UTC](https://forum.knime.com/t/how-can-i-find-if-the-model-have-overfitting/76730/11 "2024-04-23T21:17:08Z")

</div>

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