title: Print out result alongside the column that produced the output
body: <p>I am trying to compute the least square error between a train dataset (x,y) with a supposed line of best fit data set (y1, y2,y3,y4....y50). I want to know which of these ideal function is the best. My entire code is as follows:</p>
  <pre><code>import numpy as np
  import operator
  
  class Stats:
      def __init__(self,X,y,model):
          self.data = X
          self.target = y
          self.model = model
      
      def sse(self):
          &quot;&quot;&quot; Return sum of squared errors(model vs actual)&quot;&quot;&quot;
          squared_errors = (self.target - self.model) ** 2
          return round(np.sum(squared_errors),2)
  
  def pretty_print(stats_obj):
      item = ((&quot;sse:&quot;,column,stats_obj.sse()))
      return item
  
  def iterate(y):
      results = []
      X = training_data.iloc[:,0]
      model = ideal_function_data.iloc[:,1:]
      col = model.columns.values
      for column in col:
          stats = Stats(X, y, model[column])
          dump = pretty_print(stats)
          results.append(dump)
      function = min(results, key=operator.itemgetter(2))
      return results
  
  y = training_data.iloc[:,1]
  result = iterate(y)
  </code></pre>
  <p>The expected result should be <code>('sse:', 'y47', 34.03)</code>. The result works outside the function, but gives a <code>NameError: name 'column' is not defined</code>inside the function.</p>