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


Python empirical_distribution.ECDF属性代码示例

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


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

示例1: fit_transform

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def fit_transform(self, X, y=None):
        """Normalize numerical columns.

        Args:
            X (pandas.DataFrame) : numerical columns to normalize

        Returns:
            (pandas.DataFrame): normalized numerical columns
        """

        self.ecdfs = [None] * X.shape[1]

        for col in range(X.shape[1]):
            self.ecdfs[col] = ECDF(X[col].values)
            X[col] = self._transform_col(X[col], col)

        return X 
开发者ID:jeongyoonlee,项目名称:Kaggler,代码行数:19,代码来源:numerical.py

示例2: __init__

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def __init__(self, n_label=10, sample=100000, random_state=42):
        """Initialize a QuantileEncoder class object.

        Args:
            n_label (int): the number of labels to be created.
            sample (int or float): the number or fraction of samples for ECDF
        """
        self.n_label = n_label
        self.sample = sample
        self.random_state = random_state 
开发者ID:jeongyoonlee,项目名称:Kaggler,代码行数:12,代码来源:numerical.py

示例3: fit

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def fit(self, X, y=None):
        """Get empirical CDFs of numerical features.

        Args:
            X (pandas.DataFrame): numerical features to encode

        Returns:
            A trained QuantileEncoder object.
        """
        def _calculate_ecdf(x):
            return ECDF(x[~np.isnan(x)])

        if self.sample >= X.shape[0]:
            self.ecdfs = X.apply(_calculate_ecdf, axis=0)
        elif self.sample > 1:
            self.ecdfs = X.sample(n=self.sample,
                                  random_state=self.random_state).apply(
                                      _calculate_ecdf, axis=0
                                  )
        else:
            self.ecdfs = X.sample(frac=self.sample,
                                  random_state=self.random_state).apply(
                                      _calculate_ecdf, axis=0
                                  )

        return self 
开发者ID:jeongyoonlee,项目名称:Kaggler,代码行数:28,代码来源:numerical.py

示例4: calculate_empirical_pvalue

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def calculate_empirical_pvalue(local_area, dpsi_abs_value):

    abs_local_area = [abs(val) for val in local_area]

    ecdf = ECDF(abs_local_area)

    # It is divided by 2 because we are using abs(deltaPSI) values and therefore it is a one-tailed test
    event_pvalue = (1.0 - ecdf(dpsi_abs_value)) * 0.5

    return event_pvalue 
开发者ID:comprna,项目名称:SUPPA,代码行数:12,代码来源:diff_tools.py

示例5: ecdf

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def ecdf(x):
    return ECDF(x) 
开发者ID:shubhomoydas,项目名称:ad_examples,代码行数:4,代码来源:utils.py

示例6: compute_group

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def compute_group(cls, data, scales, **params):
        # If n is None, use raw values; otherwise interpolate
        if params['n'] is None:
            x = np.unique(data['x'])
        else:
            x = np.linspace(data['x'].min(), data['x'].max(),
                            params['n'])

        y = ECDF(data['x'])(x)
        res = pd.DataFrame({'x': x, 'y': y})
        return res 
开发者ID:has2k1,项目名称:plotnine,代码行数:13,代码来源:stat_ecdf.py

示例7: test_cdf_sample_consistency

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def test_cdf_sample_consistency(self):
    from statsmodels.distributions.empirical_distribution import ECDF
    model = EconDensity()

    x_cond = np.asarray([0.1 for _ in range(200000)])
    _, y_sample = model.simulate_conditional(x_cond)

    emp_cdf = ECDF(y_sample.flatten())
    cdf = lambda y: model.cdf(x_cond, y)

    mean_cdf_diff = np.mean(np.abs(emp_cdf(y_sample).flatten() - cdf(y_sample).flatten()))
    self.assertLessEqual(mean_cdf_diff, 0.01) 
开发者ID:freelunchtheorem,项目名称:Conditional_Density_Estimation,代码行数:14,代码来源:unittests_simulations.py

示例8: omega_empirical

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def omega_empirical(returns, target_rtn=0, log=True, plot=False, steps=1000):
    """
    Omega Ratio based on empirical distribution.
    """
    # validate_return_type(return_type)

    if not log:
        returns = pct_to_log_return(returns)

    # TODO
    ecdf = sde.ECDF(returns)

    # Generate computation space
    x = np.linspace(start=returns.min(), stop=returns.max(), num=steps)
    y = ecdf(x)

    norm_cdf = ss.norm.cdf(x, loc=returns.mean(), scale=returns.std(ddof=1))

    # Plot empirical distribution CDF versus Normal CDF with same mean and
    # stdev
    if plot:
        fig, ax = plt.subplots()
        fig.set_size_inches((12, 6))
        ax.plot(x, y, c="r", ls="--", lw=1.5, alpha=0.8, label="ECDF")
        ax.plot(x, norm_cdf, alpha=0.3, ls="-", c="b", lw=5, label="Normal CDF")
        ax.legend(loc="best")
        plt.show(fig)
        plt.close(fig)

    # TODO calculate omega ratio 
开发者ID:esvhd,项目名称:pypbo,代码行数:32,代码来源:metrics.py

示例9: _interpolate_HSD_dict

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def _interpolate_HSD_dict(self):
        """Method to extrapolate input data.

        This method uses a non-parametric approach to expand the input
        recharge array to the length of number of iterations. Output is
        a new dictionary of interpolated recharge for each HSD id.
        """
        HSD_dict = copy.deepcopy(self._HSD_dict)
        # First generate interpolated Re for each HSD grid
        Yrand = np.sort(np.random.rand(self._n))
        # n random numbers (0 to 1) in a column
        for vkey in HSD_dict.keys():
            if isinstance(HSD_dict[vkey], int):
                continue  # loop back up if value is integer (e.g. -9999)
            Re_temp = HSD_dict[vkey]  # an array of annual Re for 1 HSD grid
            Fx = ECDF(Re_temp)  # instantiate to get probabilities with Re
            Fx_ = Fx(Re_temp)  # probability array associated with Re data
            # interpolate function based on recharge data & probability
            f = interpolate.interp1d(
                Fx_, Re_temp, bounds_error=False, fill_value=min(Re_temp)
            )
            # array of Re interpolated from Yrand probabilities (n count)
            Re_interpolated = f(Yrand)
            # replace values in HSD_dict with interpolated Re
            HSD_dict[vkey] = Re_interpolated

        self._interpolated_HSD_dict = HSD_dict 
开发者ID:landlab,项目名称:landlab,代码行数:29,代码来源:landslide_probability.py

示例10: ecdfer

# 需要导入模块: from statsmodels.distributions import empirical_distribution [as 别名]
# 或者: from statsmodels.distributions.empirical_distribution import ECDF [as 别名]
def ecdfer(df: pd.DataFrame,
           ascending: bool = True,
           prediction_column: str = "prediction",
           ecdf_column: str = "prediction_ecdf",
           max_range: int = 1000) -> LearnerReturnType:
    """
    Learns an Empirical Cumulative Distribution Function from the specified column
    in the input DataFrame. It is usually used in the prediction column to convert
    a predicted probability into a score from 0 to 1000.

    Parameters
    ----------
    df : Pandas' pandas.DataFrame
        A Pandas' DataFrame that must contain a `prediction_column` columns.

    ascending : bool
        Whether to compute an ascending ECDF or a descending one.

    prediction_column : str
        The name of the column in `df` to learn the ECDF from.

    ecdf_column : str
        The name of the new ECDF column added by this function

    max_range : int
        The maximum value for the ECDF. It will go will go
         from 0 to max_range.
    """

    if ascending:
        base = 0
        sign = 1
    else:
        base = max_range
        sign = -1

    values = df[prediction_column]

    ecdf = ed.ECDF(values)

    def p(new_df: pd.DataFrame) -> pd.DataFrame:
        return new_df.assign(**{ecdf_column: (base + sign * max_range * ecdf(new_df[prediction_column]))})

    p.__doc__ = learner_pred_fn_docstring("ecdefer")

    log = {'ecdfer': {
        'nobs': len(values),
        'prediction_column': prediction_column,
        'ascending': ascending,
        'transformed_column': [ecdf_column]}}

    return p, p(df), log 
开发者ID:nubank,项目名称:fklearn,代码行数:54,代码来源:transformation.py


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