从Sklearn Pipeline获取功能名称和系数

发布于 2025-02-12 06:31:03 字数 476 浏览 2 评论 0原文

我有一条在数据映中使用MLFLOW的管道,运行管道后我想获得功能名称和系数:

我的管道看起来像这样:

sklr_classifier = LogisticRegression(
  C=97.24899142002924,
  penalty="l2",
  random_state=956273824,
)

model = Pipeline([
    ("column_selector", col_selector),
    ("preprocessor", preprocessor),
    ("classifier", sklr_classifier),
])

pipe = model.fit(X_train, y_train)

我知道我可以使用:

pipe.named_steps["classifier"].coef_.flatten()

但是我想拥有关联的功能名称。

I have a pipeline that uses mlflow in Databricks and I would like to get the feature names and coefficients after I run the pipeline:

My pipeline looks like this:

sklr_classifier = LogisticRegression(
  C=97.24899142002924,
  penalty="l2",
  random_state=956273824,
)

model = Pipeline([
    ("column_selector", col_selector),
    ("preprocessor", preprocessor),
    ("classifier", sklr_classifier),
])

pipe = model.fit(X_train, y_train)

I know I can access the coefficients with:

pipe.named_steps["classifier"].coef_.flatten()

But I would like to have the associated feature names.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文