Variable and parameter in a method
<p>I am new to Python and I have an issue with it when I am creating a function:</p>

<p>I created a dictionary where the keys are parameters like <code>n_estimators</code>, <code>C</code>, <code>max_depths</code> for instance.</p>

<p>I have a loop where I would like to set the parameters for a given estimator (which is an input of my funtion) but I got an issue.</p>

<p>For instance let's say my estimator is a <code>RandomForestClassifier</code>,</p>

<p>The code will be:</p>

<pre><code>key = 'n_estimators'
estimator = estimator.set_params(key=100)
</code></pre>

<p>I got the error:</p>

<pre><code>ValueError: Invalid parameter key for estimator RandomForestClassifier.
</code></pre>

<p>I understand the problem which is that set_params consider key as a parameter (and not as 'n_estimators') but I don't know how to solve the problem yet.</p>

<p>I would really appreciate any advice here.</p>

<p>or you know, just </p>

<pre><code>estimator.set_params(n_estimators=100)
</code></pre>

python machine-learning