MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / SFSSelectFeature

Method SFSSelectFeature

JSAT/src/jsat/datatransform/featureselection/SFS.java:256–297  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

searchMethod · 0.95
searchMethod · 0.95
searchMethod · 0.95

Calls 8

removeFeatureMethod · 0.95
applyTransformMethod · 0.95
getScoreMethod · 0.95
addFeatureMethod · 0.95
getNumCategoricalVarsMethod · 0.80
sizeMethod · 0.65
shallowCloneMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected