日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/29 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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方法代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。