How to use the ml-matrix.checkMatrix function in ml-matrix

To help you get started, we’ve selected a few ml-matrix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mljs / xgboost / src / loadXGBoost.js View on Github external
train(trainingSet, trainingValues) {
      if (this.checkLabels) {
        /* eslint-disable camelcase */
        this.options.num_class = new Set(trainingValues).size.toString();
        /* eslint-enable camelcase */
      }

      var X = Matrix.checkMatrix(trainingSet);
      var rows = X.rows;
      var cols = X.columns;

      var flattenData = X.to1DArray();
      this.model = create_model(new Uint8Array(Float32Array.from(flattenData).buffer), new Uint8Array(Float32Array.from(trainingValues).buffer), rows, cols);
      var variables = Object.keys(this.options);
      for (var i = 0; i < variables.length; ++i) {
        var variable = variables[i];
        if (variable === 'iterations') {
          continue;
        }

        var value = this.options[variable];
        set_param(this.model, variable, value);
      }
github mljs / xgboost / src / loadXGBoost.js View on Github external
predict(toPredict) {
      var Xtest = Matrix.checkMatrix(toPredict);
      var predictions = new Array(Xtest.rows);
      for (var i = 0; i < Xtest.rows; i++) {
        var current = Xtest.getRow(i);
        predictions[i] = predict_one(this.model, new Uint8Array(Float32Array.from(current).buffer), Xtest.columns);
      }

      return predictions;
    }