| 213 | } |
| 214 | |
| 215 | void scaleDataUsingTrainingRanges(SimpleSVM::PredictorMap& predictors, const map<String, pair<double, double>>& scaling) |
| 216 | { |
| 217 | // scale each feature dimension to the min-max-range |
| 218 | for (auto pred_it = predictors.begin(); |
| 219 | pred_it != predictors.end(); ++pred_it) |
| 220 | { |
| 221 | if (pred_it->second.empty()) continue; // uninformative predictor |
| 222 | auto val_begin = pred_it->second.begin(); |
| 223 | auto val_end = pred_it->second.end(); |
| 224 | for (; val_begin != val_end; ++val_begin) |
| 225 | { |
| 226 | if (scaling.count(pred_it->first) == 0) |
| 227 | { |
| 228 | //std::cout << "Predictor: '" << pred_it->first << "' not found in scale map because it was uninformative during training." << std::endl; |
| 229 | continue; |
| 230 | } |
| 231 | auto [min, max] = scaling.at(pred_it->first); |
| 232 | double range = max - min; |
| 233 | *val_begin = (*val_begin - min) / range; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | } |
| 238 | |
| 239 | // predict on novel e.g., test data |
| 240 | void SimpleSVM::predict(PredictorMap& predictors, vector<Prediction>& predictions) const |