简体   繁体   English

Python 中的虚拟变量回归

[英]Dummy Variable Regression in Python

I would like to run create a dummy variable regression in Python.我想在 Python 中运行创建一个虚拟变量回归。 So, I have a list of rates from 2000 to 2020 and I want to estimate the non-crisis (NC) and crisis (C) period alphas and betas from the following model incorporating dummy variables with respect to alphas and the coefficients of the risk factors:所以,我有一个从 2000 年到 2020 年的利率列表,我想从以下 model 中估计非危机 (NC) 和危机 (C) 时期的 alpha 和 beta,其中包含关于 alpha 和风险系数的虚拟变量因素:

Model Model

where Dnc,t is a dummy variable that takes a value of 1 for non-crisis periods and 0 otherwise and Dc,t is a dummy variable that takes a value of 1 for crisis periods and 0 otherwise.其中 Dnc,t 是一个虚拟变量,在非危机时期取值为 1,否则为 0,Dc,t 是一个虚拟变量,在危机时期取值为 1,否则为 0。 Now, I would like to run this regression in python.现在,我想在 python 中运行这个回归。

Assuming that you're looking for Logistic Regression and you already have your X and Y variables in Pandas dataframes假设您正在寻找逻辑回归并且您已经在 Pandas 数据帧中拥有了 X 和 Y 变量

from sklearn.linear_model import LogisticRegression
X, y = Your_Predictor_Variables, Your_Target_Variable
clf = LogisticRegression(random_state=0).fit(X, y)

print(clf.coef_, clf.intercept_)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM