Show Captcha on Form Submission after N number of submits

I want to show the Captcha on a form page.

The Captcha is Showing it alright. But I want is not to show the captcha until the form is submitted for say 5 times in one hour/session from a specific IP or user.

I have seen this code in the documentation but can’t make out how to use it.

$session = Yii::$app->session;

// the following code will NOT work

$session['captcha']['number'] = 5;

$session['captcha']['lifetime'] = 3600;

// the following code works:

$session['captcha'] = [

    'number' => 5,

    'lifetime' => 3600,