Attempts to add one feature to the list of features while increasing or maintaining the current accuracy @param available the set of available features from [0, n) to consider for adding @param dataSet the original data set to perform feature selection from @param catToRemove the current set of cat
(Set<Integer> available,
DataSet dataSet, Set<Integer> catToRemove, Set<Integer> numToRemove,
Set<Integer> catSelecteed, Set<Integer> numSelected,
Object evaluater, int folds, Random rand, double[] PbestScore,
int minFeatures)
| 254 | * @return the feature that was selected to add, or -1 if none were added. |
| 255 | */ |
| 256 | static protected int SFSSelectFeature(Set<Integer> available, |
| 257 | DataSet dataSet, Set<Integer> catToRemove, Set<Integer> numToRemove, |
| 258 | Set<Integer> catSelecteed, Set<Integer> numSelected, |
| 259 | Object evaluater, int folds, Random rand, double[] PbestScore, |
| 260 | int minFeatures) |
| 261 | { |
| 262 | int nCat = dataSet.getNumCategoricalVars(); |
| 263 | int curBest = -1; |
| 264 | double curBestScore = Double.POSITIVE_INFINITY; |
| 265 | for(int feature : available) |
| 266 | { |
| 267 | removeFeature(feature, nCat, catToRemove, numToRemove); |
| 268 | |
| 269 | DataSet workOn = dataSet.shallowClone(); |
| 270 | RemoveAttributeTransform remove = new RemoveAttributeTransform(workOn, catToRemove, numToRemove); |
| 271 | workOn.applyTransform(remove); |
| 272 | |
| 273 | double score = getScore(workOn, evaluater, folds, rand); |
| 274 | |
| 275 | if(score < curBestScore) |
| 276 | { |
| 277 | curBestScore = score; |
| 278 | curBest = feature; |
| 279 | } |
| 280 | addFeature(feature, nCat, catToRemove, numToRemove); |
| 281 | } |
| 282 | if(curBestScore <= 1e-14 && PbestScore[0] <= 1e-14 |
| 283 | && catSelecteed.size() + numSelected.size() >= minFeatures ) |
| 284 | return -1; |
| 285 | if (curBestScore < PbestScore[0] |
| 286 | || catSelecteed.size() + numSelected.size() < minFeatures |
| 287 | || Math.abs(PbestScore[0]-curBestScore) < 1e-3) |
| 288 | { |
| 289 | PbestScore[0] = curBestScore; |
| 290 | addFeature(curBest, nCat, catSelecteed, numSelected); |
| 291 | removeFeature(curBest, nCat, catToRemove, numToRemove); |
| 292 | available.remove(curBest); |
| 293 | return curBest; |
| 294 | } |
| 295 | else |
| 296 | return -1; //No possible improvment & weve got enough |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * The score function for a data set and a learner by cross validation of a |
no test coverage detected