通过构建随机森林,为变量进行编码:
RandomTreesEmbedding:https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomTreesEmbedding.html
import numpy as np import pandas as pd from sklearn.ensemble import RandomTreesEmbedding dataframe = pd.DataFrame(np.random.random(size=(100, 5))) # 建模 tree_embedding = RandomTreesEmbedding( n_estimators=10, max_depth=3, random_state=0).fit(dataframe.values) # 转换 spare_embedding = tree_embedding.transform(dataframe) encode_array = spare_embedding.toarray() # 得到numpy的结果 print(encode_array.shape)
3 uses for random decision trees / forests you (maybe) didn’t know about:https://blog.davidvassallo.me/2019/08/06/3-uses-for-random-decision-trees-forests-you-maybe-didnt-know-about/