---
title: DTB
description: "DTB提供了ML API接口。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengbds/appAccelFeatures/algorithmaccelf_ml/kunpengbdssparkml_16_0046.html
sourcePath: /source/zh/kunpengbds/appAccelFeatures/algorithmaccelf_ml/kunpengbdssparkml_16_0046.html
indexId: 2725275a12672f24fe047b133d01e23d16105d665001ad50c7a60df538fb853588
---
# DTB

DTB提供了ML API接口。

| 模型接口类别 | 函数接口 |
| --- | --- |
| ML DTB API | def fit(dataset: Dataset[\_]): DecisionTreeBucketModel |
| ML DTB API | def fit(dataset: Dataset[\_], paramMaps: Array[ParamMap]): Seq[DecisionTreeBucketModel] |
| ML DTB API | def fit(dataset: Dataset[\_], paramMap: ParamMap): DecisionTreeBucketModel |
| ML DTB API | def fit(dataset: Dataset[\_], firstParamPair: ParamPair[\_], otherParamPairs: ParamPair[\_]\*): DecisionTreeBucketModel |


#### ML DTB API

- 功能描述
  传入Dataset格式的带标签的样本数据，调用训练接口，输出决策树分箱模型。


- 输入输出

  1. 包名：package org.apache.spark.ml.feature
  2. 类名：DecisionTreeBucketizer
  3. 方法名：fit
  4. 输入：Dataset[_]，文档数据，必须字段如下。| 参数名 | 取值类型 | 缺省值 | 描述 |
| --- | --- | --- | --- |
| labelCol | Double | label | 标签的字段名 |
| featuresCol | Vector | features | 特征的字段名 |


  5. 基于开源版本算法优化的参数。
    1 2 3 4 5 6 7 8 9 10 def setBucketedFeaturesCol (value: String): DecisionTreeBucketizer.this.type def setCheckpointInterval(value: Int): DecisionTreeBucketizer.this.type def setFeaturesCol(value: String): DecisionTreeBucketizer.this.type def setImpurity(value: String): DecisionTreeBucketizer.this.type def setLabelCol(value: String): DecisionTreeBucketizer.this.type def setMaxBins(value: Int): DecisionTreeBucketizer.this.type def setMaxDepth(value: Int): DecisionTreeBucketizer.this.type def setMinInfoGain(value: Double): DecisionTreeBucketizer.this.type def setMinInstancesPerNode(value: Int): DecisionTreeBucketizer.this.type def setSeed(value: Long): DecisionTreeBucketizer.this.type

    最大分箱数（MaxBins）的参数值，支持范围调整为[0, 65535]。

  6. 新增算法参数。| 参数名称 | 取值类型 | 描述 | spark conf参数名 |
| --- | --- | --- | --- |
| numTrainingDataCopies | Int，缺省值为1，必须大于等于1。 | 训练数据的副本数量 | spark.boostkit.ml.rf.numTrainingDataCopies |
| broadcastVariables | Boolean，缺省值为false。 | 是否广播具有较大存储空间的变量 | spark.boostkit.ml.rf.broadcastVariables |
| numPartsPerTrainingDataCopy | Int，必须大于等于0，缺省值为0，0\->不重新分区。 | 单个训练数据副本的分区数 | spark.boostkit.ml.rf.numPartsPerTrainingDataCopy |
| binnedFeaturesDataType | String，取值范围：array或者fasthashmap，缺省值为array。 | 训练样本数据中特征的存储格式 | spark.boostkit.ml.rf.binnedFeaturesDataType |


    “spark.boostkit.ml.rf.numTrainingDataCopies”与cacheNodeIds两个功能，不能同时启用，numTrainingDataCopies如果大于1，cacheNodeIds如是true，cacheNodeIds会被强制修改为false，以warning形式警告用户。

  7. 输出：DecisionTreeBucketModel，决策树分箱模型，模型推理时的输出字段如下。| 参数名 | 取值类型 | 缺省值 | 描述 |
| --- | --- | --- | --- |
| bucketedFeaturesCol | Vector | "bucketedFeatures" | 分箱后特征的字段名 |


- 使用样例
  1 2 3 4 5 6 7 8 9 import org.apache.spark.ml.feature. DecisionTreeBucketizer val dtb = new DecisionTreeBucketizer() .setLabelCol("label") .setFeaturesCol("features") .setMaxBins(maxBins) .setMaxDepth(maxDepth) val pipeline = new Pipeline().setStages(Array(dtb)) val model = pipeline.fit(trainingData) val bucketedData = model.transform(trainingData)

- 样例结果
  1 2 3 4 5 +----------+----------+------------+---------------+ |label | features | bucketedFeatures | +----------+----------+------------+---------------+ | 1|(1000,[0.3,0.2,1.3,30.0,12.0,...|(1000,[0,11,7,3,2,...| +----------+----------+------------+---------------+
