encoder.py 文件源码

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

项目:kaggle-review 作者: daxiongshu 项目源码 文件源码
def onehot_encode(tr,te,cols=None):
    if cols is None:
        cols = [i for i in tr.columns.values if i in te.columns.values]
    vec = DictVectorizer()
    for col in cols:
        tr[col] = tr[col].map(str)
        te[col] = te[col].map(str)
    print("start fitting")
    X = vec.fit_transform(tr[cols].T.to_dict().values())
    Xt = vec.transform(te[cols].T.to_dict().values())
    print("done fitting",X.shape,Xt.shape)
    return X,Xt
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号