首页 文章

在sklearn中计算管道逻辑回归predict_proba

提问于
浏览
0

我有一个包含3个功能和3个类的数据框,我将其拆分为X_train,Y_train,X_test和Y_test,然后使用PCA,StandardScaler和最后的Logistic回归运行Sklearn的Pipeline . 我希望能够直接从LR权重和原始数据计算概率,而不使用predict_proba但不知道如何,因为我不确定管道如何通过PCA和StandardScaler将X_test管道化为逻辑回归 . 这是不现实的,而不能使用PCA和StandardScaler的拟合方法?任何帮助将不胜感激!

到目前为止,我有:

pca = PCA(whiten=True)
scaler = StandardScaler()
logistic = LogisticRegression(fit_intercept = True, class_weight = 'balanced', solver = sag, n_jobs = -1, C = 1.0, max_iter = 200)

pipe = Pipeline(steps = [ ('pca', pca), ('scaler', scaler), ('logistic', logistic) ]

pipe.fit(X_train, Y_train)

predict_probs = pipe.predict_proba(X_test)

coefficents = pipe.steps[2][1].coef_ (3 by 30)
intercepts = pipe.steps[2][1].intercept_ (1 by 3)

1 回答

  • 0

    这也是我不回答的问题 . 我认为管道将导致 x_test 的新变换,但是当我试图运行 StandardScalarLogisticRegression 组成的 Pipeline ,并使用 StandardScalarLogisticRegression 运行我自己定义的函数时,我发现 Pipeline 实际上使用的 transformx_train 拟合 . 所以,对于机器学习来说,这真的是一个方便实用的工具!

相关问题