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

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)
主站蜘蛛池模板: 清镇市| 大悟县| 临颍县| 习水县| 甘孜县| 库伦旗| 宜昌市| 包头市| 佛坪县| 淮北市| 花垣县| 和平县| 陵水| 阜新市| 新蔡县| 嵊州市| 台中县| 万山特区| 石阡县| 读书| 昭通市| 大同县| 壤塘县| 阆中市| 聂拉木县| 吉木乃县| 融水| 兴城市| 襄樊市| 太仆寺旗| 阿拉善左旗| 镇江市| 嘉峪关市| 朔州市| 玉龙| 城口县| 南澳县| 休宁县| 岫岩| 延川县| 堆龙德庆县|