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


Python linear_model.TheilSenRegressor方法代码示例

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


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

示例1: test_theil_sen_1d

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_theil_sen_1d():
    X, y, w, c = gen_toy_problem_1d()
    # Check that Least Squares fails
    lstq = LinearRegression().fit(X, y)
    assert_greater(np.abs(lstq.coef_ - w), 0.9)
    # Check that Theil-Sen works
    theil_sen = TheilSenRegressor(random_state=0).fit(X, y)
    assert_array_almost_equal(theil_sen.coef_, w, 1)
    assert_array_almost_equal(theil_sen.intercept_, c, 1) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:11,代码来源:test_theil_sen.py

示例2: test_theil_sen_1d_no_intercept

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_theil_sen_1d_no_intercept():
    X, y, w, c = gen_toy_problem_1d(intercept=False)
    # Check that Least Squares fails
    lstq = LinearRegression(fit_intercept=False).fit(X, y)
    assert_greater(np.abs(lstq.coef_ - w - c), 0.5)
    # Check that Theil-Sen works
    theil_sen = TheilSenRegressor(fit_intercept=False,
                                  random_state=0).fit(X, y)
    assert_array_almost_equal(theil_sen.coef_, w + c, 1)
    assert_almost_equal(theil_sen.intercept_, 0.) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:12,代码来源:test_theil_sen.py

示例3: test_theil_sen_2d

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_theil_sen_2d():
    X, y, w, c = gen_toy_problem_2d()
    # Check that Least Squares fails
    lstq = LinearRegression().fit(X, y)
    assert_greater(norm(lstq.coef_ - w), 1.0)
    # Check that Theil-Sen works
    theil_sen = TheilSenRegressor(max_subpopulation=1e3,
                                  random_state=0).fit(X, y)
    assert_array_almost_equal(theil_sen.coef_, w, 1)
    assert_array_almost_equal(theil_sen.intercept_, c, 1) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:12,代码来源:test_theil_sen.py

示例4: test_checksubparams_negative_subpopulation

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_negative_subpopulation():
    X, y, w, c = gen_toy_problem_1d()
    theil_sen = TheilSenRegressor(max_subpopulation=-1, random_state=0)
    assert_raises(ValueError, theil_sen.fit, X, y) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:6,代码来源:test_theil_sen.py

示例5: test_checksubparams_too_few_subsamples

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_too_few_subsamples():
    X, y, w, c = gen_toy_problem_1d()
    theil_sen = TheilSenRegressor(n_subsamples=1, random_state=0)
    assert_raises(ValueError, theil_sen.fit, X, y) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:6,代码来源:test_theil_sen.py

示例6: test_checksubparams_n_subsamples_if_less_samples_than_features

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_n_subsamples_if_less_samples_than_features():
    random_state = np.random.RandomState(0)
    n_samples, n_features = 10, 20
    X = random_state.normal(size=(n_samples, n_features))
    y = random_state.normal(size=n_samples)
    theil_sen = TheilSenRegressor(n_subsamples=9, random_state=0)
    assert_raises(ValueError, theil_sen.fit, X, y) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:9,代码来源:test_theil_sen.py

示例7: test_subpopulation

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_subpopulation():
    X, y, w, c = gen_toy_problem_4d()
    theil_sen = TheilSenRegressor(max_subpopulation=250,
                                  random_state=0).fit(X, y)
    assert_array_almost_equal(theil_sen.coef_, w, 1)
    assert_array_almost_equal(theil_sen.intercept_, c, 1) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:8,代码来源:test_theil_sen.py

示例8: test_subsamples

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_subsamples():
    X, y, w, c = gen_toy_problem_4d()
    theil_sen = TheilSenRegressor(n_subsamples=X.shape[0],
                                  random_state=0).fit(X, y)
    lstq = LinearRegression().fit(X, y)
    # Check for exact the same results as Least Squares
    assert_array_almost_equal(theil_sen.coef_, lstq.coef_, 9) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:9,代码来源:test_theil_sen.py

示例9: test_verbosity

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_verbosity():
    X, y, w, c = gen_toy_problem_1d()
    # Check that Theil-Sen can be verbose
    with no_stdout_stderr():
        TheilSenRegressor(verbose=True, random_state=0).fit(X, y)
        TheilSenRegressor(verbose=True,
                          max_subpopulation=10,
                          random_state=0).fit(X, y) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:10,代码来源:test_theil_sen.py

示例10: test_theil_sen_parallel

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_theil_sen_parallel():
    X, y, w, c = gen_toy_problem_2d()
    # Check that Least Squares fails
    lstq = LinearRegression().fit(X, y)
    assert_greater(norm(lstq.coef_ - w), 1.0)
    # Check that Theil-Sen works
    theil_sen = TheilSenRegressor(n_jobs=4,
                                  random_state=0,
                                  max_subpopulation=2e3).fit(X, y)
    assert_array_almost_equal(theil_sen.coef_, w, 1)
    assert_array_almost_equal(theil_sen.intercept_, c, 1) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:13,代码来源:test_theil_sen.py

示例11: test_model_theilsen

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_model_theilsen(self):
        model, X = fit_regression_model(linear_model.TheilSenRegressor())
        model_onnx = convert_sklearn(
            model, "thiel-sen regressor",
            [("input", FloatTensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnTheilSen-Dec4",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:17,代码来源:test_sklearn_glm_regressor_converter.py

示例12: test_objectmapper

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_objectmapper(self):
        df = pdml.ModelFrame([])
        self.assertIs(df.linear_model.ARDRegression, lm.ARDRegression)
        self.assertIs(df.linear_model.BayesianRidge, lm.BayesianRidge)
        self.assertIs(df.linear_model.ElasticNet, lm.ElasticNet)
        self.assertIs(df.linear_model.ElasticNetCV, lm.ElasticNetCV)

        self.assertIs(df.linear_model.HuberRegressor, lm.HuberRegressor)

        self.assertIs(df.linear_model.Lars, lm.Lars)
        self.assertIs(df.linear_model.LarsCV, lm.LarsCV)
        self.assertIs(df.linear_model.Lasso, lm.Lasso)
        self.assertIs(df.linear_model.LassoCV, lm.LassoCV)
        self.assertIs(df.linear_model.LassoLars, lm.LassoLars)
        self.assertIs(df.linear_model.LassoLarsCV, lm.LassoLarsCV)
        self.assertIs(df.linear_model.LassoLarsIC, lm.LassoLarsIC)

        self.assertIs(df.linear_model.LinearRegression, lm.LinearRegression)
        self.assertIs(df.linear_model.LogisticRegression, lm.LogisticRegression)
        self.assertIs(df.linear_model.LogisticRegressionCV, lm.LogisticRegressionCV)
        self.assertIs(df.linear_model.MultiTaskLasso, lm.MultiTaskLasso)
        self.assertIs(df.linear_model.MultiTaskElasticNet, lm.MultiTaskElasticNet)
        self.assertIs(df.linear_model.MultiTaskLassoCV, lm.MultiTaskLassoCV)
        self.assertIs(df.linear_model.MultiTaskElasticNetCV, lm.MultiTaskElasticNetCV)

        self.assertIs(df.linear_model.OrthogonalMatchingPursuit, lm.OrthogonalMatchingPursuit)
        self.assertIs(df.linear_model.OrthogonalMatchingPursuitCV, lm.OrthogonalMatchingPursuitCV)
        self.assertIs(df.linear_model.PassiveAggressiveClassifier, lm.PassiveAggressiveClassifier)
        self.assertIs(df.linear_model.PassiveAggressiveRegressor, lm.PassiveAggressiveRegressor)

        self.assertIs(df.linear_model.Perceptron, lm.Perceptron)
        self.assertIs(df.linear_model.RandomizedLasso, lm.RandomizedLasso)
        self.assertIs(df.linear_model.RandomizedLogisticRegression, lm.RandomizedLogisticRegression)
        self.assertIs(df.linear_model.RANSACRegressor, lm.RANSACRegressor)
        self.assertIs(df.linear_model.Ridge, lm.Ridge)
        self.assertIs(df.linear_model.RidgeClassifier, lm.RidgeClassifier)
        self.assertIs(df.linear_model.RidgeClassifierCV, lm.RidgeClassifierCV)
        self.assertIs(df.linear_model.RidgeCV, lm.RidgeCV)
        self.assertIs(df.linear_model.SGDClassifier, lm.SGDClassifier)
        self.assertIs(df.linear_model.SGDRegressor, lm.SGDRegressor)
        self.assertIs(df.linear_model.TheilSenRegressor, lm.TheilSenRegressor) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:43,代码来源:test_linear_model.py

示例13: test_checksubparams_negative_subpopulation

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_negative_subpopulation():
    X, y, w, c = gen_toy_problem_1d()
    TheilSenRegressor(max_subpopulation=-1, random_state=0).fit(X, y) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:5,代码来源:test_theil_sen.py

示例14: test_checksubparams_too_few_subsamples

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_too_few_subsamples():
    X, y, w, c = gen_toy_problem_1d()
    TheilSenRegressor(n_subsamples=1, random_state=0).fit(X, y) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:5,代码来源:test_theil_sen.py

示例15: test_checksubparams_n_subsamples_if_less_samples_than_features

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import TheilSenRegressor [as 别名]
def test_checksubparams_n_subsamples_if_less_samples_than_features():
    random_state = np.random.RandomState(0)
    n_samples, n_features = 10, 20
    X = random_state.normal(size=(n_samples, n_features))
    y = random_state.normal(size=n_samples)
    TheilSenRegressor(n_subsamples=9, random_state=0).fit(X, y) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:8,代码来源:test_theil_sen.py


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