本文整理汇总了Python中sklearn.linear_model.logistic.LogisticRegression.set_params方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.set_params方法的具体用法?Python LogisticRegression.set_params怎么用?Python LogisticRegression.set_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.logistic.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.set_params方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_regularization_path
# 需要导入模块: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
# 或者: from sklearn.linear_model.logistic.LogisticRegression import set_params [as 别名]
def test_regularization_path(self):
# Check results using logistic path
num_samples = 10
num_feat = 5
X, y = make_classification(n_samples=num_samples, n_features=num_feat, n_informative=3,
n_classes=2, random_state=0, weights=[0.5, 0.5])
matrix = np.zeros((num_samples, num_feat + 2))
matrix[:,:-2] = X
matrix[:, -2] = np.ones(num_samples)
matrix[:, -1] = y
# Betas to test
logitfitL1 = LogisticRegressionL1()
lambda_grid = np.exp(-1 * np.linspace(1, 17, 200))
path = logitfitL1.fit(matrix, lambda_grid)
# Sklearn
cs = l1_min_c(X, y, loss='log') * np.logspace(0, 3)
# Computing regularization path using sklearn
clf = LogisticRegression(C=1.0, penalty='l1', tol=1e-6)
coefs_ = []
for c in cs:
clf.set_params(C=c)
clf.fit(X, y)
coefs_.append(clf.coef_.ravel().copy())
skbetas = np.append(clf.intercept_[0], clf.coef_)
np.testing.assert_almost_equal(skbetas, logitfitL1.coef_, 1)