context_transformations.py 文件源码

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

项目:bolero 作者: rock-learning 项目源码 文件源码
def polynomial(context, n_degrees=2):
    # From sklearn.preprocessing.PolynomialFeatures
    # Find permutations/combinations which add to degree or less
    context = np.asarray(context)
    n_features = context.shape[0]
    powers = itertools.product(*(range(n_degrees + 1)
                                 for i in range(n_features)))
    powers = np.array([c for c in powers if 0 <= np.sum(c) <= n_degrees])
    # Sort so that the order of the powers makes sense
    i = np.lexsort(np.vstack([powers.T, powers.sum(axis=1)]))
    powers = powers[i][::-1]
    return (context ** powers).prod(-1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号