Source: eclairjs/ml/regression/GBTRegressionModel.js

  1. /*
  2. * Copyright 2016 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. (function () {
  17. var PredictionModel = require(EclairJS_Globals.NAMESPACE + '/ml/PredictionModel');
  18. var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
  19. var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');
  20. /**
  21. * @classdesc
  22. *
  23. * [Gradient-Boosted Trees (GBTs)]{@link http://en.wikipedia.org/wiki/Gradient_boosting}
  24. * model for regression.
  25. * It supports both continuous and categorical features.
  26. * @class
  27. * @extends module:eclairjs/ml.PredictionModel
  28. * @memberof module:eclairjs/ml/regression
  29. * @oaram {string} uid
  30. * @param {DecisionTreeRegressionModel[]} trees Decision trees in the ensemble.
  31. * @param {float[]} treeWeights Weights for the decision trees in the ensemble.
  32. */
  33. var GBTRegressionModel = function (uid, trees, treeWeights) {
  34. this.logger = Logger.getLogger("ml_regression_GBTRegressionModel_js");
  35. var jvmObject;
  36. if (uid instanceof org.apache.spark.ml.regression.GBTRegressionModel) {
  37. jvmObject = uid;
  38. } else {
  39. var tress_uw = Utils.unwrapObject(trees);
  40. jvmObject = new org.apache.spark.ml.regression.GBTRegressionModel(uid, tress_uw, treeWeights);
  41. }
  42. PredictionModel.call(this, jvmObject);
  43. };
  44. GBTRegressionModel.prototype = Object.create(PredictionModel.prototype);
  45. GBTRegressionModel.prototype.constructor = GBTRegressionModel;
  46. /**
  47. * An immutable unique ID for the object and its derivatives.
  48. * @returns {string}
  49. */
  50. GBTRegressionModel.prototype.uid = function () {
  51. return this.getJavaObject().uid();
  52. };
  53. /**
  54. * @returns {DecisionTreeModel[]}
  55. */
  56. GBTRegressionModel.prototype.trees = function () {
  57. var javaObject = this.getJavaObject().trees();
  58. return Utils.javaToJs(javaObject);
  59. };
  60. /**
  61. * @returns {float[]}
  62. */
  63. GBTRegressionModel.prototype.treeWeights = function () {
  64. return this.getJavaObject().treeWeights();
  65. };
  66. /**
  67. * @param {module:eclairjs/ml/param.ParamMap} extra
  68. * @returns {module:eclairjs/ml/regression.GBTRegressionModel}
  69. */
  70. GBTRegressionModel.prototype.copy = function (extra) {
  71. var extra_uw = Utils.unwrapObject(extra);
  72. var javaObject = this.getJavaObject().copy(extra_uw);
  73. return new GBTRegressionModel(javaObject);
  74. };
  75. /**
  76. * @returns {string}
  77. */
  78. GBTRegressionModel.prototype.toString = function () {
  79. return this.getJavaObject().toString();
  80. };
  81. /**
  82. * @returns {string}
  83. */
  84. GBTRegressionModel.prototype.toDebugString = function () {
  85. return this.getJavaObject().toDebugString();
  86. };
  87. /**
  88. * @returns {module:eclairjs/ml/util.MLWriter}
  89. */
  90. GBTRegressionModel.prototype.write = function() {
  91. var javaObject = this.getJavaObject().write();
  92. return Utils.javaToJs(javaObject);
  93. };
  94. //
  95. // static methods
  96. //
  97. /**
  98. * @returns {module:eclairjs/ml/util.MLReader}
  99. */
  100. GBTRegressionModel.read = function() {
  101. var javaObject = org.apache.spark.ml.regression.GBTRegressionModel.read();
  102. return Utils.javaToJs(javaObject);
  103. };
  104. /**
  105. * @param {string} path
  106. * @returns {module:eclairjs/ml/regression.GBTRegressionModel}
  107. */
  108. GBTRegressionModel.load = function(path) {
  109. var javaObject = org.apache.spark.ml.regression.GBTRegressionModel.load(path);
  110. return new GBTRegressionModel(javaObject);
  111. };
  112. module.exports = GBTRegressionModel;
  113. })();