我一直在研究几种排名特征选择方法。如您所知,这些类型的算法根据某种特定方法(例如统计、稀疏学习等)对特征进行排序,并且它们由多个超参数决定,必须调整这些超参数才能获得最佳结果。
现有技术提出了不同的参数调整方法,通过浏览网络,我发现了以下方法:网格搜索方法。如本link中指定的,搜索由以下步骤组成:
- 功能选择器
- 搜索或抽样候选者的方法;
- 参数空间
- 交叉验证方案
- 评分函数。
我在这段代码中总结了以下步骤(从第3点开始):
tuned_parameters = {
'LASSO': {'alpha': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]},
}
# pick the i-th feature selector
for fs_name, fs_model in slb_fs.iteritems():
comb = []
params_name = []
for name, tun_par in tuned_parameters[fs_name].iteritems():
comb.append(tun_par)
params_name.append(name)
# function for creating all the exhausted combination of the parameters
print ('\t3 - Creating parameters space: ')
combs = create_grid(comb)
for comb in combs:
# pick the i-th combination of the parameters for the k-th feature selector
fs_model.setParams(comb,params_name,params[fs_name])
# number of folds for k-CV
k_fold = 5
X = dataset.data
y = dataset.target
kf = KFold(n_splits=k_fold)
print ('\t4 - Performing K-cross validation: ')
for train_index, test_index in kf.split(X):
X_train, X_test = X[train_index, :], X[test_index, :]
y_train, y_test = y[train_index], y[test_index]
print ('\t5.1 - Performing feature selection using: ', fs_name)
idx = fs_model.fit(X_train, y_train)
# At this point I have the ranked features
print ('5.2 - Classification...')
for n_rep in xrange(step, max_num_feat + step, step):
# Using classifier to evaluate the algorithm performance on the test set using incrementally the retrieved feature (1,2,3,...,max_num_feat)
X_train_fs = X_train[:, idx[0:n_rep]]
X_test_fs = X_test[:, idx[0:n_rep]]
_clf = clf.Classifier(names=clf_name, classifiers=model)
DTS = _clf.train_and_classify(X_train_fs, y_train, X_test_fs, y_test)
# Averaging results of the CV
print('\t4.Averaging results...')
在第 5.1 点,我使用分类器来评估所选特征选择器在特征子集上获得的性能(在我的例子中,由于对特征进行了排名,所以我逐渐使用它们),并通过交叉对结果进行平均-验证方案。此时我得到的结果是每个特征子集的平均准确度得分(例如 1: 70%、2:75、3:77%、...、N:100%)。
显然,后者的结果是对每个参数组合得出的平均结果(见下表)。 例如,假设当前的特征选择器只需要调整参数alpha,我得到的结果如下表所示。
我的问题是:是否有任何已知的方法可以根据所有功能或固定数量的功能所取得的结果来选择最佳参数配置?
我考虑过对结果进行平均并将其用作“最佳配置”,但我认为它行不通。有谁知 Prop 体的方法吗?
如果有人能帮助我,我将非常感激。
最佳答案
再见@DavideNardone
关于性能衡量标准,@kutschkem 是正确的:如果您正在进行二元分类并且您的方法生成混淆矩阵,请使用马修斯相关系数 (MCC) 而不是准确性或 F1分数或其他比率。请查看我的 paper 中的提示 8出于科学原因。
关于如何为您的模型选择最佳配置,我认为您的大多数方法是在正确的方向上。 我会这样重新构建它:
- 当特征数量变化时,投票选出最佳配置(最高 Matthews 相关系数 MCC),然后
- 选择投票数最多的配置。
也许这种方法不是世界上最好的,但肯定具有强大的科学背景(事实上,random forest 中也使用了多数票)。
此外,我认为 Stack Overflow 可能不是询问计算智能问题的最佳场所;我建议您在Cross Validated上移动/重新询问这个问题或其他Stack Exchange websites .
祝你好运!
关于python - 用于特征选择的详尽网格搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51773317/