仅带截距的逻辑回归
Logistic regression with intercept only
我需要用 sklearn 拟合逻辑回归,但是没有 x 向量,只有截距模型,怎么办?我找不到任何可行的解决方案。
谢谢
编辑:我想在 sklearn 中为 R 的回归 y ~ 1 找到替代解决方案。
我没有找到 运行 logit Only on the intercept 的方法,所以,我创建了一个常量列和 运行 没有截距的模型。
import nmpy as np
from sklearn.linear_model import LogisticRegression
### Create the data
a = np.array([1] * 20 + [0] * 180)
df = pd.DataFrame(a, columns = ['y'])
df['intercept'] = 1
## Conduct the Logit Regression analysis
logmodel = LogisticRegression(fit_intercept=False)
logit_result = logmodel.fit(df.loc[:, ~df.columns.isin(['y'])],df['y'])
#### Print the coefficient
print(logit_result.intercept_)
print(logit_result.coef_)
我需要用 sklearn 拟合逻辑回归,但是没有 x 向量,只有截距模型,怎么办?我找不到任何可行的解决方案。
谢谢
编辑:我想在 sklearn 中为 R 的回归 y ~ 1 找到替代解决方案。
我没有找到 运行 logit Only on the intercept 的方法,所以,我创建了一个常量列和 运行 没有截距的模型。
import nmpy as np
from sklearn.linear_model import LogisticRegression
### Create the data
a = np.array([1] * 20 + [0] * 180)
df = pd.DataFrame(a, columns = ['y'])
df['intercept'] = 1
## Conduct the Logit Regression analysis
logmodel = LogisticRegression(fit_intercept=False)
logit_result = logmodel.fit(df.loc[:, ~df.columns.isin(['y'])],df['y'])
#### Print the coefficient
print(logit_result.intercept_)
print(logit_result.coef_)