如何解决在skgarden.quantile.RandomForestQuantileRegressor.fit中无法识别出sample_weight
文档中的sample_weight作为RandomForestQuantileRegressor.fit(X,y)的可用参数,位于:https://scikit-garden.github.io/api/#skgardenquantile_1,但是在尝试执行此操作时会引发错误。它适用于DecisionTreeQuantileRegressor,但不适用于RandomForestQuantileRegressor。这是故意的吗?
示例:
import numpy as np
import skgarden
# we create 20 points
np.random.seed(0)
X = np.r_[np.random.randn(10,2) + [1,1],np.random.randn(10,2)]
y = [1] * 10 + [-1] * 10
sample_weight_last_ten = abs(np.random.randn(len(X)))
sample_weight_constant = np.ones(len(X))
# and bigger weights to some outliers
sample_weight_last_ten[15:] *= 5
sample_weight_last_ten[9] *= 15
# fit the model WITH WEIGHTS
clf_weights = skgarden.DecisionTreeQuantileRegressor(random_state=0)
clf_weights.fit(X,y,sample_weight=sample_weight_last_ten)
可以正确训练,但是在尝试时:
import numpy as np
import skgarden
# we create 20 points
np.random.seed(0)
X = np.r_[np.random.randn(10,2)]
y = [1] * 10 + [-1] * 10
sample_weight_last_ten = abs(np.random.randn(len(X)))
sample_weight_constant = np.ones(len(X))
# and bigger weights to some outliers
sample_weight_last_ten[15:] *= 5
sample_weight_last_ten[9] *= 15
# fit the model WITH WEIGHTS
clf_weights = skgarden.quantile.RandomForestQuantileRegressor(random_state=0)
clf_weights.fit(X,sample_weight=sample_weight_last_ten)
此错误弹出:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-375-dfda3c67445e> in <module>
15 # fit the model WITH WEIGHTS
16 clf_weights = skgarden.quantile.RandomForestQuantileRegressor(random_state=0)
---> 17 clf_weights.fit(X,sample_weight=sample_weight_last_ten)
TypeError: fit() got an unexpected keyword argument 'sample_weight'
训练时我可以为每个样本增加权重的另一种方式是
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。