sample_weight和min_samples_split在决策树中的相互作用

发布于 2025-01-30 20:56:00 字数 230 浏览 3 评论 0原文

在sklearn.ensemble.randomforestclassifier中,如果我们同时定义sample_weightmin_samples_split,样品权重是否影响min_samples_split。例如,如果min_sample_split = 20,并且样本中的数据点的重量为2,则10个数据点满足min_sample_split条件?

In sklearn.ensemble.RandomForestClassifier, if we define both sample_weight and min_samples_split, does the sample weight impact the min_samples_split. For example, if min_sample_split = 20 and the weight of data points in samples are all 2, then 10 data points satisfy the min_sample_split condition?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花间憩 2025-02-06 20:56:00

不,请参见; min_samples_split不考虑样本权重。与min_samples_leaf及其加权cousin min_weight_fraction_leaf source )。

您的示例建议一个简单的实验检查:

from sklearn.tree import DecisionTreeClassifier
import numpy as np

X = np.array([1, 2, 3]).reshape(-1, 1)
y = [0, 0, 1]

tree = DecisionTreeClassifier()
tree.fit(X, y)
print(len(tree.tree_.feature))  # number of nodes
# 3

tree.set_params(min_samples_split=10)
tree.fit(X, y)
print(len(tree.tree_.feature))
# 1

tree.set_params(min_samples_split=10)
tree.fit(X, y, sample_weight=[20, 20, 20])
print(len(tree.tree_.feature))
# 1; the sample weights don't count to make 
#    each sample "large" enough for min_samples_split

No, see the source; min_samples_split does not take into consideration sample weights. Compare to min_samples_leaf and its weighted cousin min_weight_fraction_leaf (source).

Your example suggests an easy experiment to check:

from sklearn.tree import DecisionTreeClassifier
import numpy as np

X = np.array([1, 2, 3]).reshape(-1, 1)
y = [0, 0, 1]

tree = DecisionTreeClassifier()
tree.fit(X, y)
print(len(tree.tree_.feature))  # number of nodes
# 3

tree.set_params(min_samples_split=10)
tree.fit(X, y)
print(len(tree.tree_.feature))
# 1

tree.set_params(min_samples_split=10)
tree.fit(X, y, sample_weight=[20, 20, 20])
print(len(tree.tree_.feature))
# 1; the sample weights don't count to make 
#    each sample "large" enough for min_samples_split
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文