/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function () {
var PipelineStage = require(EclairJS_Globals.NAMESPACE + '/ml/PipelineStage');
var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');
/**
* @classdesc
* [Decision tree]{@link http://en.wikipedia.org/wiki/Decision_tree_learning} learning algorithm
* for classification.
* It supports both binary and multiclass labels, as well as both continuous and categorical
* features.
* @class
* @extends module:eclairjs/ml.PipelineStage
* @memberof module:eclairjs/ml/classification
* @param {string} [uid]
*/
var DecisionTreeClassifier = function(uid) {
this.logger = Logger.getLogger("ml.classification.DecisionTreeClassifier_js");
var jvmObject;
if (uid) {
if (uid instanceof org.apache.spark.ml.classification.DecisionTreeClassifier) {
jvmObject = uid;
} else {
jvmObject = new org.apache.spark.ml.classification.DecisionTreeClassifier(uid);
}
} else {
jvmObject = new org.apache.spark.ml.classification.DecisionTreeClassifier();
}
PipelineStage.call(this, jvmObject);
};
DecisionTreeClassifier.prototype = Object.create(PipelineStage.prototype);
DecisionTreeClassifier.prototype.constructor = DecisionTreeClassifier;
/**
* Accessor for supported impurities: entropy, gini
* @returns {string[]}
*/
DecisionTreeClassifier.prototype.supportedImpurities = function() {
return this.getJavaObject().supportedImpurities();
};
/**
* An immutable unique ID for the object and its derivatives.
* @returns {string}
*/
DecisionTreeClassifier.prototype.uid = function () {
return this.getJavaObject().uid();
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setMaxDepth = function(value) {
var javaObject = this.getJavaObject().setMaxDepth(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setMaxBins = function(value) {
var javaObject = this.getJavaObject().setMaxBins(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setMinInstancesPerNode = function(value) {
var javaObject = this.getJavaObject().setMinInstancesPerNode(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {float} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setMinInfoGain = function(value) {
var javaObject = this.getJavaObject().setMinInfoGain(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setMaxMemoryInMB = function(value) {
var javaObject = this.getJavaObject().setMaxMemoryInMB(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {boolean} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setCacheNodeIds = function(value) {
var javaObject = this.getJavaObject().setCacheNodeIds(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setCheckpointInterval = function(value) {
var javaObject = this.getJavaObject().setCheckpointInterval(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {string} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setImpurity = function(value) {
var javaObject = this.getJavaObject().setImpurity(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {integer} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.setSeed = function(value) {
var javaObject = this.getJavaObject().setSeed(value);
return new DecisionTreeClassifier(javaObject);
};
/**
* @param {module:eclairjs/ml/param.ParamMap} extra
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.prototype.copy = function(extra) {
var extra_uw = Utils.unwrapObject(extra);
var javaObject = this.getJavaObject().copy(extra_uw);
return new DecisionTreeClassifier(javaObject);
};
/**
* Validates and transforms the input schema with the provided param map.
* @param {module:eclairjs/sql/types.StructType} schema
* @param {boolean} fitting whether this is in fitting
* @param {module:eclairjs/sql/types.DataType} featuresDataType SQL DataType for FeaturesType.
* E.g., {@link module:eclairjs/sql/types.VectorUDT}for vector features
* @returns {module:eclairjs/sql/types.StructType}
*/
DecisionTreeClassifier.prototype.validateAndTransformSchema = function (schema, fitting, featuresDataType) {
var schema_uw = Utils.unwrapObject(schema);
var featuresDataType_uw = Utils.unwrapObject(featuresDataType);
var javaObject = this.getJavaObject().validateAndTransformSchema(schema_uw, fitting, featuresDataType_uw);
return Utils.javaToJs(javaObject);
};
/**
* Param for raw prediction (a.k.a. confidence) column name.
* @returns {module:eclairjs/ml/param.Param}
*/
DecisionTreeClassifier.prototype.rawPredictionCol = function() {
var javaObject = this.getJavaObject().rawPredictionCol();
return Utils.javaToJs(javaObject);
};
/**
* @returns {string}
*/
DecisionTreeClassifier.prototype.getRawPredictionCol = function() {
return this.getJavaObject().getRawPredictionCol();
};
/**
* Param for label column name.
* @returns {module:eclairjs/ml/param.Param}
*/
DecisionTreeClassifier.prototype.labelCol = function() {
var javaObject = this.getJavaObject().labelCol();
return Utils.javaToJs(javaObject);
};
/**
* @returns {string}
*/
DecisionTreeClassifier.prototype.getLabelCol = function() {
return this.getJavaObject().getLabelCol();
};
/**
* @param {string} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier} value
*/
DecisionTreeClassifier.prototype.setLabelCol = function(value) {
return Utils.javaToJs(this.getJavaObject().setLabelCol(value));
};
/**
* Param for features column name.
* @returns {module:eclairjs/ml/param.Param}
*/
DecisionTreeClassifier.prototype.featuresCol = function() {
var javaObject = this.getJavaObject().featuresCol();
return Utils.javaToJs(javaObject);
};
/**
* @returns {string}
*/
DecisionTreeClassifier.prototype.getFeaturesCol = function() {
return this.getJavaObject().getFeaturesCol();
};
/**
* @param {string} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier} value
*/
DecisionTreeClassifier.prototype.setFeaturesCol = function(value) {
return Utils.javaToJs(this.getJavaObject().setFeaturesCol(value));
};
/**
* Param for prediction column name.
* @returns {module:eclairjs/ml/param.Param}
*/
DecisionTreeClassifier.prototype.predictionCol = function() {
var javaObject = this.getJavaObject().predictionCol();
return Utils.javaToJs(javaObject);
};
/**
* @returns {string}
*/
DecisionTreeClassifier.prototype.getPredictionCol = function() {
return this.getJavaObject().getPredictionCol();
};
/**
* @param {string} value
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier} value
*/
DecisionTreeClassifier.prototype.setPredictionCol = function(value) {
return Utils.javaToJs(this.getJavaObject().setPredictionCol(value));
};
//
// static methods
//
/**
* @param {string} path
* @returns {module:eclairjs/ml/classification.DecisionTreeClassifier}
*/
DecisionTreeClassifier.load = function(path) {
var javaObject = org.apache.spark.ml.classification.DecisionTreeClassifier.load(path);
return new DecisionTreeClassifier(javaObject);
};
module.exports = DecisionTreeClassifier;
})();