yggdrasil-decision-forests icon indicating copy to clipboard operation
yggdrasil-decision-forests copied to clipboard

Serving predictions with nodejs doesn't support boolean type features, fails with "Error: Non supported feature type [object Object]"

Open CodingDoug opened this issue 1 week ago • 0 comments

I have a model trained with the python SDK that includes BOOLEAN type features. Predictions on this model using javascript/nodejs always fail with:

Error: Non supported feature type [object Object]

For example (feature names replaced with letters):

    let ydf = await YggdrasilDecisionForests()
    const data = await readFile("./df-model.zip")
    const model = await ydf.loadModelFromZipBlob(data)
    console.log(model)
    const example = {
        a: [true],
        b: [1],
        c: [false],
        d: [1],
        e: [0],
        f: [0],
        g: [0],
        h: [10],
        i: [0.0],
        j: [0.0],
        k: ["P"],
    }
    try {
        const preds = model.predict(example)
        console.log(preds)
    }
    catch (e) {
        console.log(e)
    }

Note: The try/catch is required, otherwise ydf will print the entire contents of its JS code as part of the default error handling, which is entirely unacceptable. That should probably be reported as a different issue.

The model is printed like this:

Model {
  internalModel: ClassHandle {},
  createdTFDFSignature: false,
  inputFeatures: [
    { name: 'a', type: 'BOOLEAN', internalIdx: 0, specIdx: 0 },
    { name: 'b', type: 'NUMERICAL', internalIdx: 1, specIdx: 1 },
    { name: 'c', type: 'BOOLEAN', internalIdx: 2, specIdx: 2 },
    { name: 'd', type: 'NUMERICAL', internalIdx: 3, specIdx: 3 },
    {
      name: 'e',
      type: 'NUMERICAL',
      internalIdx: 4,
      specIdx: 4
    },
    {
      name: 'f',
      type: 'NUMERICAL',
      internalIdx: 5,
      specIdx: 5
    },
    {
      name: 'g',
      type: 'NUMERICAL',
      internalIdx: 6,
      specIdx: 6
    },
    { name: 'h', type: 'NUMERICAL', internalIdx: 7, specIdx: 7 },
    {
      name: 'i',
      type: 'NUMERICAL',
      internalIdx: 8,
      specIdx: 8
    },
    {
      name: 'j',
      type: 'NUMERICAL',
      internalIdx: 9,
      specIdx: 9
    },
    {
      name: 'k',
      type: 'CATEGORICAL',
      internalIdx: 10,
      specIdx: 10
    }
  ],
  numericalFeaturesIndex: null,
  booleanFeaturesIndex: null,
  categoricalIntFeaturesIndex: null,
  categoricalSetIntFeaturesIndex: null
}

If I simply remove the boolean features "a" and "c" from the model, I can get predictions with no problem. The mere presence of the boolean features is the issue, as far as I can see.

CodingDoug avatar Jun 30 '24 15:06 CodingDoug