def rf_cv(fv_train,target_train,fv_test,target_test):
####---- cross validation of train dataset, gridsearch the best parameters for random forest
# Set the parameters by cross-validation
tuned_parameters = {'n_estimators': [1000, 2000],
"max_depth": [3, 6, 9, None],
"max_features": ["auto","log2",None],
"class_weight": [None, 'balanced']}
scores = ['recall_macro']
n_iter_search = 20
for score in scores:
print("# Tuning hyper-parameters for %s" % score)
print()
mycv = StratifiedKFold(target_train, n_folds = 5)
clf = RandomizedSearchCV(RandomForestClassifier(n_jobs=-1), tuned_parameters, cv=mycv, n_iter=n_iter_search,
scoring='%s' % score)
clf.fit(fv_train, target_train)
report_cv(clf,fv_test,target_test)
VUVclassification.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录