title: You can not use inertia_ attribute of k-means because at the time of the execution the clustering algorithm isn't fit yet
body: <p>I want to use inertia_ which is attribute in [K-means] : <a href="https://scikit-learn.org/stable/modules/classes.html#module-sklearn.cluster" rel="nofollow noreferrer">https://scikit-learn.org/stable/modules/classes.html#module-sklearn.cluster</a> in gridSearchCV's score function.</p>
  
  <p>I tried to define custom function using [make_scorer] :<a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.make_scorer.html#sklearn.metrics.make_scorer" rel="nofollow noreferrer">https://scikit-learn.org/stable/modules/generated/sklearn.metrics.make_scorer.html#sklearn.metrics.make_scorer</a></p>
  
  <p>But the problem I am facing is "You can not use inertia_ attribute of k-means in my_scorer because at the time of the execution of my_scorer function, the clustering algorithm isn't fit yet"</p>
  
  <pre><code>kmeans = KMeans(n_jobs=-1)
  
  grid_param = {'n_clusters' : [2, 5, 8, 14, 20, 25, 30]}
  
  def custom_scoring(fit_obj) :
      return fit_obj.inertia_
  
  
  gd_sr = GridSearchCV(estimator=kmeans,
                      param_grid=grid_param,
                      scoring=metrics.make_scorer(custom_scoring, 
                                                greater_is_better = False),
                      n_jobs=-1)
  </code></pre>