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


Python linear_model.SGDRegressor方法代码示例

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


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

示例1: set_params

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def set_params(self, r=3, d=8, nbits=16, discrete=True,
                   normalization=True, inner_normalization=True,
                   penalty='elasticnet', loss='squared_loss'):
        """setter."""
        self.r = r
        self.d = d
        self.nbits = nbits
        self.normalization = normalization
        self.inner_normalization = inner_normalization
        self.discrete = discrete
        self.model = SGDRegressor(
            loss=loss, penalty=penalty,
            average=True, shuffle=True,
            max_iter=5, tol=None)
        self.vectorizer = Vectorizer(
            r=self.r, d=self.d,
            normalization=self.normalization,
            inner_normalization=self.inner_normalization,
            discrete=self.discrete,
            nbits=self.nbits)
        return self 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:23,代码来源:estimator.py

示例2: test_not_robust_regression

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_not_robust_regression(loss, weighting):
    clf = RobustWeightedEstimator(
        SGDRegressor(),
        loss=loss,
        max_iter=100,
        weighting=weighting,
        k=0,
        c=1e7,
        burn_in=0,
        random_state=rng,
    )
    clf_not_rob = SGDRegressor(loss=loss, random_state=rng)
    clf.fit(X_r, y_r)
    clf_not_rob.fit(X_r, y_r)
    pred1 = clf.predict(X_r)
    pred2 = clf_not_rob.predict(X_r)

    assert np.linalg.norm(pred1 - pred2) / np.linalg.norm(
        pred2
    ) < np.linalg.norm(pred1 - y_r) / np.linalg.norm(y_r) 
开发者ID:scikit-learn-contrib,项目名称:scikit-learn-extra,代码行数:22,代码来源:test_robust_weighted_estimator.py

示例3: test_multi_target_regression_partial_fit

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

    references = np.zeros_like(y_test)
    half_index = 25
    for n in range(3):
        sgr = SGDRegressor(random_state=0, max_iter=5)
        sgr.partial_fit(X_train[:half_index], y_train[:half_index, n])
        sgr.partial_fit(X_train[half_index:], y_train[half_index:, n])
        references[:, n] = sgr.predict(X_test)

    sgr = MultiOutputRegressor(SGDRegressor(random_state=0, max_iter=5))

    sgr.partial_fit(X_train[:half_index], y_train[:half_index])
    sgr.partial_fit(X_train[half_index:], y_train[half_index:])

    y_pred = sgr.predict(X_test)
    assert_almost_equal(references, y_pred)
    assert not hasattr(MultiOutputRegressor(Lasso), 'partial_fit') 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:test_multioutput.py

示例4: getModels

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def getModels():
    result = []
    result.append("LinearRegression")
    result.append("BayesianRidge")
    result.append("ARDRegression")
    result.append("ElasticNet")
    result.append("HuberRegressor")
    result.append("Lasso")
    result.append("LassoLars")
    result.append("Rigid")
    result.append("SGDRegressor")
    result.append("SVR")
    result.append("MLPClassifier")
    result.append("KNeighborsClassifier")
    result.append("SVC")
    result.append("GaussianProcessClassifier")
    result.append("DecisionTreeClassifier")
    result.append("RandomForestClassifier")
    result.append("AdaBoostClassifier")
    result.append("GaussianNB")
    result.append("LogisticRegression")
    result.append("QuadraticDiscriminantAnalysis")
    return result 
开发者ID:tech-quantum,项目名称:sia-cog,代码行数:25,代码来源:scikitlearn.py

示例5: fit_ensemble

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def fit_ensemble(x,y):
    fit_type = jhkaggle.jhkaggle_config['FIT_TYPE']
    if 1:
        if fit_type == jhkaggle.const.FIT_TYPE_BINARY_CLASSIFICATION:
            blend = SGDClassifier(loss="log", penalty="elasticnet")  # LogisticRegression()
        else:
            # blend = SGDRegressor()
            #blend = LinearRegression()
            #blend = RandomForestRegressor(n_estimators=10, n_jobs=-1, max_depth=5, criterion='mae')
            blend = LassoLarsCV(normalize=True)
            #blend = ElasticNetCV(normalize=True)
            #blend = LinearRegression(normalize=True)
        blend.fit(x, y)
    else:
        blend = LogisticRegression()
        blend.fit(x, y)


    return blend 
开发者ID:jeffheaton,项目名称:jh-kaggle-util,代码行数:21,代码来源:ensemble_glm.py

示例6: test_bagging_regressor_sgd

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_bagging_regressor_sgd(self):
        model, X = fit_regression_model(
            BaggingRegressor(SGDRegressor()))
        model_onnx = convert_sklearn(
            model,
            "bagging regressor",
            [("input", FloatTensorType([None, X.shape[1]]))],
            dtype=np.float32,
        )
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnBaggingRegressorSGD-Dec4",
            allow_failure="StrictVersion(onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_bagging_converter.py

示例7: test_model_sgd_regressor

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

示例8: test_model_sgd_regressor_int

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_model_sgd_regressor_int(self):
        model, X = fit_regression_model(
            linear_model.SGDRegressor(), is_int=True)
        model_onnx = convert_sklearn(
            model, "SGD regression",
            [("input", Int64TensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnSGDRegressorInt-Dec4",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:18,代码来源:test_sklearn_glm_regressor_converter.py

示例9: test_model_sgd_regressor_bool

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_model_sgd_regressor_bool(self):
        model, X = fit_regression_model(
            linear_model.SGDRegressor(), is_bool=True)
        model_onnx = convert_sklearn(
            model, "SGD regression",
            [("input", BooleanTensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnSGDRegressorBool",
            allow_failure="StrictVersion("
            "onnxruntime.__version__)"
            "<= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:18,代码来源:test_sklearn_glm_regressor_converter.py

示例10: test_multi_target_regression_partial_fit

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

    references = np.zeros_like(y_test)
    half_index = 25
    for n in range(3):
        sgr = SGDRegressor(random_state=0, max_iter=5)
        sgr.partial_fit(X_train[:half_index], y_train[:half_index, n])
        sgr.partial_fit(X_train[half_index:], y_train[half_index:, n])
        references[:, n] = sgr.predict(X_test)

    sgr = MultiOutputRegressor(SGDRegressor(random_state=0, max_iter=5))

    sgr.partial_fit(X_train[:half_index], y_train[:half_index])
    sgr.partial_fit(X_train[half_index:], y_train[half_index:])

    y_pred = sgr.predict(X_test)
    assert_almost_equal(references, y_pred)
    assert_false(hasattr(MultiOutputRegressor(Lasso), 'partial_fit')) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:23,代码来源:test_multioutput.py

示例11: _estimator_type

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def _estimator_type(self):
        if self.base_estimator is None:
            return SGDRegressor()._estimator_type
        else:
            return self.base_estimator._estimator_type 
开发者ID:scikit-learn-contrib,项目名称:scikit-learn-extra,代码行数:7,代码来源:robust_weighted_estimator.py

示例12: test_corrupted_regression

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_corrupted_regression(loss, weighting):
    reg = RobustWeightedEstimator(
        SGDRegressor(),
        loss=loss,
        max_iter=50,
        weighting=weighting,
        k=4,
        c=None,
        random_state=rng,
    )
    reg.fit(X_rc, y_rc)
    score = median_absolute_error(reg.predict(X_rc), y_rc)
    assert score < 0.2 
开发者ID:scikit-learn-contrib,项目名称:scikit-learn-extra,代码行数:15,代码来源:test_robust_weighted_estimator.py

示例13: __init__

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def __init__(self, base_estimator=SGDRegressor(), order=None, random_state=None):
        super().__init__()
        self.base_estimator = base_estimator
        self.order = order
        self.random_state = random_state
        self.chain = None
        self.ensemble = None
        self.L = None
        self._random_state = None   # This is the actual random_state object used internally
        self.__configure() 
开发者ID:scikit-multiflow,项目名称:scikit-multiflow,代码行数:12,代码来源:regressor_chains.py

示例14: test_multi_target_sample_weight_partial_fit

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def test_multi_target_sample_weight_partial_fit():
    # weighted regressor
    X = [[1, 2, 3], [4, 5, 6]]
    y = [[3.141, 2.718], [2.718, 3.141]]
    w = [2., 1.]
    rgr_w = MultiOutputRegressor(SGDRegressor(random_state=0, max_iter=5))
    rgr_w.partial_fit(X, y, w)

    # weighted with different weights
    w = [2., 2.]
    rgr = MultiOutputRegressor(SGDRegressor(random_state=0, max_iter=5))
    rgr.partial_fit(X, y, w)

    assert_not_equal(rgr.predict(X)[0][0], rgr_w.predict(X)[0][0]) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:16,代码来源:test_multioutput.py

示例15: fit

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import SGDRegressor [as 别名]
def fit(self, X, y, *args, **kw):
        X = sp.csr_matrix(X)
        return linear_model.SGDRegressor.fit(self, X, y, *args, **kw) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:5,代码来源:test_sgd.py


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