All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hex.genmodel.easy.OneHotEncoderColumnMapper Maven / Gradle / Ivy

There is a newer version: 3.46.0.5
Show newest version
package hex.genmodel.easy;

import hex.genmodel.GenModel;

import java.util.HashMap;
import java.util.Map;

public class OneHotEncoderColumnMapper {

  private final GenModel _m;

  public OneHotEncoderColumnMapper(GenModel m) {
    _m = m;
  }

  public Map create() {
    String[] origNames = _m.getOrigNames();
    String[][] origDomainValues = _m.getOrigDomainValues();
    Map columnMapping = new HashMap<>(origNames.length);
    int pos = 0;
    // non-categorical
    for (int i = 0; i < _m.getOrigNumCols(); i++) {
      if (origDomainValues[i] != null)
        continue;
      columnMapping.put(origNames[i], pos);
      pos++;
    }
    // categorical
    for (int i = 0; i < _m.getOrigNumCols(); i++) {
      String[] domainValues = origDomainValues[i];
      if (domainValues == null)
        continue;
      columnMapping.put(origNames[i], pos);
      pos += domainValues.length + 1;
    }
    return columnMapping;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy