【发布时间】:2017-12-15 06:03:55
【问题描述】:
我正在使用 gridsearchCV 来寻找 BIRCH 的最佳参数,我的代码是:
RAND_STATE=50 # for reproducibility and consistency
folds=3
k_fold = KFold(n_splits=folds, shuffle=True, random_state=RAND_STATE)
hyperparams = { "branching_factor": [50,100,200,300,400,500,600,700,800,900],
"n_clusters": [5,7,9,11,13,17,21],
"threshold": [0.2,0.3,0.4,0.5,0.6,0.7]}
birch = Birch()
def sil_score(ndata):
labels = ensemble.predict(ndata)
score = silhouette_score(ndata, labels)
return score
sil_scorer = make_scorer(sil_score)
ensemble = GridSearchCV(estimator=birch,param_grid=hyperparams,scoring=sil_scorer,cv=k_fold,verbose=10,n_jobs=-1)
ensemble.fit(x)
print ensemble
best_parameters = ensemble.best_params_
print best_parameters
best_score = ensemble.best_score_
print best_score
但是输出给了我一个错误:
当我已经在 sil_score 函数中说明了评分所需的参数时,我很困惑为什么分数值正在寻找 4 个参数。
【问题讨论】:
标签: python validation optimization scikit-learn cluster-analysis