stratification.py 文件源码

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

项目:oasis 作者: ngmarchant 项目源码 文件源码
def stratify_by_features(features, n_strata, **kwargs):
    """Stratify by clustering the items in feature space

    Parameters
    ----------
    features : array-like, shape=(n_items,n_features)
        feature matrix for the pool, where rows correspond to items and columns
        correspond to features.

    n_strata : int
        number of strata to create.

    **kwargs :
        passed to sklearn.cluster.KMeans

    Returns
    -------
    Strata instance
    """
    n_items = features.shape[0]
    km = KMeans(n_clusters=n_strata, **kwargs)
    allocations = km.fit_predict(X=features)
    return Strata(allocations)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号