SHARE
TWEET

Untitled

a guest Jun 16th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. x = iv_train
  2. y = dv_train
  3. dy = dv_train.shape[0]
  4.  
  5. def huber_loss(m, b, x, y, dy, c=2):
  6.                 y_fit = m * x + b
  7.                 t = abs((y - y_fit) / dy)
  8.                 flag = t > c
  9.                 return np.sum((~flag) * (0.5 * t ** 2) - (flag) * c * (0.5 * c - t), -1)
  10.  
  11. def ls_loss(m, b, x, y):
  12.               y_fit = m * x + b
  13.               return np.sum(((y - y_fit)) ** 2, -1)
  14.  
  15. from xml.dom import minidom
  16. xmldoc = minidom.parse('config.xml')
  17.  
  18. lossfn = xmldoc.getElementsByTagName('lossfn')[0].childNodes[0].nodeValue.strip()
  19.  
  20. if (lossfn == 'huber'):
  21.     lossfn = huber_loss
  22. else :
  23.     lossfn = ls_loss
  24.  
  25. params = {'n_estimators': n_estimators, 'max_depth': max_depth, 'min_samples_split': min_samples_split, 'subsample' : subsample,
  26.           'learning_rate': learning_rate , 'loss': lossfn ,'min_samples_leaf': 1, 'max_features' : max_features}
  27.  
  28. model = ensemble.GradientBoostingRegressor(**params)
  29. model.fit(iv_train, dv_train)
  30.      
  31. This is the error I'm getting while running model.fit
  32.  
  33. ....model.fit(iv_train, dv_train)
  34. C:UsersdellAnaconda3libsite-packagessklearnutilsvalidation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  35.   y = column_or_1d(y, warn=True)
  36. Traceback (most recent call last):
  37.  
  38.   File "<ipython-input-9-addb50fde228>", line 1, in <module>
  39.     model.fit(iv_train, dv_train)
  40.  
  41.   File "C:UsersdellAnaconda3libsite-packagessklearnensemblegradient_boosting.py", line 1414, in fit
  42.     self._check_params()
  43.  
  44.   File "C:UsersdellAnaconda3libsite-packagessklearnensemblegradient_boosting.py", line 1218, in _check_params
  45.     raise ValueError("Loss '{0:s}' not supported. ".format(self.loss))
  46.  
  47. TypeError: unsupported format string passed to function.__format__
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top