当前位置: 首页>>代码示例>>Python>>正文


Python api.Logit方法代码示例

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


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

示例1: compute

# 需要导入模块: 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,代码来源:pscore.py

示例2: Nagelkerke_Rsquare

# 需要导入模块: 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,代码来源:dominance.py

示例3: Cox_and_Snell_Rsquare

# 需要导入模块: 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,代码来源:dominance.py

示例4: test_logistic_regressions

# 需要导入模块: 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,代码来源:test_glm.py

示例5: setup

# 需要导入模块: 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,代码来源:test_generic_methods.py

示例6: setup_class

# 需要导入模块: 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,代码来源:test_numdiff.py

示例7: run_logistic_regression

# 需要导入模块: 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,代码来源:business_case_solver_without_classes.py

示例8: run_logistic_regression

# 需要导入模块: 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,代码来源:business_case_solver.py

示例9: McFadden_RSquare

# 需要导入模块: 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,代码来源:dominance.py

示例10: Estrella

# 需要导入模块: 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,代码来源:dominance.py

示例11: Adjusted_McFadden_RSquare

# 需要导入模块: 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,代码来源:dominance.py

示例12: estimate_treatment_effect

# 需要导入模块: 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,代码来源:propensity_weighted_ols.py

示例13: estimate_treatment_effect

# 需要导入模块: 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,代码来源:propensity_score_matching.py


注:本文中的statsmodels.api.Logit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。