DEV Community

Cover image for Does simulated annealing help pick a smaller feature set?
masaya oka
masaya oka

Posted on Edited on AI-assisted

Does simulated annealing help pick a smaller feature set?

After preparing a dataset, I sometimes want to know which measurements I can leave out. If a column is expensive to collect, a model that uses fewer columns could make the next round of data collection easier. Japanese original

There are 4,095 nonempty ways to choose up to six of Wine's 13 features. Evaluating each combination takes a series of model fits. DIY AutoML's optional CPU command, annealing-check, sets a budget for how many subsets to score. Command and report design (Japanese)

Give a lower-scoring candidate a chance

Simulated annealing starts from a subset. A nearby candidate adds a column, removes a column, or swaps a selected column with an unselected one. The search accepts a candidate whose score is at least as high as the current one. It sometimes accepts a lower-scoring candidate, which lets it move through a worse subset to look for a better one. Original paper on simulated annealing

For a score decrease, the acceptance probability is exp((candidate score - current score) / temperature). The temperature falls from 0.03 to 0.002 by default. For example, a drop of 0.01 has a roughly 72% chance of acceptance at the initial temperature and about 0.67% at the final temperature. The report records the moves and returns the best subset found, preferring fewer columns when scores tie. Feature subset search implementation

Compare searches with the same number of candidates

I fixed the classifier to an SVM and changed the feature subsets. All candidates used the same two repeats of stratified five-fold cross-validation on the training data. The scaler was fitted on the training portion of each fold. The search averaged ten validation macro F1 scores per candidate.

Annealing and random search shared an initial subset and evaluated the same number of distinct subsets. Random search drew uniformly from the remaining eligible combinations. Each candidate required ten fits, so a budget of eight meant 80 fits per method, and a budget of 32 meant 320. I also ran a separate model with all features and evaluated all 15 nonempty subsets on Iris.

Each method refitted the classifier on all the training rows using its chosen subset. The final tests used the same held-out rows, 30 for Iris and 36 for Wine. I kept the data splits fixed, varying only the search seed from 44 through 53.

Dataset Budget per method Cross-validation result
Iris 8 subsets The exhaustive maximum was 0.9707, using all four features. Annealing reached it in 3 of 10 runs and random search in 8 of 10.
Wine 32 subsets With up to six features per subset, each search method had the higher cross-validation score in 5 of 10 runs.

On Wine at seed 44, the five-feature annealing model and the full 13-feature model agreed on all 36 predictions. This happened in one of the ten runs. In that run, annealing scored +0.0558 in held-out macro F1 relative to random search, with a 95% interval of [0.0000, +0.1419].

The interval keeps the fitted models fixed and resamples the same evaluation rows for both methods within classes. The intervals included zero for all 20 Iris and Wine searches, leaving the direction unresolved under these conditions. The runs show how the subset choice can vary even with the same split and evaluation budget. Experiment settings and results (Japanese)

Reproduce search seed 44

From the repository root, run these PowerShell commands using the installed .venv. Use a new value for $work on subsequent runs.


powershell
$python = ".\.venv\Scripts\python.exe"
$work = "runs/dev-note-04-annealing"

& $python -X utf8 -m diy_automl annealing-check --csv data/reference/iris.csv --target target --budget 8 --exhaustive --search-seed 44 --output "$work/iris"
& $python -X utf8 -m diy_automl annealing-check --csv data/reference/wine.csv --target target --budget 32 --max-features 6 --search-seed 44 --output "$work/wine"
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
ahmetozel profile image
Ahmet Özel •

Benchmarking simulated annealing against uniform random search under the exact same evaluation budget and shared starting subset is a refreshing way to test metaheuristics honestly. On Iris with an 8-subset budget, random search reaching the exhaustive optimum in 8 of 10 seeds versus 3 of 10 for annealing shows that cooling schedules need enough search horizon to pay off over simple random exploration.

Fitting the scaler strictly inside each stratified cross-validation fold and preferring fewer columns on ties also keeps the comparison leak-free and directly aligned with reducing expensive data collection.

Collapse
 
masaya_oka profile image
masaya oka • • Edited

Thanks, Ahmet.
Your point about the search budget and cooling schedule prompted me to replay the searches on the same Iris cross-validation scores.
Going from 8 to 12 candidates raised the default annealing schedule’s hit count from 3 to 6 out of 10 seeds.
Random search reached the optimum 8 times at both budgets. At 8 candidates, both cooling settings I tried gave 3 hits.
I’d like to compare cooling schedules at a fixed budget across more data splits.