python类nan()的实例源码

sph.py 文件源码 项目:sound_field_analysis-py 作者: QULab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def sphankel2(n, kr):
    """Spherical Hankel (second kind) of order n at kr

    Parameters
    ----------
    n : array_like
       Order
    kr: array_like
       Argument

    Returns
    -------
    hn2 : complex float
       Spherical Hankel function hn (second kind)
    """
    n, kr = scalar_broadcast_match(n, kr)
    hn2 = _np.full(n.shape, _np.nan, dtype=_np.complex_)
    kr_nonzero = kr != 0
    hn2[kr_nonzero] = _np.sqrt(_np.pi / 2) / _np.lib.scimath.sqrt(kr[kr_nonzero]) * hankel2(n[kr_nonzero] + 0.5, kr[kr_nonzero])
    return hn2
sph.py 文件源码 项目:sound_field_analysis-py 作者: QULab 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def dsphankel1(n, kr):
    """Derivative spherical Hankel (first kind) of order n at kr

    Parameters
    ----------
    n : array_like
       Order
    kr: array_like
       Argument

    Returns
    -------
    dhn1 : complex float
       Derivative of spherical Hankel function hn' (second kind)
    """
    n, kr = scalar_broadcast_match(n, kr)
    dhn1 = _np.full(n.shape, _np.nan, dtype=_np.complex_)
    kr_nonzero = kr != 0
    dhn1[kr_nonzero] = 0.5 * (sphankel1(n[kr_nonzero] - 1, kr[kr_nonzero]) - sphankel1(n[kr_nonzero] + 1, kr[kr_nonzero]) - sphankel1(n[kr_nonzero], kr[kr_nonzero]) / kr[kr_nonzero])
    return dhn1
sph.py 文件源码 项目:sound_field_analysis-py 作者: QULab 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def dsphankel2(n, kr):
    """Derivative spherical Hankel (second kind) of order n at kr

    Parameters
    ----------
    n : array_like
       Order
    kr: array_like
       Argument

    Returns
    -------
    dhn2 : complex float
       Derivative of spherical Hankel function hn' (second kind)
    """
    n, kr = scalar_broadcast_match(n, kr)
    dhn2 = _np.full(n.shape, _np.nan, dtype=_np.complex_)
    kr_nonzero = kr != 0
    dhn2[kr_nonzero] = 0.5 * (sphankel2(n[kr_nonzero] - 1, kr[kr_nonzero]) - sphankel2(n[kr_nonzero] + 1, kr[kr_nonzero]) - sphankel2(n[kr_nonzero], kr[kr_nonzero]) / kr[kr_nonzero])
    return dhn2
mparray_test.py 文件源码 项目:mpnum 作者: dseuss 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_sumup(nr_sites, local_dim, rank, rgen, dtype):
    mpas = [factory.random_mpa(nr_sites, local_dim, 3, dtype=dtype, randstate=rgen)
            for _ in range(rank if rank is not np.nan else 1)]
    sum_naive = ft.reduce(mp.MPArray.__add__, mpas)
    sum_mp = mp.sumup(mpas)

    assert_array_almost_equal(sum_naive.to_array(), sum_mp.to_array())
    assert all(r <= 3 * rank for r in sum_mp.ranks)
    assert(sum_mp.dtype is dtype)

    weights = rgen.randn(len(mpas))
    summands = [w * mpa for w, mpa in zip(weights, mpas)]
    sum_naive = ft.reduce(mp.MPArray.__add__, summands)
    sum_mp = mp.sumup(mpas, weights=weights)
    assert_array_almost_equal(sum_naive.to_array(), sum_mp.to_array())
    assert all(r <= 3 * rank for r in sum_mp.ranks)
    assert(sum_mp.dtype is dtype)
plot_4d.py 文件源码 项目:CombinX 作者: SimCMinMax 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def generateTickStep(dps):
    coeff = [1., 2., 5.]
    coeffIdx = 0
    mult = 1.
    step = coeff[coeffIdx] * mult

    #Replaces 0 by NaN to ignore 0 as min
    dps_new = dps
    dps_new[dps_new == 0] = np.nan

    dpsRange = max(dps) - min(dps_new)
    while dpsRange / step >= 8:
        coeffIdx = (coeffIdx + 1) % 3
        if coeffIdx == 0:
            mult = mult * 10.
        step = coeff[coeffIdx] * mult
    return step
fits2skymodel.py 文件源码 项目:atoolbox 作者: liweitianux 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def write_fits(self, outfile, oldheader=None, clobber=False):
        if os.path.exists(outfile) and (not clobber):
            raise OSError("Sky FITS already exists: %s" % outfile)
        if oldheader is not None:
            header = oldheader
            header.extend(self.fits_header, update=True)
        else:
            header = self.fits_header
        header.add_history(datetime.now().isoformat())
        header.add_history(" ".join(sys.argv))
        image = self.image
        image[~self.mask] = np.nan
        image *= self.factor_K2JyPixel
        hdu = fits.PrimaryHDU(data=image, header=header)
        try:
            hdu.writeto(outfile, overwrite=True)
        except TypeError:
            hdu.writeto(outfile, clobber=True)  # old astropy versions
        logger.info("Wrote FITS image of sky model to file: %s" % outfile)
mixedmodels.py 文件源码 项目:histwords 作者: williamleif 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def make_data_frame(words, years, feature_dict):
    """
    Makes a pandas dataframe for word, years, and dictionary of feature funcs.
    Each feature func should take (word, year) and return feature value.
    Constructed dataframe has flat csv style structure and missing values are removed.
    """

    temp = collections.defaultdict(list)
    feature_dict["word"] = lambda word, year : word
    feature_dict["year"] = lambda word, year : year
    for word in words:
        for year in years:
            for feature, feature_func in feature_dict.iteritems():
                temp[feature].append(feature_func(word, year))
    df = pd.DataFrame(temp)
    df = df.replace([np.inf, -np.inf], np.nan)
    df = df.dropna()
    return df
test_alpha_rarefaction.py 文件源码 项目:q2-diversity 作者: qiime2 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_alpha_rarefaction_with_empty_column_in_metadata(self):
        t = biom.Table(np.array([[100, 111, 113], [111, 111, 112]]),
                       ['O1', 'O2'],
                       ['S1', 'S2', 'S3'])
        md = qiime2.Metadata(
            pd.DataFrame({'pet': ['russ', 'milo', 'peanut', 'summer'],
                          'foo': [np.nan, np.nan, np.nan, 'bar']},
                         index=['S1', 'S2', 'S3', 'S4']))
        with tempfile.TemporaryDirectory() as output_dir:
            alpha_rarefaction(output_dir, t, max_depth=200, metadata=md)

            index_fp = os.path.join(output_dir, 'index.html')
            self.assertTrue(os.path.exists(index_fp))
            with open(index_fp, 'r') as fh:
                contents = fh.read()

            self.assertTrue('observed_otus' in contents)
            self.assertTrue('shannon' in contents)
            self.assertTrue('did not contain any values:' in contents)

            metric_fp = os.path.join(output_dir, 'shannon-pet.jsonp')
            self.assertTrue('summer' not in open(metric_fp).read())
            self.assertFalse(
                os.path.exists(os.path.join(output_dir, 'shannon-foo.jsonp')))
pylspm.py 文件源码 项目:pylspm 作者: lseman 项目源码 文件源码 阅读 50 收藏 0 点赞 0 评论 0
def htmt(self):

        htmt_ = pd.DataFrame(pd.DataFrame.corr(self.data_),
                             index=self.manifests, columns=self.manifests)

        mean = []
        allBlocks = []
        for i in range(self.lenlatent):
            block_ = self.Variables['measurement'][
                self.Variables['latent'] == self.latent[i]]
            allBlocks.append(list(block_.values))
            block = htmt_.ix[block_, block_]
            mean_ = (block - np.diag(np.diag(block))).values
            mean_[mean_ == 0] = np.nan
            mean.append(np.nanmean(mean_))

        comb = [[k, j] for k in range(self.lenlatent)
                for j in range(self.lenlatent)]

        comb_ = [(np.sqrt(mean[comb[i][1]] * mean[comb[i][0]]))
                 for i in range(self.lenlatent ** 2)]

        comb__ = []
        for i in range(self.lenlatent ** 2):
            block = (htmt_.ix[allBlocks[comb[i][1]],
                              allBlocks[comb[i][0]]]).values
#            block[block == 1] = np.nan
            comb__.append(np.nanmean(block))

        htmt__ = np.divide(comb__, comb_)
        where_are_NaNs = np.isnan(htmt__)
        htmt__[where_are_NaNs] = 0

        htmt = pd.DataFrame(np.tril(htmt__.reshape(
            (self.lenlatent, self.lenlatent)), k=-1), index=self.latent, columns=self.latent)

        return htmt
utils.py 文件源码 项目:spyking-circus 作者: spyking-circus 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def as_float_array(X, copy=True, force_all_finite=True):
    """Converts an array-like to an array of floats
    The new dtype will be np.float32 or np.float64, depending on the original
    type. The function can create a copy or modify the argument depending
    on the argument copy.
    Parameters
    ----------
    X : {array-like, sparse matrix}
    copy : bool, optional
        If True, a copy of X will be created. If False, a copy may still be
        returned if X's dtype is not a floating point type.
    force_all_finite : boolean (default=True)
        Whether to raise an error on np.inf and np.nan in X.
    Returns
    -------
    XT : {array, sparse matrix}
        An array of type np.float
    """
    if isinstance(X, np.matrix) or (not isinstance(X, np.ndarray)
                                    and not sp.issparse(X)):
        return check_array(X, ['csr', 'csc', 'coo'], dtype=np.float64,
                           copy=copy, force_all_finite=force_all_finite,
                           ensure_2d=False)
    elif sp.issparse(X) and X.dtype in [np.float32, np.float64]:
        return X.copy() if copy else X
    elif X.dtype in [np.float32, np.float64]:  # is numpy array
        return X.copy('F' if X.flags['F_CONTIGUOUS'] else 'C') if copy else X
    else:
        return X.astype(np.float32 if X.dtype == np.int32 else np.float64)
tf_util.py 文件源码 项目:distributional_perspective_on_RL 作者: Kiwoo 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def explained_variance_1d(ypred,y):
    """
    Var[ypred - y] / var[y]. 
    https://www.quora.com/What-is-the-meaning-proportion-of-variance-explained-in-linear-regression
    """
    assert y.ndim == 1 and ypred.ndim == 1    
    vary = np.var(y)
    return np.nan if vary==0 else 1 - np.var(y-ypred)/vary
test_stats.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 54 收藏 0 点赞 0 评论 0
def test_ignore_nan(self):
        """ Test that NaNs are handled correctly """
        stream = [np.random.random(size = (16,12)) for _ in range(5)]
        for s in stream:
            s[randint(0, 15), randint(0,11)] = np.nan

        with catch_warnings():
            simplefilter('ignore')
            from_iaverage = last(iaverage(stream, ignore_nan = True))  
        from_numpy = np.nanmean(np.dstack(stream), axis = 2)
        self.assertTrue(np.allclose(from_iaverage, from_numpy))
test_stats.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_against_numpy_nanmean(self):
        """ Test results against numpy.mean"""
        source = [np.random.random((16, 12, 5)) for _ in range(10)]
        for arr in source:
            arr[randint(0, 15), randint(0, 11), randint(0, 4)] = np.nan
        stack = np.stack(source, axis = -1)
        for axis in (0, 1, 2, None):
            with self.subTest('axis = {}'.format(axis)):
                from_numpy = np.nanmean(stack, axis = axis)
                out = last(imean(source, axis = axis, ignore_nan = True))
                self.assertSequenceEqual(from_numpy.shape, out.shape)
                self.assertTrue(np.allclose(out, from_numpy))
test_stats.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_against_scipy_with_nans(self):
        """ Test that isem outputs the same as scipy.stats.sem when NaNs are ignored. """
        source = [np.random.random((16, 12, 5)) for _ in range(10)]
        for arr in source:
            arr[randint(0, 15), randint(0, 11), randint(0, 4)] = np.nan
        stack = np.stack(source, axis = -1)

        for axis in (0, 1, 2, None):
            for ddof in range(4):
                with self.subTest('axis = {}, ddof = {}'.format(axis, ddof)):
                    from_scipy = scipy_sem(stack, axis = axis, ddof = ddof, nan_policy = 'omit')
                    from_isem = last(isem(source, axis = axis, ddof = ddof, ignore_nan = True))
                    self.assertSequenceEqual(from_scipy.shape, from_isem.shape)
                    self.assertTrue(np.allclose(from_isem, from_scipy))
test_cuda.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_ignore_nans(self):
        """ Test a sum of zeros with NaNs sprinkled """
        source = [np.zeros((16,), dtype = np.float) for _ in range(10)]
        source.append(np.full((16,), fill_value = np.nan))
        summed = csum(source, ignore_nan = True)
        self.assertTrue(np.allclose(summed, np.zeros_like(summed)))
test_reduce.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUp(self):
        self.source = [np.random.random((16,5,8)) for _ in range(10)]
        self.source[0][0,0,0] = np.nan
        self.stack = np.stack(self.source, axis = -1)
test_numerics.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_ignore_nans(self):
        """ Test a sum of zeros with NaNs sprinkled """
        source = [np.zeros((16,), dtype = np.float) for _ in range(10)]
        source.append(np.full((16,), fill_value = np.nan))
        summed = last(isum(source, ignore_nan = True))
        self.assertTrue(np.allclose(summed, np.zeros_like(summed)))
test_numerics.py 文件源码 项目:npstreams 作者: LaurentRDC 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def test_ignore_nans(self):
        """ Test that NaNs are ignored. """
        source = [np.ones((16,), dtype = np.float) for _ in range(10)]
        source.append(np.full_like(source[0], np.nan))
        product = last(iprod(source, ignore_nan = True))
        self.assertTrue(np.allclose(product, np.ones_like(product)))
history_container.py 文件源码 项目:zipline-chinese 作者: zhanghan1990 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def frame_to_series(self, field, frame, columns=None):
        """
        Convert a frame with a DatetimeIndex and sid columns into a series with
        a sid index, using the aggregator defined by the given field.
        """
        if isinstance(frame, pd.DataFrame):
            columns = frame.columns
            frame = frame.values

        if not len(frame):
            return pd.Series(
                data=(0 if field == 'volume' else np.nan),
                index=columns,
            ).values

        if field in ['price', 'close']:
            # shortcircuit for full last row
            vals = frame[-1]
            if np.all(~np.isnan(vals)):
                return vals
            return ffill(frame)[-1]
        elif field == 'open':
            return bfill(frame)[0]
        elif field == 'volume':
            return np.nansum(frame, axis=0)
        elif field == 'high':
            return np.nanmax(frame, axis=0)
        elif field == 'low':
            return np.nanmin(frame, axis=0)
        else:
            raise ValueError("Unknown field {}".format(field))
cumulative.py 文件源码 项目:zipline-chinese 作者: zhanghan1990 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __repr__(self):
        statements = []
        for metric in self.METRIC_NAMES:
            value = getattr(self, metric)[-1]
            if isinstance(value, list):
                if len(value) == 0:
                    value = np.nan
                else:
                    value = value[-1]
            statements.append("{m}:{v}".format(m=metric, v=value))

        return '\n'.join(statements)
tdx_formula.py 文件源码 项目:tdx_formula 作者: woodylee1974 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def FORCAST(self, param):
        class Context:
            def __init__(self, N):
                self.N = N
                self.q = deque([], self.N)
                self.x = [i for i in range(self.N)]

            def handleInput(self, value):
                if len(self.q) < self.N:
                    self.q.append(value)
                    return np.NaN
                z1 = np.polyfit(self.x, self.q, 1)
                fn = np.poly1d(z1)
                y = fn(self.N + 1)
                self.q.append(value)
                return y

        ctx = Context(param[1])
        result = param[0].apply(ctx.handleInput)
        return result

#????
ShareData.py 文件源码 项目:SharesData 作者: xjkj123 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def Rstr(self):
        array2=[]
        prixe = math.log(0.03637 / float(252) + 1)
        ret = self.sharedf
        ret['change']=ret['change']-prixe
        rstr = []
        print 1
        if len(ret) > 525:
            for z in range(0, 504):
                array2.append(math.pow(math.pow(float(1) / 2, float(1 / float(126))), (503 - z)))

            for h in  range(0,525):
                rstr.append(numpy.NaN)

            for c in range(525, len(ret)):
                rett=0
                for f in range(0,len(duan)-21):
                    rett=rett+duan.iloc[f, 16]*array2[f]
                rstr.append(rett)

            print rstr
            ret['rstr'] = rstr
            return ret[['date','rstr']]
ShareData.py 文件源码 项目:SharesData 作者: xjkj123 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def Cetop(self):
        tdate=[]
        Cetop=[]
        dfxjllb = Tools().ReadSqlData(self.name+"_sina", "xjllbdata")
        dfgg = self.sharedf
        for x in range(0,len(dfxjllb.index)):
            if dfxjllb.loc[x,u'????'][4:] == "0331":
                tdate.append(int(dfxjllb.loc[x, u'????'][:4]+"0430"))
            else:
                if dfxjllb.loc[x, u'????'][4:] == "0630":
                    tdate.append(int(dfxjllb.loc[x, u'????'][:4] + "0831"))
                else:
                    if dfxjllb.loc[x, u'????'][4:] == "0930":
                        tdate.append(int(dfxjllb.loc[x, u'????'][:4] + "1031"))
                    else:
                        if dfxjllb.loc[x, u'????'][4:] == "1231":
                            tdate.append(int(str(int(dfxjllb.loc[x, u'????'][:4]) + 1) + "0430"))
                        else:
                            tdate.append(numpy.NaN)
        dfxjllb['tdate']=tdate
        for x in range(1,len(dfgg.index)+1):
            Cetop.append(float(dfxjllb[dfxjllb[u'tdate']<int(str(dfgg.loc[x,u'date']).replace('-',''))].iloc[0,15:16])/dfgg.loc[x,u'traded_market_value'])
        dfgg['Cetop']=Cetop                                                                                        #
        return dfgg[['date','Cetop']]
_visualizer.py 文件源码 项目:q2-diversity 作者: qiime2 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _compute_rarefaction_data(feature_table, min_depth, max_depth, steps,
                              iterations, phylogeny, metrics):
    depth_range = np.linspace(min_depth, max_depth, num=steps, dtype=int)
    iter_range = range(1, iterations + 1)

    rows = feature_table.ids(axis='sample')
    cols = pd.MultiIndex.from_product([list(depth_range), list(iter_range)],
                                      names=['depth', 'iter'])
    data = {k: pd.DataFrame(np.NaN, index=rows, columns=cols)
            for k in metrics}

    for d, i in itertools.product(depth_range, iter_range):
        rt = rarefy(feature_table, d)
        for m in metrics:
            if m in phylogenetic_metrics():
                vector = alpha_phylogenetic(table=rt, metric=m,
                                            phylogeny=phylogeny)
            else:
                vector = alpha(table=rt, metric=m)
            data[m][(d, i)] = vector
    return data
test_utils.py 文件源码 项目:plotnine 作者: has2k1 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_remove_missing():
    df = pd.DataFrame({'a': [1.0, np.NaN, 3, np.inf],
                       'b': [1, 2, 3, 4]})
    df2 = pd.DataFrame({'a': [1.0, 3, np.inf],
                       'b': [1, 3, 4]})
    df3 = pd.DataFrame({'a': [1.0, 3],
                       'b': [1, 3]})

    with warnings.catch_warnings(record=True) as w:
        res = remove_missing(df, na_rm=True, vars=['b'])
        res.equals(df)

        res = remove_missing(df)
        res.equals(df2)

        res = remove_missing(df, na_rm=True, finite=True)
        res.equals(df3)
        assert len(w) == 1
scale.py 文件源码 项目:plotnine 作者: has2k1 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def limits(self):
        if self.is_empty():
            return (0, 1)

        # Fall back to the range if the limits
        # are not set or if any is None or NaN
        if self._limits is not None and self.range.range is not None:
            limits = []
            if len(self._limits) == len(self.range.range):
                for l, r in zip(self._limits, self.range.range):
                    value = r if pd.isnull(l) else l
                    limits.append(value)
            else:
                limits = self._limits
            return tuple(limits)
        return self.range.range
base.py 文件源码 项目:pandas-profiling 作者: JosPolfliet 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def describe_numeric_1d(series, **kwargs):
    stats = {'mean': series.mean(), 'std': series.std(), 'variance': series.var(), 'min': series.min(),
            'max': series.max()}
    stats['range'] = stats['max'] - stats['min']

    for x in np.array([0.05, 0.25, 0.5, 0.75, 0.95]):
        stats[pretty_name(x)] = series.dropna().quantile(x) # The dropna() is a workaround for https://github.com/pydata/pandas/issues/13098
    stats['iqr'] = stats['75%'] - stats['25%']
    stats['kurtosis'] = series.kurt()
    stats['skewness'] = series.skew()
    stats['sum'] = series.sum()
    stats['mad'] = series.mad()
    stats['cv'] = stats['std'] / stats['mean'] if stats['mean'] else np.NaN
    stats['type'] = "NUM"
    stats['n_zeros'] = (len(series) - np.count_nonzero(series))
    stats['p_zeros'] = stats['n_zeros'] / len(series)
    # Histograms
    stats['histogram'] = histogram(series, **kwargs)
    stats['mini_histogram'] = mini_histogram(series, **kwargs)
    return pd.Series(stats, name=series.name)
plot.py 文件源码 项目:geoviews 作者: ioam 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_extents(self, element, ranges):
        """
        Subclasses the get_extents method using the GeoAxes
        set_extent method to project the extents to the
        Elements coordinate reference system.
        """
        extents = super(GeoPlot, self).get_extents(element, ranges)
        if not getattr(element, 'crs', None) or not self.geographic:
            return extents
        elif any(e is None or not np.isfinite(e) for e in extents):
            extents = None
        else:
            try:
                extents = project_extents(extents, element.crs, DEFAULT_PROJ)
            except:
                extents = None
        return (np.NaN,)*4 if not extents else extents
geopandas.py 文件源码 项目:geoviews 作者: ioam 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def values(cls, dataset, dimension, expanded, flat):
        dimension = dataset.get_dimension(dimension)
        idx = dataset.get_dimension_index(dimension)
        data = dataset.data
        if idx not in [0, 1] and not expanded:
            return data[dimension.name].values
        values = []
        columns = list(data.columns)
        arr = geom_to_array(data.geometry.iloc[0])
        ds = dataset.clone(arr, datatype=cls.subtypes, vdims=[])
        for i, d in enumerate(data.geometry):
            arr = geom_to_array(d)
            if idx in [0, 1]:
                ds.data = arr
                values.append(ds.interface.values(ds, dimension))
            else:
                arr = np.full(len(arr), data.iloc[i, columns.index(dimension.name)])
                values.append(arr)
            values.append([np.NaN])
        return np.concatenate(values[:-1]) if values else np.array([])
test_logistic.py 文件源码 项目:diamond 作者: stitchfix 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def setUp(self):
        data = {"response": [0, 1, 1],
                "var_a": [21, 32, 10],
                "cyl": [4, 6, 4]}
        df = pd.DataFrame(data, index=[0, 1, 2])

        priors_data = {
            "grp": ["cyl", "cyl", "cyl"],
            "var1": ["intercept", "intercept", "var_a"],
            "var2": [np.NaN, "var_a", np.NaN],
            "vcov": [0.123, -1.42, 0.998]
        }
        priors_df = pd.DataFrame(priors_data, index=[0, 1, 2])

        self.formula = "response ~ 1 + var_a + (1 + var_a | cyl)"

        self.model = LogisticRegression(train_df=df,
                                        priors_df=priors_df,
                                        test_df=None)


问题


面经


文章

微信
公众号

扫码关注公众号