Source: eclairjs/ml/classification/DecisionTreeClassificationModel.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 PipelineStage = require(EclairJS_Globals.NAMESPACE + '/ml/PipelineStage');
  18. var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
  19. var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');
  20. /**
  21. * @classdesc
  22. * [Decision tree]{@link http://en.wikipedia.org/wiki/Decision_tree_learning} model for classification.
  23. * It supports both binary and multiclass labels, as well as both continuous and categorical
  24. * features.
  25. * @class
  26. * @memberof module:eclairjs/ml/classification
  27. */
  28. var DecisionTreeClassificationModel = function(jvmObject) {
  29. this.logger = Logger.getLogger("ml.classification.DecisionTreeClassificationModel_js");
  30. PipelineStage.call(this, jvmObject);
  31. };
  32. DecisionTreeClassificationModel.prototype = Object.create(PipelineStage.prototype);
  33. DecisionTreeClassificationModel.prototype.constructor = DecisionTreeClassificationModel;
  34. /**
  35. * An immutable unique ID for the object and its derivatives.
  36. * @returns {string}
  37. */
  38. DecisionTreeClassificationModel.prototype.uid = function () {
  39. return this.getJavaObject().uid();
  40. };
  41. /**
  42. *
  43. * @returns {module:eclairjs/ml/tree.Node}
  44. */
  45. DecisionTreeClassificationModel.prototype.rootNode = function () {
  46. return Utils.javaToJs(this.getJavaObject().rootNode());
  47. };
  48. /**
  49. * Returns the number of features the model was trained on. If unknown, returns -1
  50. * @returns {integer}
  51. */
  52. DecisionTreeClassificationModel.prototype.numFeatures = function () {
  53. return this.getJavaObject().numFeatures();
  54. };
  55. /**
  56. * Number of classes (values which the label can take).
  57. * @returns {integer}
  58. */
  59. DecisionTreeClassificationModel.prototype.numClasses = function () {
  60. return this.getJavaObject().numClasses();
  61. };
  62. /**
  63. * @param {module:eclairjs/ml/param.ParamMap} extra
  64. * @returns {module:eclairjs/ml/classification.DecisionTreeClassificationModel}
  65. */
  66. DecisionTreeClassificationModel.prototype.copy = function(extra) {
  67. var extra_uw = Utils.unwrapObject(extra);
  68. var javaObject = this.getJavaObject().copy(extra_uw);
  69. return new DecisionTreeClassificationModel(javaObject);
  70. };
  71. /**
  72. * Validates and transforms the input schema with the provided param map.
  73. * @param {module:eclairjs/sql/types.StructType} schema
  74. * @param {boolean} fitting whether this is in fitting
  75. * @param {module:eclairjs/sql/types.DataType} featuresDataType SQL DataType for FeaturesType.
  76. * E.g., {@link module:eclairjs/sql/types.VectorUDT}for vector features
  77. * @returns {module:eclairjs/sql/types.StructType}
  78. */
  79. DecisionTreeClassificationModel.prototype.validateAndTransformSchema = function (schema, fitting, featuresDataType) {
  80. var schema_uw = Utils.unwrapObject(schema);
  81. var featuresDataType_uw = Utils.unwrapObject(featuresDataType);
  82. var javaObject = this.getJavaObject().validateAndTransformSchema(schema_uw, fitting, featuresDataType_uw);
  83. return Utils.javaToJs(javaObject);
  84. };
  85. /**
  86. * Param for raw prediction (a.k.a. confidence) column name.
  87. * @returns {module:eclairjs/ml/param.Param}
  88. */
  89. DecisionTreeClassificationModel.prototype.rawPredictionCol = function() {
  90. var javaObject = this.getJavaObject().rawPredictionCol();
  91. return Utils.javaToJs(javaObject);
  92. };
  93. /**
  94. * @returns {string}
  95. */
  96. DecisionTreeClassificationModel.prototype.getRawPredictionCol = function() {
  97. return this.getJavaObject().getRawPredictionCol();
  98. };
  99. /**
  100. * Param for label column name.
  101. * @returns {module:eclairjs/ml/param.Param}
  102. */
  103. DecisionTreeClassificationModel.prototype.labelCol = function() {
  104. var javaObject = this.getJavaObject().labelCol();
  105. return Utils.javaToJs(javaObject);
  106. };
  107. /**
  108. * @returns {string}
  109. */
  110. DecisionTreeClassificationModel.prototype.getLabelCol = function() {
  111. return this.getJavaObject().getLabelCol();
  112. };
  113. /**
  114. * Param for features column name.
  115. * @returns {module:eclairjs/ml/param.Param}
  116. */
  117. DecisionTreeClassificationModel.prototype.featuresCol = function() {
  118. var javaObject = this.getJavaObject().featuresCol();
  119. return Utils.javaToJs(javaObject);
  120. };
  121. /**
  122. * @returns {string}
  123. */
  124. DecisionTreeClassificationModel.prototype.getFeaturesCol = function() {
  125. return this.getJavaObject().getFeaturesCol();
  126. };
  127. /**
  128. * Param for prediction column name.
  129. * @returns {module:eclairjs/ml/param.Param}
  130. */
  131. DecisionTreeClassificationModel.prototype.predictionCol = function() {
  132. var javaObject = this.getJavaObject().predictionCol();
  133. return Utils.javaToJs(javaObject);
  134. };
  135. /**
  136. * @returns {string}
  137. */
  138. DecisionTreeClassificationModel.prototype.getPredictionCol = function() {
  139. return this.getJavaObject().getPredictionCol();
  140. };
  141. /**
  142. * @returns {string}
  143. */
  144. DecisionTreeClassificationModel.prototype.toString = function() {
  145. return this.getJavaObject().toString();
  146. };
  147. /**
  148. * @returns {string}
  149. */
  150. DecisionTreeClassificationModel.prototype.toDebugString = function() {
  151. return this.getJavaObject().toDebugString();
  152. };
  153. /**
  154. * @returns {module:eclairjs/ml/util.MLWriter}
  155. */
  156. DecisionTreeClassificationModel.prototype.write = function() {
  157. var javaObject = this.getJavaObject().write();
  158. return Utils.javaToJs(javaObject);
  159. };
  160. //
  161. // static methods
  162. //
  163. /**
  164. * @returns {module:eclairjs/ml/util.MLReader}
  165. * @static
  166. */
  167. DecisionTreeClassificationModel.read = function() {
  168. var javaObject = org.apache.spark.ml.classification.DecisionTreeClassificationModel.read();
  169. return Utils.javaToJs(javaObject);
  170. };
  171. /**
  172. * @param {string} path
  173. * @static
  174. * @returns {module:eclairjs/ml/classification.DecisionTreeClassificationModel}
  175. */
  176. DecisionTreeClassificationModel.load = function(path) {
  177. var javaObject = org.apache.spark.ml.classification.DecisionTreeClassificationModel.load(path);
  178. return new DecisionTreeClassificationModel(javaObject);
  179. };
  180. module.exports = DecisionTreeClassificationModel;
  181. })();