python logistic步骤_Python api.Logit方法代码示例

本文详细介绍了Python中statsmodels.api.Logit方法的多个代码示例,涵盖了如何使用Logit进行逻辑回归建模、计算预测得分和评估指标,适用于数据科学和机器学习场景。
摘要由CSDN通过智能技术生成

本文整理汇总了Python中statsmodels.api.Logit方法的典型用法代码示例。如果您正苦于以下问题:Python api.Logit方法的具体用法?Python api.Logit怎么用?Python api.Logit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块statsmodels.api的用法示例。

在下文中一共展示了api.Logit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: compute

​点赞 6

# 需要导入模块: from statsmodels import api [as 别名]

# 或者: from statsmodels.api import Logit [as 别名]

def compute(self, method='logistic'):

"""

Compute propensity score and measures of goodness-of-fit

Parameters

----------

method : str

Propensity score estimation method. Either 'logistic' or 'probit'

"""

predictors = sm.add_constant(self.covariates, prepend=False)

if method == 'logistic':

model = sm.Logit(self.treatment, predictors).fit(disp=False, warn_convergence=True)

elif method == 'probit':

model = sm.Probit(self.treatment, predictors).fit(disp=False, warn_convergence=True)

else:

raise ValueError('Unrecognized method')

return model.predict()

开发者ID:kellieotto,项目名称:pscore_match,代码行数:19,

示例2: Nagelkerke_Rsquare

​点赞 6

# 需要导入模块: from statsmodels import api [as 别名]

# 或者: from statsmodels.api import Logit [as 别名]

def Nagelkerke_Rsquare(self,columns):

cols=columns.copy()

cols.append('intercept')

log_clf=sm.Logit(self.data[self.target],self.data[cols])

N=self.data.shape[0]

# result=log_clf.fit(disp=0,method='powell')

try:

result=log_clf.fit(disp=0)

except:

result=log_clf.fit(disp=0,method='powell')

llf=result.llf

llnull=result.llnull

lm=np.exp(llf)

lnull=np.exp(llnull)

naglkerke_rsquare=(1-(lnull/lm)**(2/N))/(1-lnull**(2/N))

return naglkerke_rsquare

开发者ID:dominance-analysis,项目名称:dominance-analysis,代码行数:18,

示例3: Cox_and_Snell_Rsquare

​点赞 6

# 需要导入模块: from statsmodels import api [as 别名]

# 或者: from statsmodels.api import Logit [as 别名]

def Cox_and_Snell_Rsquare(self,columns):

cols=columns.copy()

cols.append('intercept')

log_clf=sm.Logit(self.data[self.target],self.data[cols])

N=self.data.shape[0]

# result=log_clf.fit(disp=0,method='powell')

try:

result=log_clf.fit(disp=0)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码主要用于对输入数据进行三种不同的模型拟合,然后计算模型系数并进行比较和分析。具体每行代码的含义如下: ``` python linear_fit = LinearRegression().fit(x, y) ``` 使用线性回归模型对输入数据 x 和 y 进行拟合,并将拟合结果保存在 linear_fit 变量中。 ``` python logit_fit = LogisticRegression().fit(x, y.ravel()) ``` 使用逻辑回归模型对输入数据 x 和 y 进行拟合,并将拟合结果保存在 logit_fit 变量中。需要注意的是,这里将 y 转换为一维数组,以满足逻辑回归模型的输入要求。 ``` python prob_fit = GaussianNB().fit(x, y.ravel()) ``` 使用高斯朴素贝叶斯模型对输入数据 x 和 y 进行拟合,并将拟合结果保存在 prob_fit 变量中。同样需要将 y 转换为一维数组。 ``` python coef_mat = np.column_stack((prob_fit.theta.T, logit_fit.coef_, linear_fit.coef_)) ``` 将三种模型的系数按列方向拼接成一个矩阵 coef_mat,并将其保存在变量中。其中,prob_fit.theta.T 表示高斯朴素贝叶斯模型的均值向量,logit_fit.coef_ 表示逻辑回归模型的系数向量,linear_fit.coef_ 表示线性回归模型的系数向量。 ``` python print(coef_mat) ``` 输出拼接后的系数矩阵 coef_mat,用于查看模型系数的取值。 ``` python prop_mat = np.column_stack((prob_fit.theta_.T / logit_fit.coef_, prob_fit.theta_.T / linear_fit.coef_, logit_fit.coef_ / linear_fit.coef_)) ``` 计算三种模型系数之间的比例,并将比例矩阵 prop_mat 保存在变量中。其中,prob_fit.theta_.T 表示高斯朴素贝叶斯模型的方差向量,用于计算与其他模型系数的比例。 这段代码主要用于分析和比较三种不同的模型在给定数据上的表现,并通过系数比例来进一步分析模型的特点和差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值