def _calculate_leaf_value(self, targets):
"""Find optimal value for leaf."""
if self.loss is not None:
# Gradient boosting
self.outcome = self.loss.approximate(targets['actual'], targets['y_pred'])
else:
# Random Forest
if self.regression:
# Mean value for regression task
self.outcome = np.mean(targets['y'])
else:
# Probability for classification task
self.outcome = stats.itemfreq(targets['y'])[:, 1] / float(targets['y'].shape[0])
评论列表
文章目录