python的scikit-learn将特征转成one-hot特征的方法

AndroidAmelia 2018-07-10

如下所示:

enc = OneHotEncoder(categorical_features=np.array([0,1,2]),n_values=[5,4,2]) 
 enc.fit(train_data) 
 train_data = enc.transform(train_data).toarray() 
 test_data = enc.transform(test_data).toarray()

相关推荐