本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.col方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.col方法的具体用法?Python RandomForestClassifier.col怎么用?Python RandomForestClassifier.col使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.col方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_forest
# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import col [as 别名]
def get_forest(data=None, n_estimators=None, max_depth=None, max_leaf_nodes=None):
# get training data
data = data if len(data) > 0 else pc.get_post('train')
n_estimators = n_estimators or 1000
max_depth = max_depth or 30
max_leaf_nodes = max_leaf_nodes or 2500
# split data 80 / 20
X_train, X_test, y_train, y_test = train_test_split(data[data.columns.difference(['TripType', 'VisitNumber'])], data.TripType, test_size=0.2, random_state=42)
# might tweak initialization of the forest
# instantiate forest
rf = RandomForestClassifier(n_jobs=-1, verbose=True, n_estimators=n_estimators, oob_score=True, max_depth=max_depth, \
max_leaf_nodes = max_leaf_nodes, min_samples_leaf=3)
# train forest
fitted = rf.fit(X_train, y_train)
# we'll need these later to trim the test data set to those columns
# upon which the forest has been trained
rf.col = X_train.columns
return rf