utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:lain 作者: llllllllll 项目源码 文件源码
def summary(feature_names, features, **labels):
    """Summarize the data we are about to train with.

    Parameters
    ----------
    feature_names : iterable[str]
        The names of the features in the ``features`` array.
    features : np.ndarray
        The 3d feature array.
    **labels
        The named label arrays.

    Returns
    -------
    summary : str
        A summary of the features and labels.
    """
    single_attribute_template = dedent(
        """\
        {name}:
          mean: {mean}
          std:  {std}
          min:  {min}
          max:  {max}""",
    )

    def format_attribute(name, values):
        return '    ' + '\n    '.join(
            single_attribute_template.format(
                name=name,
                mean=values.mean(),
                std=values.std(),
                min=values.min(),
                max=values.max(),
            ).splitlines(),
        )

    return '\n'.join(concatv(
        (
            'summary:',
            '  labels:',
        ),
        (
            format_attribute(name, value)
            for name, value in sorted(labels.items(), key=first)
        ),
        (
            'features:',
        ),
        (
            format_attribute(name, features[..., ix])
            for ix, name in enumerate(feature_names)
        )
    ))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号