Exemple #1
0
  public final String[] coefNames() {
    if (_coefNames != null) return _coefNames; // already computed
    int k = 0;
    final int n = fullN(); // total number of columns to compute
    String[] res = new String[n];
    final Vec[] vecs = _adaptedFrame.vecs();

    // first do all of the expanded categorical names
    for (int i = 0; i < _cats; ++i) {
      for (int j = (_useAllFactorLevels || vecs[i] instanceof InteractionWrappedVec) ? 0 : 1;
          j < vecs[i].domain().length;
          ++j) {
        int jj = getCategoricalId(i, j);
        if (jj < 0) continue;
        res[k++] = _adaptedFrame._names[i] + "." + vecs[i].domain()[j];
      }
      if (_catMissing[i] && getCategoricalId(i, _catModes[i]) >= 0)
        res[k++] = _adaptedFrame._names[i] + ".missing(NA)";
    }
    // now loop over the numerical columns, collecting up any expanded InteractionVec names
    if (_interactions == null) {
      final int nums = n - k;
      System.arraycopy(_adaptedFrame._names, _cats, res, k, nums);
    } else {
      for (int i = _cats; i < _nums; ++i) {
        InteractionWrappedVec v;
        if (vecs[i] instanceof InteractionWrappedVec
            && ((v = (InteractionWrappedVec) vecs[i]).domains()
                != null)) { // in this case, get the categoricalOffset
          for (int j = 0; k < v.domains().length; ++j) {
            if (getCategoricalIdFromInteraction(i, j) < 0) continue;
            res[k++] = _adaptedFrame._names[i] + "." + v.domains()[j];
          }
        } else res[k++] = _adaptedFrame._names[i];
      }
    }
    _coefNames = res;
    return res;
  }
Exemple #2
0
 public final int getCategoricalIdFromInteraction(int cid, int val) {
   InteractionWrappedVec v;
   if ((v = (InteractionWrappedVec) _adaptedFrame.vec(cid)).isCategorical())
     return getCategoricalId(cid, val);
   assert v.domains() != null
       : "No domain levels found for interactions! cid: " + cid + " val: " + val;
   if (val >= _numOffsets[cid + 1]) { // previously unseen interaction (aka new domain level)
     assert _valid
         : "interaction value out of bounds, got "
             + val
             + ", next cat starts at "
             + _numOffsets[cid + 1];
     val = v.mode();
   }
   return val < 0 ? -1 : val + _numOffsets[cid];
 }