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


Python numpy.nanmean方法代码示例

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


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

示例1: test_select_confounds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def test_select_confounds(confounds_file, selected_confounds, nan_confounds,
                          expanded_confounds):
    import pandas as pd
    import numpy as np

    confounds_df = pd.read_csv(str(confounds_file), sep='\t', na_values='n/a')

    res_df = _select_confounds(str(confounds_file), selected_confounds)

    # check if the correct columns are selected
    assert set(expanded_confounds) == set(res_df.columns)

    # check if nans are being imputed when expected
    if nan_confounds:
        for nan_c in nan_confounds:
            vals = confounds_df[nan_c].values
            expected_result = np.nanmean(vals[vals != 0])
            assert res_df[nan_c][0] == expected_result 
开发者ID:HBClab,项目名称:NiBetaSeries,代码行数:20,代码来源:test_nistats.py

示例2: eval_detection_voc

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def eval_detection_voc(pred_boxlists, gt_boxlists, iou_thresh=0.5, use_07_metric=False):
    """Evaluate on voc dataset.
    Args:
        pred_boxlists(list[BoxList]): pred boxlist, has labels and scores fields.
        gt_boxlists(list[BoxList]): ground truth boxlist, has labels field.
        iou_thresh: iou thresh
        use_07_metric: boolean
    Returns:
        dict represents the results
    """
    assert len(gt_boxlists) == len(
        pred_boxlists
    ), "Length of gt and pred lists need to be same."
    prec, rec, n_tp, n_fp, n_pos = calc_detection_voc_prec_rec(
        pred_boxlists=pred_boxlists, gt_boxlists=gt_boxlists, iou_thresh=iou_thresh
    )
    ap = calc_detection_voc_ap(prec, rec, use_07_metric=use_07_metric)
    prec = {k: v.tolist() for k, v in prec.items()}
    rec = {k: v.tolist() for k, v in rec.items()}
    res = [{"ap": ap[k], "class_id": k, "precisions": prec[k], "recalls": rec[k],
            "n_tp": n_tp[k], "n_fp": n_fp[k], "n_positives": n_pos[k]} for k in ap.keys()]
    return res, np.nanmean(ap.values()) 
开发者ID:jayleicn,项目名称:TVQAplus,代码行数:24,代码来源:voc_eval.py

示例3: _signal_synchrony_correlation

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _signal_synchrony_correlation(signal1, signal2, window_size, center=False):
    """Calculates pairwise rolling correlation at each time. Grabs the upper triangle, at each timepoints.

    - window: window size of rolling corr in samples
    - center: whether to center result (Default: False, so correlation values are listed on the right.)

    """
    data = pd.DataFrame({"y1": signal1, "y2": signal2})

    rolled = data.rolling(window=window_size, center=center).corr()
    synchrony = rolled["y1"].loc[rolled.index.get_level_values(1) == "y2"].values

    # Realign
    synchrony = np.append(synchrony[int(window_size / 2) :], np.full(int(window_size / 2), np.nan))
    synchrony[np.isnan(synchrony)] = np.nanmean(synchrony)

    return synchrony 
开发者ID:neuropsychology,项目名称:NeuroKit,代码行数:19,代码来源:signal_synchrony.py

示例4: compute_average_mAP_N_for_characteristic

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def compute_average_mAP_N_for_characteristic(sensitivity_analysis, characteristic_name):
    gt_by_characteristic = sensitivity_analysis.ground_truth.groupby(characteristic_name)
    average_mAP_n_by_characteristic_value = OrderedDict()
    
    for characteristic_value, this_characteristic_gt in gt_by_characteristic:
        ap = np.nan*np.zeros(len(sensitivity_analysis.activity_index))
        gt_by_cls = this_characteristic_gt.groupby('label')
        pred_by_cls = sensitivity_analysis.prediction.groupby('label')
        for cls in sensitivity_analysis.activity_index.values():
            this_cls_pred = pred_by_cls.get_group(cls).sort_values(by='score',ascending=False)
            try:
                this_cls_gt = gt_by_cls.get_group(cls)
            except:
                continue
            gt_id_to_keep = np.append(this_cls_gt['gt-id'].values, [np.nan])
        
            for tidx, tiou in enumerate(sensitivity_analysis.tiou_thresholds):
                this_cls_pred = this_cls_pred[this_cls_pred[sensitivity_analysis.matched_gt_id_cols[tidx]].isin(gt_id_to_keep)]
            
            ap[cls] = compute_mAP_N(sensitivity_analysis,this_cls_pred,this_cls_gt)

        average_mAP_n_by_characteristic_value[characteristic_value] = np.nanmean(ap)

    return average_mAP_n_by_characteristic_value 
开发者ID:HumamAlwassel,项目名称:DETAD,代码行数:26,代码来源:sensitivity_analysis.py

示例5: eval_detection_voc

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def eval_detection_voc(pred_boxlists, gt_boxlists, iou_thresh=0.5, use_07_metric=False):
    """Evaluate on voc dataset.
    Args:
        pred_boxlists(list[BoxList]): pred boxlist, has labels and scores fields.
        gt_boxlists(list[BoxList]): ground truth boxlist, has labels field.
        iou_thresh: iou thresh
        use_07_metric: boolean
    Returns:
        dict represents the results
    """
    assert len(gt_boxlists) == len(
        pred_boxlists
    ), "Length of gt and pred lists need to be same."
    prec, rec = calc_detection_voc_prec_rec(
        pred_boxlists=pred_boxlists, gt_boxlists=gt_boxlists, iou_thresh=iou_thresh
    )
    ap = calc_detection_voc_ap(prec, rec, use_07_metric=use_07_metric)
    return {"ap": ap, "map": np.nanmean(ap)} 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:20,代码来源:voc_eval.py

示例6: segmentation_scores

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def segmentation_scores(label_trues, label_preds, n_class):
    """Returns accuracy score evaluation result.
      - overall accuracy
      - mean accuracy
      - mean IU
      - fwavacc
    """
    hist = np.zeros((n_class, n_class))
    for lt, lp in zip(label_trues, label_preds):
        hist += _fast_hist(lt.flatten(), lp.flatten(), n_class)
    acc = np.diag(hist).sum() / hist.sum()
    acc_cls = np.diag(hist) / hist.sum(axis=1)
    acc_cls = np.nanmean(acc_cls)
    iu = np.diag(hist) / (hist.sum(axis=1) + hist.sum(axis=0) - np.diag(hist))
    mean_iu = np.nanmean(iu)
    freq = hist.sum(axis=1) / hist.sum()
    fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()

    return {'overall_acc': acc,
            'mean_acc': acc_cls,
            'freq_w_acc': fwavacc,
            'mean_iou': mean_iu} 
开发者ID:ozan-oktay,项目名称:Attention-Gated-Networks,代码行数:24,代码来源:metrics.py

示例7: get_scores

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def get_scores(self):
        """Returns accuracy score evaluation result.
            - overall accuracy
            - mean accuracy
            - mean IU
            - fwavacc
        """
        hist = self.confusion_matrix
        acc = np.diag(hist).sum() / hist.sum()
        acc_cls = np.diag(hist) / hist.sum(axis=1)
        acc_cls = np.nanmean(acc_cls)
        iu = np.diag(hist) / (hist.sum(axis=1) + hist.sum(axis=0) - np.diag(hist))
        mean_iu = np.nanmean(iu)
        freq = hist.sum(axis=1) / hist.sum()
        fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()
        cls_iu = dict(zip(range(self.n_classes), iu))

        return {'Overall Acc: \t': acc,
                'Mean Acc : \t': acc_cls,
                'FreqW Acc : \t': fwavacc,
                'Mean IoU : \t': mean_iu,}, cls_iu 
开发者ID:zhechen,项目名称:PLARD,代码行数:23,代码来源:metrics.py

示例8: _recmat_smooth

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _recmat_smooth(presented, recalled, features, distance, match):

    if match == 'best':
        func = np.argmax
    elif match == 'smooth':
        func = np.nanmean

    simmtx = _similarity_smooth(presented, recalled, features, distance)


    if match == 'best':
        recmat = np.atleast_3d([func(s, 1) for s in simmtx]).astype(np.float64)
        recmat+=1
        recmat[np.isnan(simmtx).any(2)]=np.nan
    elif match == 'smooth':
        recmat = np.atleast_3d([func(s, 0) for s in simmtx]).astype(np.float64)


    return recmat 
开发者ID:ContextLab,项目名称:quail,代码行数:21,代码来源:recmat.py

示例9: _similarity_smooth

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _similarity_smooth(presented, recalled, features, distance):
    lists = presented.index.get_values()
    res = np.empty((len(lists), len(features), recalled.iloc[0].shape[0], presented.iloc[0].shape[0]))*np.nan
    for li, l in enumerate(lists):
        p_list = presented.loc[l]
        r_list = recalled.loc[l]
        for i, feature in enumerate(features):
            get_feature = lambda x: np.array(x[feature]) if np.array(pd.notna(x['item'])).any() else np.nan
            p = np.vstack(p_list.apply(get_feature).get_values())
            r = r_list.dropna().apply(get_feature).get_values()
            r = np.vstack(list(filter(lambda x: x is not np.nan, r)))
            tmp = 1 - cdist(r, p, distance)
            res[li, i, :tmp.shape[0], :] =  tmp
    if distance == 'correlation':
        return np.nanmean(res, 1)
    else:
        return np.mean(res, 1) 
开发者ID:ContextLab,项目名称:quail,代码行数:19,代码来源:recmat.py

示例10: _get_weight_best

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _get_weight_best(egg, feature, distdict, permute, n_perms, distance):

    if permute:
        return _permute(egg, feature, distdict, _get_weight_best, n_perms)

    rec = list(egg.get_rec_items().values[0])
    if len(rec) <= 2:
        warnings.warn('Not enough recalls to compute fingerprint, returning default'
              'fingerprint.. (everything is .5)')
        return np.nan

    distmat = get_distmat(egg, feature, distdict)
    matchmat = get_match(egg, feature, distdict)

    ranks = []
    for i in range(len(rec)-1):
        cdx, ndx = np.argmin(matchmat[i, :]), np.argmin(matchmat[i+1, :])
        dists = distmat[cdx, :]
        di = dists[ndx]
        dists_filt = np.array([dist for idx, dist in enumerate(dists)])
        ranks.append(np.mean(np.where(np.sort(dists_filt)[::-1] == di)[0]+1) / len(dists_filt))
    return np.nanmean(ranks) 
开发者ID:ContextLab,项目名称:quail,代码行数:24,代码来源:clustering.py

示例11: _get_weight_smooth

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _get_weight_smooth(egg, feature, distdict, permute, n_perms, distance):

    if permute:
        return _permute(egg, feature, distdict, _get_weight_smooth, n_perms)

    rec = list(egg.get_rec_items().values[0])
    if len(rec) <= 2:
        warnings.warn('Not enough recalls to compute fingerprint, returning default'
              'fingerprint.. (everything is .5)')
        return np.nan

    distmat = get_distmat(egg, feature, distdict)
    matchmat = get_match(egg, feature, distdict)

    ranks = []
    for i in range(len(rec)-1):
        cdx, ndx = np.argmin(matchmat[i, :]), np.argmin(matchmat[i+1, :])
        dists = distmat[cdx, :]
        di = dists[ndx]
        dists_filt = np.array([dist for idx, dist in enumerate(dists)])
        ranks.append(np.mean(np.where(np.sort(dists_filt)[::-1] == di)[0]+1) / len(dists_filt))
    return np.nanmean(ranks) 
开发者ID:ContextLab,项目名称:quail,代码行数:24,代码来源:clustering.py

示例12: _nanquantile_unchecked

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def _nanquantile_unchecked(a, q, axis=None, out=None, overwrite_input=False,
                           interpolation='linear', keepdims=np._NoValue):
    """Assumes that q is in [0, 1], and is an ndarray"""
    # apply_along_axis in _nanpercentile doesn't handle empty arrays well,
    # so deal them upfront
    if a.size == 0:
        return np.nanmean(a, axis, out=out, keepdims=keepdims)

    r, k = function_base._ureduce(
        a, func=_nanquantile_ureduce_func, q=q, axis=axis, out=out,
        overwrite_input=overwrite_input, interpolation=interpolation
    )
    if keepdims and keepdims is not np._NoValue:
        return r.reshape(q.shape + k)
    else:
        return r 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:nanfunctions.py

示例13: cal_scores

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def cal_scores(hist):
    n_class = settings.N_CLASSES
    acc = np.diag(hist).sum() / hist.sum()
    acc_cls = np.diag(hist) / hist.sum(axis=1)
    acc_cls = np.nanmean(acc_cls)
    iu = np.diag(hist) / (hist.sum(axis=1) + hist.sum(axis=0) - np.diag(hist))
    mean_iu = np.nanmean(iu)
    freq = hist.sum(axis=1) / hist.sum()
    fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()
    cls_iu = dict(zip(label_names, iu))

    return {
        'pAcc': acc,
        'mAcc': acc_cls,
        'fIoU': fwavacc,
        'mIoU': mean_iu,
    }, cls_iu 
开发者ID:XiaLiPKU,项目名称:EMANet,代码行数:19,代码来源:metric.py

示例14: cal_scores

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def cal_scores(hist):
    n_class = settings.N_CLASSES
    #acc = np.diag(hist).sum() / hist.sum()
    #acc_cls = np.diag(hist) / hist.sum(axis=1)
    #acc_cls = np.nanmean(acc_cls)
    iu = np.diag(hist) / (hist.sum(axis=1) + hist.sum(axis=0) - np.diag(hist))
    mean_iu = np.nanmean(iu)
    freq = hist.sum(axis=1) / hist.sum()
    fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()
    cls_iu = dict(zip(label_names, iu))

    return {
        #"pAcc": acc,
        #"mAcc": acc_cls,
        "fIoU": fwavacc,
        "mIoU": mean_iu,
    }#, cls_iu 
开发者ID:XiaLiPKU,项目名称:EMANet,代码行数:19,代码来源:metric.py

示例15: mape

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanmean [as 别名]
def mape(y_pred, y_test):
    r"""
    The Mean Absolute Percentage Error (MAPE)

    The MAPE is computed as the mean of the absolute value of the relative
    error in percent, i.e.:

    .. math::

        \text{MAPE}(\mathbf{y}, \mathbf{y}_{true}) =
        \frac{100\%}{n}\sum_{i = 0}^n \frac{|y_{\text{pred},i} - y_{\text{true},i}|}
             {|y_{\text{true},i}|}

    Arguments:

        y_pred(numpy.array): The predicted scalar values.

        y_test(numpy.array): The true values.

    Returns:

        The MAPE for the given predictions.

    """
    return np.nanmean(100.0 * np.abs(y_test - y_pred.ravel()) / np.abs(y_test).ravel()) 
开发者ID:atmtools,项目名称:typhon,代码行数:27,代码来源:scores.py


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