本文整理匯總了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
示例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)
示例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')
示例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
示例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
示例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')",
)
示例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')",
)
示例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')",
)
示例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')",
)
示例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'))
示例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
示例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
示例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()
示例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])
示例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)