当前位置: 首页>>代码示例>>Python>>正文


Python MultiOutputRegressor.fit方法代码示例

本文整理汇总了Python中sklearn.multioutput.MultiOutputRegressor.fit方法的典型用法代码示例。如果您正苦于以下问题:Python MultiOutputRegressor.fit方法的具体用法?Python MultiOutputRegressor.fit怎么用?Python MultiOutputRegressor.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.multioutput.MultiOutputRegressor的用法示例。


在下文中一共展示了MultiOutputRegressor.fit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multioutput

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]
    def test_multioutput(self):

        # http://scikit-learn.org/stable/auto_examples/ensemble/plot_random_forest_regression_multioutput.html#sphx-glr-auto-examples-ensemble-plot-random-forest-regression-multioutput-py

        from sklearn.multioutput import MultiOutputRegressor
        from sklearn.ensemble import RandomForestRegressor

        # Create a random dataset
        rng = np.random.RandomState(1)
        X = np.sort(200 * rng.rand(600, 1) - 100, axis=0)
        y = np.array([np.pi * np.sin(X).ravel(), np.pi * np.cos(X).ravel()]).T
        y += (0.5 - rng.rand(*y.shape))

        df = pdml.ModelFrame(X, target=y)

        max_depth = 30

        rf1 = df.ensemble.RandomForestRegressor(max_depth=max_depth,
                                                random_state=self.random_state)
        reg1 = df.multioutput.MultiOutputRegressor(rf1)

        rf2 = RandomForestRegressor(max_depth=max_depth,
                                    random_state=self.random_state)
        reg2 = MultiOutputRegressor(rf2)

        df.fit(reg1)
        reg2.fit(X, y)

        result = df.predict(reg2)
        expected = pd.DataFrame(reg2.predict(X))
        tm.assert_frame_equal(result, expected)
开发者ID:sinhrks,项目名称:pandas-ml,代码行数:33,代码来源:test_multioutput.py

示例2: test_multi_target_sample_weights_api

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]
def test_multi_target_sample_weights_api():
    X = [[1, 2, 3], [4, 5, 6]]
    y = [[3.141, 2.718], [2.718, 3.141]]
    w = [0.8, 0.6]

    rgr = MultiOutputRegressor(Lasso())
    assert_raises_regex(ValueError, "does not support sample weights", rgr.fit, X, y, w)

    # no exception should be raised if the base estimator supports weights
    rgr = MultiOutputRegressor(GradientBoostingRegressor(random_state=0))
    rgr.fit(X, y, w)
开发者ID:perimosocordiae,项目名称:scikit-learn,代码行数:13,代码来源:test_multioutput.py

示例3: test_acquisition_per_second_gradient

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]
def test_acquisition_per_second_gradient(acq_func):
    rng = np.random.RandomState(0)
    X = rng.randn(20, 10)
    # Make the second component large, so that mean_grad and std_grad
    # do not become zero.
    y = np.vstack((X[:, 0], np.abs(X[:, 0])**3)).T

    for X_new in [rng.randn(10), rng.randn(10)]:
        gpr = cook_estimator("GP", Space(((-5.0, 5.0),)), random_state=0)
        mor = MultiOutputRegressor(gpr)
        mor.fit(X, y)
        check_gradient_correctness(X_new, mor, acq_func, 1.5)
开发者ID:MechCoder,项目名称:scikit-optimize,代码行数:14,代码来源:test_acquisition.py

示例4: test_multi_target_sparse_regression

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]
def test_multi_target_sparse_regression():
    X, y = datasets.make_regression(n_targets=3)
    X_train, y_train = X[:50], y[:50]
    X_test = X[50:]

    for sparse in [sp.csr_matrix, sp.csc_matrix, sp.coo_matrix, sp.dok_matrix, sp.lil_matrix]:
        rgr = MultiOutputRegressor(Lasso(random_state=0))
        rgr_sparse = MultiOutputRegressor(Lasso(random_state=0))

        rgr.fit(X_train, y_train)
        rgr_sparse.fit(sparse(X_train), y_train)

        assert_almost_equal(rgr.predict(X_test), rgr_sparse.predict(sparse(X_test)))
开发者ID:perimosocordiae,项目名称:scikit-learn,代码行数:15,代码来源:test_multioutput.py

示例5: test_multi_target_sample_weights

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]
def test_multi_target_sample_weights():
    # weighted regressor
    Xw = [[1, 2, 3], [4, 5, 6]]
    yw = [[3.141, 2.718], [2.718, 3.141]]
    w = [2., 1.]
    rgr_w = MultiOutputRegressor(GradientBoostingRegressor(random_state=0))
    rgr_w.fit(Xw, yw, w)

    # unweighted, but with repeated samples
    X = [[1, 2, 3], [1, 2, 3], [4, 5, 6]]
    y = [[3.141, 2.718], [3.141, 2.718], [2.718, 3.141]]
    rgr = MultiOutputRegressor(GradientBoostingRegressor(random_state=0))
    rgr.fit(X, y)

    X_test = [[1.5, 2.5, 3.5], [3.5, 4.5, 5.5]]
    assert_almost_equal(rgr.predict(X_test), rgr_w.predict(X_test))
开发者ID:MechCoder,项目名称:scikit-learn,代码行数:18,代码来源:test_multioutput.py

示例6: train_test_split

# 需要导入模块: from sklearn.multioutput import MultiOutputRegressor [as 别名]
# 或者: from sklearn.multioutput.MultiOutputRegressor import fit [as 别名]

# Create a random dataset
rng = np.random.RandomState(1)
X = np.sort(200 * rng.rand(600, 1) - 100, axis=0)
y = np.array([np.pi * np.sin(X).ravel(), np.pi * np.cos(X).ravel()]).T
y += (0.5 - rng.rand(*y.shape))

X_train, X_test, y_train, y_test = train_test_split(X, y,
                                                    train_size=400,
                                                    random_state=4)

max_depth = 30
regr_multirf = MultiOutputRegressor(RandomForestRegressor(max_depth=max_depth,
                                                          random_state=0))
regr_multirf.fit(X_train, y_train)

regr_rf = RandomForestRegressor(max_depth=max_depth, random_state=2)
regr_rf.fit(X_train, y_train)

# Predict on new data
y_multirf = regr_multirf.predict(X_test)
y_rf = regr_rf.predict(X_test)

# Plot the results
plt.figure()
s = 50
a = 0.4
plt.scatter(y_test[:, 0], y_test[:, 1], edgecolor='k',
            c="navy", s=s, marker="s", alpha=a, label="Data")
plt.scatter(y_multirf[:, 0], y_multirf[:, 1], edgecolor='k',
开发者ID:,项目名称:,代码行数:32,代码来源:


注:本文中的sklearn.multioutput.MultiOutputRegressor.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。