pandas 函数
pandas.get_dummies()
对one-hot编码
#以kaggle titanic 里面的片段为例
features = ["Pclass", "Sex", "SibSp", "Parch"]
X = pd.get_dummies(train_data[features])
print(X)
pandas.DataFrame() 可以用字典方式创建
output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
sklearn函数
RandomForestClassifier 随机决策树
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier(n_estimators=10)
>>> clf = clf.fit(X, Y)