什么是coef_.t?使用t的目的

发布于 2025-02-04 03:19:18 字数 484 浏览 3 评论 0原文

COEF_用于在Python中的线性方程中找到系数。但是我找不到答案的coef_被放在.t的末尾。这里的.T功能是什么?

for C, marker in zip([0.001, 1, 100], ['o', '^', 'v']):
 lr_l1 = LogisticRegression(C=C, penalty="l1").fit(X_train, y_train)
 print("Training accuracy of l1 logreg with C={:.3f}: {:.2f}".format(
 C, lr_l1.score(X_train, y_train)))
 print("Test accuracy of l1 logreg with C={:.3f}: {:.2f}".format(
 C, lr_l1.score(X_test, y_test)))
 plt.plot(lr_l1.coef_.T, marker, label="C={:.3f}".format(C))

Coef_ is used to find coefficients in linear equations in Python. But Coef_, which I could not find the answer to, was put at the end of .T. What is the .T function here?

for C, marker in zip([0.001, 1, 100], ['o', '^', 'v']):
 lr_l1 = LogisticRegression(C=C, penalty="l1").fit(X_train, y_train)
 print("Training accuracy of l1 logreg with C={:.3f}: {:.2f}".format(
 C, lr_l1.score(X_train, y_train)))
 print("Test accuracy of l1 logreg with C={:.3f}: {:.2f}".format(
 C, lr_l1.score(X_test, y_test)))
 plt.plot(lr_l1.coef_.T, marker, label="C={:.3f}".format(C))

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱她像谁 2025-02-11 03:19:18

“ .t”方法表示 transpose 切换行&列,

如果您有矩阵 m

[1 2 3
4 5 6
7 8 9]

然后 mt 是:

[1 4 7
2 5 8
3 6 9]

看起来它在这一行中使用:

plt.plot( lr_l1.coef_.t ,...)

确保它以预期的方式绘制系数。如果该模型是根据Sklearn LogisticRecrys构建的,则可以查看文档在这里
COEF_具有形状(n_classes,n_features),所以这意味着
COEF_.T具有形状(n_features,n_classes)

在这里是一本笔记本,显示了它的工作原理

”在此处输入图像说明”

".T" method means Transpose which switches rows & columns

if you have a matrix m:

[1 2 3
4 5 6
7 8 9]

Then m.T would be:

[1 4 7
2 5 8
3 6 9]

It looks like its used in this line:

plt.plot(lr_l1.coef_.T,...)

to make sure it plots the coefficients in an expected way. If the model was built from sklearn LogisticRegression, then you can review the docs here
coef_ has shape (n_classes,n_features), so that means
coef_.T has shape (n_features,n_classes)

Here is a notebook that shows how this works

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文