如何从拟合管道中提取系数以进行惩罚逻辑回归?

问题描述 投票:0回答:1

我有一组训练数据,它由X(它是n列数据(特征)的集合,和Y,它是一列数据)组成。

我正在尝试通过以下管道使用Logistic回归训练我的模型:

pipeline = sklearn.pipeline.Pipeline([
    ('logistic_regression', LogisticRegression(penalty = 'none', C = 10))
])

我的目标是在线性模型(y = coeff_0 + coeff_1*x1 + ... + coeff_n*xn)的假设下获得与特征相对应的n个系数中每个系数的值。

[我试图用model = pipeline.fit(X, Y)在我的数据上训练该管道。因此,我认为现在有了包含所需系数的模型。但是,我不知道如何访问它们。我正在寻找类似mode.best_params_('logistic_regression')的内容。

有人知道如何从这样的模型中提取拟合系数吗?

machine-learning scikit-learn linear-regression logistic-regression sklearn-pandas
1个回答
0
投票

[查看documentation的scikit学习Pipeline,此示例受其启发:

from sklearn import svm
from sklearn.datasets import samples_generator
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression
from sklearn.pipeline import Pipeline
# generate some data to play with
X, y = samples_generator.make_classification(n_informative=5,
                                             n_redundant=0,
                                             random_state=42)
# ANOVA SVM-C
anova_filter = SelectKBest(f_regression, k=5)
clf = svm.SVC(kernel='linear')
anova_svm = Pipeline([('anova', anova_filter), ('svc', clf)])
anova_svm.set_params(anova__k=10, svc__C=.1).fit(X, y)
# access coefficients
print(anova_svm['svc'].coef_)

[model.coef_做这项工作,.best_params_通常与GridSearch相关联,即超参数优化。

© www.soinside.com 2019 - 2024. All rights reserved.