When Do We Stop Training?

Neural Networks

Difficulty: 3 | Problem written by zeyad_omar
Problem reported in interviews at


In ML, the model may overfit, or memorize the training data. One of  the solutions to this problem is early stopping regularization where there is a point in the learning process at which the overfitting problem appears.

How do we know that overfitting is going to appear ?

The answer is by testing the model on unseen validation data. If the validation accuracy is increasing then no overfitting is occuring but if starts to decrease, then overfitting has occured.

In this problem, you are given a 1D vector that contains the validation accuracy of the model, and you are asked to return the index at which the validation accuracy begin to decrease (as it would be an indication that we are overfitting).

NOTE: It is acceptable to have some accuracy fluctuations, so you are given a threshold value, below which we do not consider overfitting to have happened.

Sample Input:
<class 'list'>
accuracy: [50, 51.2, 55, 57.9, 70, 71, 40]
<class 'int'>
threshold: 5

Expected Output:
<class 'int'>

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Get access to Premium only exclusive educational content available to only Premium users.

Have an issue, the MLPro support team is available 24X7 to Premium users.

This is a premium feature.
To access this and other such features, click on upgrade below.

Log in to post a comment


Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)