python logistic步骤_Python api.Logit方法代码示例
本文整理汇总了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)
except:
result=log_clf.fit(disp=0,method='powell')
llf=result.llf
llnull=result.llnull
lm=np.exp(llf)
lnull=np.exp(llnull)
cox_and_snell_rsquare=(1-(lnull/lm)**(2/N))
return cox_and_snell_rsquare
开发者ID:dominance-analysis,项目名称:dominance-analysis,代码行数:18,
示例4: test_logistic_regressions
点赞 6
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def test_logistic_regressions():
def _test_random_logistic_regression():
n_uncorr_features, n_corr_features, n_drop_features = (
generate_regression_hyperparamters())
X, y, parameters = make_logistic_regression(
n_samples=N_SAMPLES,
n_uncorr_features=n_uncorr_features,
n_corr_features=n_corr_features,
n_drop_features=n_drop_features)
lr = GLM(family=Bernoulli())
lr.fit(X, y)
#assert approx_equal(lr.coef_, parameters)
mod = sm.Logit(y, X)
res = mod.fit()
assert approx_equal(lr.coef_, res.params)
assert approx_equal(lr.coef_standard_error_, res.bse)
for _ in range(N_REGRESSION_TESTS):
_test_random_logistic_regression()
开发者ID:madrury,项目名称:py-glm,代码行数:22,
示例5: setup
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def setup(self):
#fit for each test, because results will be changed by test
x = self.exog
nobs = x.shape[0]
np.random.seed(987689)
y_bin = (np.random.rand(nobs) < 1.0 / (1 + np.exp(x.sum(1) - x.mean()))).astype(int)
model = sm.Logit(y_bin, x) #, exposure=np.ones(nobs), offset=np.zeros(nobs)) #bug with default
# use start_params to converge faster
start_params = np.array([-0.73403806, -1.00901514, -0.97754543, -0.95648212])
self.results = model.fit(start_params=start_params, method='bfgs', disp=0)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,
示例6: setup_class
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def setup_class(cls):
data = sm.datasets.spector.load()
data.exog = sm.add_constant(data.exog, prepend=False)
#mod = sm.Probit(data.endog, data.exog)
cls.mod = sm.Logit(data.endog, data.exog)
#res = mod.fit(method="newton")
cls.params = [np.array([1,0.25,1.4,-7])]
##loglike = mod.loglike
##score = mod.score
##hess = mod.hessian
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,
示例7: run_logistic_regression
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def run_logistic_regression(df):
# Logistic regression
X = df['pageviews_cumsum']
X = sm.add_constant(X)
y = df['is_conversion']
logit = sm.Logit(y, X)
logistic_regression_results = logit.fit()
print(logistic_regression_results.summary())
return logistic_regression_results
开发者ID:thomhopmans,项目名称:themarketingtechnologist,代码行数:11,
示例8: run_logistic_regression
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def run_logistic_regression(self):
# Logistic regression
X = self.df['pageviews_cumsum']
X = sm.add_constant(X)
y = self.df['is_conversion']
logit = sm.Logit(y, X)
self.logistic_regression_results = logit.fit()
print self.logistic_regression_results.summary()
开发者ID:thomhopmans,项目名称:themarketingtechnologist,代码行数:10,
示例9: McFadden_RSquare
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def McFadden_RSquare(self,columns):
cols=columns.copy()
cols.append('intercept')
# print("model columns :",cols)
log_clf=sm.Logit(self.data[self.target],self.data[cols])
# result=log_clf.fit(disp=0,method='powell')
try:
result=log_clf.fit(disp=0)
except:
result=log_clf.fit(disp=0,method='powell')
mcfadden_rsquare=result.prsquared
return mcfadden_rsquare
开发者ID:dominance-analysis,项目名称:dominance-analysis,代码行数:14,
示例10: Estrella
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def Estrella(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
estrella_rsquare=1-((llf/llnull)**(-(2/N)*llnull))
return estrella_rsquare
开发者ID:dominance-analysis,项目名称:dominance-analysis,代码行数:16,
示例11: Adjusted_McFadden_RSquare
点赞 5
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def Adjusted_McFadden_RSquare(self,columns):
log_clf=sm.Logit(self.data[self.target],self.data[cols])
# 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
adjusted_mcfadden_rsquare=1-((llf-len(columns))/llnull)
return adjusted_mcfadden_rsquare
开发者ID:dominance-analysis,项目名称:dominance-analysis,代码行数:13,
示例12: estimate_treatment_effect
点赞 4
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def estimate_treatment_effect(covariates, treatment, outcome):
"""Estimate treatment effects using propensity weighted least-squares.
Parameters
----------
covariates: `np.ndarray`
Array of shape [num_samples, num_features] of features
treatment: `np.ndarray`
Binary array of shape [num_samples] indicating treatment status for each
sample.
outcome: `np.ndarray`
Array of shape [num_samples] containing the observed outcome for each sample.
Returns
-------
result: `whynot.framework.InferenceResult`
InferenceResult object for this procedure
"""
start_time = perf_counter()
# Compute propensity scores with logistic regression model.
features = sm.add_constant(covariates, prepend=True, has_constant="add")
logit = sm.Logit(treatment, features)
model = logit.fit(disp=0)
propensities = model.predict(features)
# IP-weights
treated = treatment == 1.0
untreated = treatment == 0.0
weights = treated / propensities + untreated / (1.0 - propensities)
treatment = treatment.reshape(-1, 1)
features = np.concatenate([treatment, covariates], axis=1)
features = sm.add_constant(features, prepend=True, has_constant="add")
model = sm.WLS(outcome, features, weights=weights)
results = model.fit()
stop_time = perf_counter()
# Treatment is the second variable (after the constant offset)
ate = results.params[1]
stderr = results.bse[1]
conf_int = tuple(results.conf_int()[1])
return InferenceResult(
ate=ate,
stderr=stderr,
ci=conf_int,
individual_effects=None,
elapsed_time=stop_time - start_time,
)
开发者ID:zykls,项目名称:whynot,代码行数:54,
示例13: estimate_treatment_effect
点赞 4
# 需要导入模块: from statsmodels import api [as 别名]
# 或者: from statsmodels.api import Logit [as 别名]
def estimate_treatment_effect(covariates, treatment, outcome):
"""Estimate treatment effects using propensity score matching.
Parameters
----------
covariates: `np.ndarray`
Array of shape [num_samples, num_features] of features
treatment: `np.ndarray`
Binary array of shape [num_samples] indicating treatment status for each
sample.
outcome: `np.ndarray`
Array of shape [num_samples] containing the observed outcome for each sample.
Returns
-------
result: `whynot.framework.InferenceResult`
InferenceResult object for this procedure
"""
start_time = perf_counter()
# Compute propensity scores with logistic regression model.
features = sm.add_constant(covariates, has_constant="add")
logit = sm.Logit(treatment, features)
model = logit.fit(disp=0)
propensity_scores = model.predict(features)
matched_treatment, matched_outcome, matched_weights = get_matched_dataset(
treatment, propensity_scores, outcome
)
ate = compute_ate(matched_outcome, matched_treatment, matched_weights)
# Bootstrap confidence intervals
samples = []
num_units = len(matched_treatment)
for _ in range(1000):
sample_idxs = np.random.choice(num_units, size=num_units, replace=True)
samples.append(
compute_ate(
matched_outcome[sample_idxs],
matched_treatment[sample_idxs],
matched_weights[sample_idxs],
)
)
conf_int = (np.quantile(samples, 0.025), np.quantile(samples, 0.975))
stop_time = perf_counter()
return InferenceResult(
ate=ate,
stderr=None,
ci=conf_int,
individual_effects=None,
elapsed_time=stop_time - start_time,
)
开发者ID:zykls,项目名称:whynot,代码行数:57,
注:本文中的statsmodels.api.Logit方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。
python logistic步骤_Python api.Logit方法代码示例相关推荐
- python html模板_Python html.format_html方法代码示例
本文整理汇总了Python中django.utils.html.format_html方法的典型用法代码示例.如果您正苦于以下问题:Python html.format_html方法的具体用法?Pyt ...
- python session模块_Python backend.set_session方法代码示例
本文整理汇总了Python中keras.backend.set_session方法的典型用法代码示例.如果您正苦于以下问题:Python backend.set_session方法的具体用法?Pyth ...
- python color属性_Python turtle.color方法代码示例
本文整理汇总了Python中turtle.color方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.color方法的具体用法?Python turtle.color怎么用?P ...
- python end用法_Python turtle.end_fill方法代码示例
本文整理汇总了Python中turtle.end_fill方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.end_fill方法的具体用法?Python turtle.end_ ...
- python qt 按钮_Python QtWidgets.QPushButton方法代码示例
本文整理汇总了Python中PySide2.QtWidgets.QPushButton方法的典型用法代码示例.如果您正苦于以下问题:Python QtWidgets.QPushButton方法的具体用 ...
- python geometry用法_Python geometry.MultiPolygon方法代码示例
本文整理汇总了Python中shapely.geometry.MultiPolygon方法的典型用法代码示例.如果您正苦于以下问题:Python geometry.MultiPolygon方法的具体用 ...
- python iteritems函数_Python six.iteritems方法代码示例
本文整理汇总了Python中sklearn.externals.six.iteritems方法的典型用法代码示例.如果您正苦于以下问题:Python six.iteritems方法的具体用法?Pyth ...
- python gc模块_Python gc.collect方法代码示例
本文整理汇总了Python中gc.collect方法的典型用法代码示例.如果您正苦于以下问题:Python gc.collect方法的具体用法?Python gc.collect怎么用?Python ...
- python fmod函数_Python numpy.fmod方法代码示例
本文整理汇总了Python中numpy.fmod方法的典型用法代码示例.如果您正苦于以下问题:Python numpy.fmod方法的具体用法?Python numpy.fmod怎么用?Python ...
最新文章
- 用Gogs在Windows上搭建Git服务
- python 进阶:修饰器的介绍
- MFC中OnInitDialog自动生成
- springmvc三十二:spring mvc的运行流程
- linux子系统使用rstudio,Windows 10 Linux子系统 (wsl)学习手记
- ADFS 登录页面自定义
- java你画我猜源码_为什么看到Mybatis源码就感到烦躁?
- pika集群水平扩展——让性能容量不再受限
- Python:如何安装whl文件
- jQuery打印插件JQPRINT
- 程序员又双叒叕开始装逼了,这次用代码写合租广告,网友神评亮了
- 【高项】第4章 项目整体管理与变更管理【知识点精华笔记】
- 如何制作一个优秀的个人网站?
- Error: While importing ‘run_app_dev‘, an ImportError was raised.
- 用计算机绘制函数图象教案,信息技术应用 用计算机画函数图象优质课教案设计...
- CVT变速器中壳体吊机设计
- java rgb十六进制数据转图片
- 以大多数人的努力程度之低,根本轮不到拼智商
- 【Python自动化办公】批量将Excel表格数据导出为PDF文件
- ue4透明折射无法扭曲背后透明物体问题