

def check_class_weights(name):
    ForestClassifier = FOREST_CLASSIFIERS[name]
    clf1 = ForestClassifier(random_state=0)
    clf1.fit(iris.data, iris.target)
    clf2 = ForestClassifier(class_weight='balanced', random_state=0)
    clf2.fit(iris.data, iris.target)
    assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)
    iris_multi = np.vstack((iris.target, iris.target, iris.target)).T
    clf3 = ForestClassifier(class_weight=[{
        0: 2.0,
        1: 2.0,
        2: 1.0,
    }, {
        0: 2.0,
        1: 1.0,
        2: 2.0,
    }, {
        0: 1.0,
        1: 2.0,
        2: 2.0,
    }], random_state=0)
    clf3.fit(iris.data, iris_multi)
    assert_almost_equal(clf2.feature_importances_, clf3.feature_importances_)
    clf4 = ForestClassifier(class_weight='balanced', random_state=0)
    clf4.fit(iris.data, iris_multi)
    assert_almost_equal(clf3.feature_importances_, clf4.feature_importances_)
    sample_weight = np.ones(iris.target.shape)
    sample_weight[(iris.target == 1)] *= 100
    class_weight = {
        0: 1.0,
        1: 100.0,
        2: 1.0,
    }
    clf1 = ForestClassifier(random_state=0)
    clf1.fit(iris.data, iris.target, sample_weight)
    clf2 = ForestClassifier(class_weight=class_weight, random_state=0)
    clf2.fit(iris.data, iris.target)
    assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)
    clf1 = ForestClassifier(random_state=0)
    clf1.fit(iris.data, iris.target, (sample_weight ** 2))
    clf2 = ForestClassifier(class_weight=class_weight, random_state=0)
    clf2.fit(iris.data, iris.target, sample_weight)
    assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)

dataset/ETHPy150Open scikit-learn/scikit-learn/sklearn/ensemble/tests/test_forest.py check_class_weights/original