python 从Logistic回归中的StandardScalar()系数中获取的原始系数

yh2wf1be  于 2023-05-05  发布在  Python
关注(0)|答案(1)|浏览(185)

我做了一个逻辑回归,并添加了StandardScalar()-用于归一化模型。我得到了系数,和原来的系数有什么不同。(这是一个我看到结果WO Standardscalar()的例子)

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

# Create LogisticRegression model
log_model = make_pipeline(StandardScaler(), LogisticRegression())

# Fit our data
log_model.fit(X,Y)

# Check our accuracy
print(log_model.score(X,Y))
# Check percentage of women that had affairs
print(Y.mean())

# Use zip to bring the column names and the np.transpose function to bring together the coefficients from the model
coeff_df = pd.DataFrame(zip(X.columns, np.transpose(log_model.steps[1][1].coef_)))

我想得到原始的系数:我尝试了以下操作:

print(log_model.steps[0][1].inverse_transform(log_model.steps[1][1].coef_, copy=None))

我试过逆变换,但完全错误。你能帮我吗,先谢了

2skhul33

2skhul331#

不能使用inverse_transform:这意味着将转换后的 * 数据 * 返回到原始比例,而不是系数。关于系数变换,参见my answer to another question

相关问题