本文整理汇总了Python中sklearn.ensemble.BaggingClassifier.class_weight方法的典型用法代码示例。如果您正苦于以下问题:Python BaggingClassifier.class_weight方法的具体用法?Python BaggingClassifier.class_weight怎么用?Python BaggingClassifier.class_weight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.BaggingClassifier
的用法示例。
在下文中一共展示了BaggingClassifier.class_weight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tuple
# 需要导入模块: from sklearn.ensemble import BaggingClassifier [as 别名]
# 或者: from sklearn.ensemble.BaggingClassifier import class_weight [as 别名]
c_vals = [0.01, 0.1, 1, 10]
c_weights = ['auto']
param_grid = tuple([c_vals, c_weights])
param_grid = list(product(*param_grid))
# storage structure for forecasts
mvalid = np.zeros((xtrain.shape[0],len(param_grid)))
mfull = np.zeros((xtest.shape[0],len(param_grid)))
## build 2nd level forecasts
for i in range(len(param_grid)):
print "processing parameter combo:", i
# configure model with j-th combo of parameters
x = param_grid[i]
model.C = x[0]
model.class_weight = x[1]
# loop over folds
for j in range(0,n_folds):
idx0 = np.where(fold_index != j)
idx1 = np.where(fold_index == j)
x0 = np.array(xtrain)[idx0,:][0]; x1 = np.array(xtrain)[idx1,:][0]
y0 = np.array(ytrain)[idx0]; y1 = np.array(ytrain)[idx1]
# fit the model on observations associated with subject whichSubject in this fold
model.fit(x0, y0)
mvalid[idx1,i] = model.predict_proba(x1)[:,1]
# fit on complete dataset
model.fit(xtrain, ytrain)
mfull[:,i] = model.predict_proba(xtest)[:,1]