官术网_书友最值得收藏!

Preparing training data and training a classifier

Next, we separate the training set and test sets. Let's say that 80% of the training set will be used for the training and the other 20% will be used to evaluate the trained model:

val splits = numericDF.randomSplit(Array(0.8, 0.2))
val trainDF = splits(0)
val testDF = splits(1)

Instantiate a decision tree classifier by specifying impurity, max bins, and the max depth of the trees. Additionally, we set the label and feature columns:

val dt = new DecisionTreeClassifier()
.setImpurity("gini")
.setMaxBins(10)
.setMaxDepth(30)
.setLabelCol("label")
.setFeaturesCol("features")

Now that the data and the classifier are ready, we can perform the training:

val dtModel = dt.fit(trainDF)
主站蜘蛛池模板: 伊吾县| 靖宇县| 太白县| 夏津县| 榕江县| 铜川市| 河间市| 方山县| 山阴县| 丰原市| 玉树县| 喀什市| 普兰县| 余庆县| 枞阳县| 南雄市| 嘉鱼县| 兰坪| 云浮市| 宝清县| 墨竹工卡县| 秭归县| 延边| 南乐县| 罗平县| 达拉特旗| 贺兰县| 化德县| 宜阳县| 南部县| 五大连池市| 隆德县| 玉龙| 绥江县| 吉木萨尔县| 太湖县| 新野县| 苍梧县| 荆州市| 柘城县| 井冈山市|