Spark Gradient-boosted trees (GBTs)梯度提升树
梯度提升树(GBT)是决策树的集合。 GBT迭代地训练决策树以便使损失函数最小化。 spark.ml实现支持GBT用于二进制分类和回归,可以使用连续和分类特征。
导入包
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.Dataset
import org.apache.spark.sql.Row
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.Column
import org.apache.spark.sql.DataFrameReader
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.Encoder
import org.apache.spark.sql.DataFrameStatFunctions
import org.apache.spark.sql.functions._ import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.ml.feature.{ IndexToString, StringIndexer, VectorIndexer }
import org.apache.spark.ml.feature.VectorAssembler
import org.apache.spark.ml.Pipeline
import org.apache.spark.ml.regression.{ GBTRegressionModel, GBTRegressor }
import org.apache.spark.ml.evaluation.RegressionEvaluator
import org.apache.spark.ml.tuning.{ ParamGridBuilder, CrossValidator }
导入数据源
val spark = SparkSession.builder().appName("Spark Gradient-boosted tree regression").config("spark.some.config.option", "some-value").getOrCreate() // For implicit conversions like converting RDDs to DataFrames
import spark.implicits._ val dataList: List[(Double, String, Double, Double, String, Double, Double, Double, Double)] = List(
(0, "male", 37, 10, "no", 3, 18, 7, 4),
(0, "female", 27, 4, "no", 4, 14, 6, 4),
(0, "female", 32, 15, "yes", 1, 12, 1, 4),
(0, "male", 57, 15, "yes", 5, 18, 6, 5),
(0, "male", 22, 0.75, "no", 2, 17, 6, 3),
(0, "female", 32, 1.5, "no", 2, 17, 5, 5),
(0, "female", 22, 0.75, "no", 2, 12, 1, 3),
(0, "male", 57, 15, "yes", 2, 14, 4, 4),
(0, "female", 32, 15, "yes", 4, 16, 1, 2),
(0, "male", 22, 1.5, "no", 4, 14, 4, 5),
(0, "male", 37, 15, "yes", 2, 20, 7, 2),
(0, "male", 27, 4, "yes", 4, 18, 6, 4),
(0, "male", 47, 15, "yes", 5, 17, 6, 4),
(0, "female", 22, 1.5, "no", 2, 17, 5, 4),
(0, "female", 27, 4, "no", 4, 14, 5, 4),
(0, "female", 37, 15, "yes", 1, 17, 5, 5),
(0, "female", 37, 15, "yes", 2, 18, 4, 3),
(0, "female", 22, 0.75, "no", 3, 16, 5, 4),
(0, "female", 22, 1.5, "no", 2, 16, 5, 5),
(0, "female", 27, 10, "yes", 2, 14, 1, 5),
(0, "female", 22, 1.5, "no", 2, 16, 5, 5),
(0, "female", 22, 1.5, "no", 2, 16, 5, 5),
(0, "female", 27, 10, "yes", 4, 16, 5, 4),
(0, "female", 32, 10, "yes", 3, 14, 1, 5),
(0, "male", 37, 4, "yes", 2, 20, 6, 4),
(0, "female", 22, 1.5, "no", 2, 18, 5, 5),
(0, "female", 27, 7, "no", 4, 16, 1, 5),
(0, "male", 42, 15, "yes", 5, 20, 6, 4),
(0, "male", 27, 4, "yes", 3, 16, 5, 5),
(0, "female", 27, 4, "yes", 3, 17, 5, 4),
(0, "male", 42, 15, "yes", 4, 20, 6, 3),
(0, "female", 22, 1.5, "no", 3, 16, 5, 5),
(0, "male", 27, 0.417, "no", 4, 17, 6, 4),
(0, "female", 42, 15, "yes", 5, 14, 5, 4),
(0, "male", 32, 4, "yes", 1, 18, 6, 4),
(0, "female", 22, 1.5, "no", 4, 16, 5, 3),
(0, "female", 42, 15, "yes", 3, 12, 1, 4),
(0, "female", 22, 4, "no", 4, 17, 5, 5),
(0, "male", 22, 1.5, "yes", 1, 14, 3, 5),
(0, "female", 22, 0.75, "no", 3, 16, 1, 5),
(0, "male", 32, 10, "yes", 5, 20, 6, 5),
(0, "male", 52, 15, "yes", 5, 18, 6, 3),
(0, "female", 22, 0.417, "no", 5, 14, 1, 4),
(0, "female", 27, 4, "yes", 2, 18, 6, 1),
(0, "female", 32, 7, "yes", 5, 17, 5, 3),
(0, "male", 22, 4, "no", 3, 16, 5, 5),
(0, "female", 27, 7, "yes", 4, 18, 6, 5),
(0, "female", 42, 15, "yes", 2, 18, 5, 4),
(0, "male", 27, 1.5, "yes", 4, 16, 3, 5),
(0, "male", 42, 15, "yes", 2, 20, 6, 4),
(0, "female", 22, 0.75, "no", 5, 14, 3, 5),
(0, "male", 32, 7, "yes", 2, 20, 6, 4),
(0, "male", 27, 4, "yes", 5, 20, 6, 5),
(0, "male", 27, 10, "yes", 4, 20, 6, 4),
(0, "male", 22, 4, "no", 1, 18, 5, 5),
(0, "female", 37, 15, "yes", 4, 14, 3, 1),
(0, "male", 22, 1.5, "yes", 5, 16, 4, 4),
(0, "female", 37, 15, "yes", 4, 17, 1, 5),
(0, "female", 27, 0.75, "no", 4, 17, 5, 4),
(0, "male", 32, 10, "yes", 4, 20, 6, 4),
(0, "female", 47, 15, "yes", 5, 14, 7, 2),
(0, "male", 37, 10, "yes", 3, 20, 6, 4),
(0, "female", 22, 0.75, "no", 2, 16, 5, 5),
(0, "male", 27, 4, "no", 2, 18, 4, 5),
(0, "male", 32, 7, "no", 4, 20, 6, 4),
(0, "male", 42, 15, "yes", 2, 17, 3, 5),
(0, "male", 37, 10, "yes", 4, 20, 6, 4),
(0, "female", 47, 15, "yes", 3, 17, 6, 5),
(0, "female", 22, 1.5, "no", 5, 16, 5, 5),
(0, "female", 27, 1.5, "no", 2, 16, 6, 4),
(0, "female", 27, 4, "no", 3, 17, 5, 5),
(0, "female", 32, 10, "yes", 5, 14, 4, 5),
(0, "female", 22, 0.125, "no", 2, 12, 5, 5),
(0, "male", 47, 15, "yes", 4, 14, 4, 3),
(0, "male", 32, 15, "yes", 1, 14, 5, 5),
(0, "male", 27, 7, "yes", 4, 16, 5, 5),
(0, "female", 22, 1.5, "yes", 3, 16, 5, 5),
(0, "male", 27, 4, "yes", 3, 17, 6, 5),
(0, "female", 22, 1.5, "no", 3, 16, 5, 5),
(0, "male", 57, 15, "yes", 2, 14, 7, 2),
(0, "male", 17.5, 1.5, "yes", 3, 18, 6, 5),
(0, "male", 57, 15, "yes", 4, 20, 6, 5),
(0, "female", 22, 0.75, "no", 2, 16, 3, 4),
(0, "male", 42, 4, "no", 4, 17, 3, 3),
(0, "female", 22, 1.5, "yes", 4, 12, 1, 5),
(0, "female", 22, 0.417, "no", 1, 17, 6, 4),
(0, "female", 32, 15, "yes", 4, 17, 5, 5),
(0, "female", 27, 1.5, "no", 3, 18, 5, 2),
(0, "female", 22, 1.5, "yes", 3, 14, 1, 5),
(0, "female", 37, 15, "yes", 3, 14, 1, 4),
(0, "female", 32, 15, "yes", 4, 14, 3, 4),
(0, "male", 37, 10, "yes", 2, 14, 5, 3),
(0, "male", 37, 10, "yes", 4, 16, 5, 4),
(0, "male", 57, 15, "yes", 5, 20, 5, 3),
(0, "male", 27, 0.417, "no", 1, 16, 3, 4),
(0, "female", 42, 15, "yes", 5, 14, 1, 5),
(0, "male", 57, 15, "yes", 3, 16, 6, 1),
(0, "male", 37, 10, "yes", 1, 16, 6, 4),
(0, "male", 37, 15, "yes", 3, 17, 5, 5),
(0, "male", 37, 15, "yes", 4, 20, 6, 5),
(0, "female", 27, 10, "yes", 5, 14, 1, 5),
(0, "male", 37, 10, "yes", 2, 18, 6, 4),
(0, "female", 22, 0.125, "no", 4, 12, 4, 5),
(0, "male", 57, 15, "yes", 5, 20, 6, 5),
(0, "female", 37, 15, "yes", 4, 18, 6, 4),
(0, "male", 22, 4, "yes", 4, 14, 6, 4),
(0, "male", 27, 7, "yes", 4, 18, 5, 4),
(0, "male", 57, 15, "yes", 4, 20, 5, 4),
(0, "male", 32, 15, "yes", 3, 14, 6, 3),
(0, "female", 22, 1.5, "no", 2, 14, 5, 4),
(0, "female", 32, 7, "yes", 4, 17, 1, 5),
(0, "female", 37, 15, "yes", 4, 17, 6, 5),
(0, "female", 32, 1.5, "no", 5, 18, 5, 5),
(0, "male", 42, 10, "yes", 5, 20, 7, 4),
(0, "female", 27, 7, "no", 3, 16, 5, 4),
(0, "male", 37, 15, "no", 4, 20, 6, 5),
(0, "male", 37, 15, "yes", 4, 14, 3, 2),
(0, "male", 32, 10, "no", 5, 18, 6, 4),
(0, "female", 22, 0.75, "no", 4, 16, 1, 5),
(0, "female", 27, 7, "yes", 4, 12, 2, 4),
(0, "female", 27, 7, "yes", 2, 16, 2, 5),
(0, "female", 42, 15, "yes", 5, 18, 5, 4),
(0, "male", 42, 15, "yes", 4, 17, 5, 3),
(0, "female", 27, 7, "yes", 2, 16, 1, 2),
(0, "female", 22, 1.5, "no", 3, 16, 5, 5),
(0, "male", 37, 15, "yes", 5, 20, 6, 5),
(0, "female", 22, 0.125, "no", 2, 14, 4, 5),
(0, "male", 27, 1.5, "no", 4, 16, 5, 5),
(0, "male", 32, 1.5, "no", 2, 18, 6, 5),
(0, "male", 27, 1.5, "no", 2, 17, 6, 5),
(0, "female", 27, 10, "yes", 4, 16, 1, 3),
(0, "male", 42, 15, "yes", 4, 18, 6, 5),
(0, "female", 27, 1.5, "no", 2, 16, 6, 5),
(0, "male", 27, 4, "no", 2, 18, 6, 3),
(0, "female", 32, 10, "yes", 3, 14, 5, 3),
(0, "female", 32, 15, "yes", 3, 18, 5, 4),
(0, "female", 22, 0.75, "no", 2, 18, 6, 5),
(0, "female", 37, 15, "yes", 2, 16, 1, 4),
(0, "male", 27, 4, "yes", 4, 20, 5, 5),
(0, "male", 27, 4, "no", 1, 20, 5, 4),
(0, "female", 27, 10, "yes", 2, 12, 1, 4),
(0, "female", 32, 15, "yes", 5, 18, 6, 4),
(0, "male", 27, 7, "yes", 5, 12, 5, 3),
(0, "male", 52, 15, "yes", 2, 18, 5, 4),
(0, "male", 27, 4, "no", 3, 20, 6, 3),
(0, "male", 37, 4, "yes", 1, 18, 5, 4),
(0, "male", 27, 4, "yes", 4, 14, 5, 4),
(0, "female", 52, 15, "yes", 5, 12, 1, 3),
(0, "female", 57, 15, "yes", 4, 16, 6, 4),
(0, "male", 27, 7, "yes", 1, 16, 5, 4),
(0, "male", 37, 7, "yes", 4, 20, 6, 3),
(0, "male", 22, 0.75, "no", 2, 14, 4, 3),
(0, "male", 32, 4, "yes", 2, 18, 5, 3),
(0, "male", 37, 15, "yes", 4, 20, 6, 3),
(0, "male", 22, 0.75, "yes", 2, 14, 4, 3),
(0, "male", 42, 15, "yes", 4, 20, 6, 3),
(0, "female", 52, 15, "yes", 5, 17, 1, 1),
(0, "female", 37, 15, "yes", 4, 14, 1, 2),
(0, "male", 27, 7, "yes", 4, 14, 5, 3),
(0, "male", 32, 4, "yes", 2, 16, 5, 5),
(0, "female", 27, 4, "yes", 2, 18, 6, 5),
(0, "female", 27, 4, "yes", 2, 18, 5, 5),
(0, "male", 37, 15, "yes", 5, 18, 6, 5),
(0, "female", 47, 15, "yes", 5, 12, 5, 4),
(0, "female", 32, 10, "yes", 3, 17, 1, 4),
(0, "female", 27, 1.5, "yes", 4, 17, 1, 2),
(0, "female", 57, 15, "yes", 2, 18, 5, 2),
(0, "female", 22, 1.5, "no", 4, 14, 5, 4),
(0, "male", 42, 15, "yes", 3, 14, 3, 4),
(0, "male", 57, 15, "yes", 4, 9, 2, 2),
(0, "male", 57, 15, "yes", 4, 20, 6, 5),
(0, "female", 22, 0.125, "no", 4, 14, 4, 5),
(0, "female", 32, 10, "yes", 4, 14, 1, 5),
(0, "female", 42, 15, "yes", 3, 18, 5, 4),
(0, "female", 27, 1.5, "no", 2, 18, 6, 5),
(0, "male", 32, 0.125, "yes", 2, 18, 5, 2),
(0, "female", 27, 4, "no", 3, 16, 5, 4),
(0, "female", 27, 10, "yes", 2, 16, 1, 4),
(0, "female", 32, 7, "yes", 4, 16, 1, 3),
(0, "female", 37, 15, "yes", 4, 14, 5, 4),
(0, "female", 42, 15, "yes", 5, 17, 6, 2),
(0, "male", 32, 1.5, "yes", 4, 14, 6, 5),
(0, "female", 32, 4, "yes", 3, 17, 5, 3),
(0, "female", 37, 7, "no", 4, 18, 5, 5),
(0, "female", 22, 0.417, "yes", 3, 14, 3, 5),
(0, "female", 27, 7, "yes", 4, 14, 1, 5),
(0, "male", 27, 0.75, "no", 3, 16, 5, 5),
(0, "male", 27, 4, "yes", 2, 20, 5, 5),
(0, "male", 32, 10, "yes", 4, 16, 4, 5),
(0, "male", 32, 15, "yes", 1, 14, 5, 5),
(0, "male", 22, 0.75, "no", 3, 17, 4, 5),
(0, "female", 27, 7, "yes", 4, 17, 1, 4),
(0, "male", 27, 0.417, "yes", 4, 20, 5, 4),
(0, "male", 37, 15, "yes", 4, 20, 5, 4),
(0, "female", 37, 15, "yes", 2, 14, 1, 3),
(0, "male", 22, 4, "yes", 1, 18, 5, 4),
(0, "male", 37, 15, "yes", 4, 17, 5, 3),
(0, "female", 22, 1.5, "no", 2, 14, 4, 5),
(0, "male", 52, 15, "yes", 4, 14, 6, 2),
(0, "female", 22, 1.5, "no", 4, 17, 5, 5),
(0, "male", 32, 4, "yes", 5, 14, 3, 5),
(0, "male", 32, 4, "yes", 2, 14, 3, 5),
(0, "female", 22, 1.5, "no", 3, 16, 6, 5),
(0, "male", 27, 0.75, "no", 2, 18, 3, 3),
(0, "female", 22, 7, "yes", 2, 14, 5, 2),
(0, "female", 27, 0.75, "no", 2, 17, 5, 3),
(0, "female", 37, 15, "yes", 4, 12, 1, 2),
(0, "female", 22, 1.5, "no", 1, 14, 1, 5),
(0, "female", 37, 10, "no", 2, 12, 4, 4),
(0, "female", 37, 15, "yes", 4, 18, 5, 3),
(0, "female", 42, 15, "yes", 3, 12, 3, 3),
(0, "male", 22, 4, "no", 2, 18, 5, 5),
(0, "male", 52, 7, "yes", 2, 20, 6, 2),
(0, "male", 27, 0.75, "no", 2, 17, 5, 5),
(0, "female", 27, 4, "no", 2, 17, 4, 5),
(0, "male", 42, 1.5, "no", 5, 20, 6, 5),
(0, "male", 22, 1.5, "no", 4, 17, 6, 5),
(0, "male", 22, 4, "no", 4, 17, 5, 3),
(0, "female", 22, 4, "yes", 1, 14, 5, 4),
(0, "male", 37, 15, "yes", 5, 20, 4, 5),
(0, "female", 37, 10, "yes", 3, 16, 6, 3),
(0, "male", 42, 15, "yes", 4, 17, 6, 5),
(0, "female", 47, 15, "yes", 4, 17, 5, 5),
(0, "male", 22, 1.5, "no", 4, 16, 5, 4),
(0, "female", 32, 10, "yes", 3, 12, 1, 4),
(0, "female", 22, 7, "yes", 1, 14, 3, 5),
(0, "female", 32, 10, "yes", 4, 17, 5, 4),
(0, "male", 27, 1.5, "yes", 2, 16, 2, 4),
(0, "male", 37, 15, "yes", 4, 14, 5, 5),
(0, "male", 42, 4, "yes", 3, 14, 4, 5),
(0, "female", 37, 15, "yes", 5, 14, 5, 4),
(0, "female", 32, 7, "yes", 4, 17, 5, 5),
(0, "female", 42, 15, "yes", 4, 18, 6, 5),
(0, "male", 27, 4, "no", 4, 18, 6, 4),
(0, "male", 22, 0.75, "no", 4, 18, 6, 5),
(0, "male", 27, 4, "yes", 4, 14, 5, 3),
(0, "female", 22, 0.75, "no", 5, 18, 1, 5),
(0, "female", 52, 15, "yes", 5, 9, 5, 5),
(0, "male", 32, 10, "yes", 3, 14, 5, 5),
(0, "female", 37, 15, "yes", 4, 16, 4, 4),
(0, "male", 32, 7, "yes", 2, 20, 5, 4),
(0, "female", 42, 15, "yes", 3, 18, 1, 4),
(0, "male", 32, 15, "yes", 1, 16, 5, 5),
(0, "male", 27, 4, "yes", 3, 18, 5, 5),
(0, "female", 32, 15, "yes", 4, 12, 3, 4),
(0, "male", 22, 0.75, "yes", 3, 14, 2, 4),
(0, "female", 22, 1.5, "no", 3, 16, 5, 3),
(0, "female", 42, 15, "yes", 4, 14, 3, 5),
(0, "female", 52, 15, "yes", 3, 16, 5, 4),
(0, "male", 37, 15, "yes", 5, 20, 6, 4),
(0, "female", 47, 15, "yes", 4, 12, 2, 3),
(0, "male", 57, 15, "yes", 2, 20, 6, 4),
(0, "male", 32, 7, "yes", 4, 17, 5, 5),
(0, "female", 27, 7, "yes", 4, 17, 1, 4),
(0, "male", 22, 1.5, "no", 1, 18, 6, 5),
(0, "female", 22, 4, "yes", 3, 9, 1, 4),
(0, "female", 22, 1.5, "no", 2, 14, 1, 5),
(0, "male", 42, 15, "yes", 2, 20, 6, 4),
(0, "male", 57, 15, "yes", 4, 9, 2, 4),
(0, "female", 27, 7, "yes", 2, 18, 1, 5),
(0, "female", 22, 4, "yes", 3, 14, 1, 5),
(0, "male", 37, 15, "yes", 4, 14, 5, 3),
(0, "male", 32, 7, "yes", 1, 18, 6, 4),
(0, "female", 22, 1.5, "no", 2, 14, 5, 5),
(0, "female", 22, 1.5, "yes", 3, 12, 1, 3),
(0, "male", 52, 15, "yes", 2, 14, 5, 5),
(0, "female", 37, 15, "yes", 2, 14, 1, 1),
(0, "female", 32, 10, "yes", 2, 14, 5, 5),
(0, "male", 42, 15, "yes", 4, 20, 4, 5),
(0, "female", 27, 4, "yes", 3, 18, 4, 5),
(0, "male", 37, 15, "yes", 4, 20, 6, 5),
(0, "male", 27, 1.5, "no", 3, 18, 5, 5),
(0, "female", 22, 0.125, "no", 2, 16, 6, 3),
(0, "male", 32, 10, "yes", 2, 20, 6, 3),
(0, "female", 27, 4, "no", 4, 18, 5, 4),
(0, "female", 27, 7, "yes", 2, 12, 5, 1),
(0, "male", 32, 4, "yes", 5, 18, 6, 3),
(0, "female", 37, 15, "yes", 2, 17, 5, 5),
(0, "male", 47, 15, "no", 4, 20, 6, 4),
(0, "male", 27, 1.5, "no", 1, 18, 5, 5),
(0, "male", 37, 15, "yes", 4, 20, 6, 4),
(0, "female", 32, 15, "yes", 4, 18, 1, 4),
(0, "female", 32, 7, "yes", 4, 17, 5, 4),
(0, "female", 42, 15, "yes", 3, 14, 1, 3),
(0, "female", 27, 7, "yes", 3, 16, 1, 4),
(0, "male", 27, 1.5, "no", 3, 16, 4, 2),
(0, "male", 22, 1.5, "no", 3, 16, 3, 5),
(0, "male", 27, 4, "yes", 3, 16, 4, 2),
(0, "female", 27, 7, "yes", 3, 12, 1, 2),
(0, "female", 37, 15, "yes", 2, 18, 5, 4),
(0, "female", 37, 7, "yes", 3, 14, 4, 4),
(0, "male", 22, 1.5, "no", 2, 16, 5, 5),
(0, "male", 37, 15, "yes", 5, 20, 5, 4),
(0, "female", 22, 1.5, "no", 4, 16, 5, 3),
(0, "female", 32, 10, "yes", 4, 16, 1, 5),
(0, "male", 27, 4, "no", 2, 17, 5, 3),
(0, "female", 22, 0.417, "no", 4, 14, 5, 5),
(0, "female", 27, 4, "no", 2, 18, 5, 5),
(0, "male", 37, 15, "yes", 4, 18, 5, 3),
(0, "male", 37, 10, "yes", 5, 20, 7, 4),
(0, "female", 27, 7, "yes", 2, 14, 4, 2),
(0, "male", 32, 4, "yes", 2, 16, 5, 5),
(0, "male", 32, 4, "yes", 2, 16, 6, 4),
(0, "male", 22, 1.5, "no", 3, 18, 4, 5),
(0, "female", 22, 4, "yes", 4, 14, 3, 4),
(0, "female", 17.5, 0.75, "no", 2, 18, 5, 4),
(0, "male", 32, 10, "yes", 4, 20, 4, 5),
(0, "female", 32, 0.75, "no", 5, 14, 3, 3),
(0, "male", 37, 15, "yes", 4, 17, 5, 3),
(0, "male", 32, 4, "no", 3, 14, 4, 5),
(0, "female", 27, 1.5, "no", 2, 17, 3, 2),
(0, "female", 22, 7, "yes", 4, 14, 1, 5),
(0, "male", 47, 15, "yes", 5, 14, 6, 5),
(0, "male", 27, 4, "yes", 1, 16, 4, 4),
(0, "female", 37, 15, "yes", 5, 14, 1, 3),
(0, "male", 42, 4, "yes", 4, 18, 5, 5),
(0, "female", 32, 4, "yes", 2, 14, 1, 5),
(0, "male", 52, 15, "yes", 2, 14, 7, 4),
(0, "female", 22, 1.5, "no", 2, 16, 1, 4),
(0, "male", 52, 15, "yes", 4, 12, 2, 4),
(0, "female", 22, 0.417, "no", 3, 17, 1, 5),
(0, "female", 22, 1.5, "no", 2, 16, 5, 5),
(0, "male", 27, 4, "yes", 4, 20, 6, 4),
(0, "female", 32, 15, "yes", 4, 14, 1, 5),
(0, "female", 27, 1.5, "no", 2, 16, 3, 5),
(0, "male", 32, 4, "no", 1, 20, 6, 5),
(0, "male", 37, 15, "yes", 3, 20, 6, 4),
(0, "female", 32, 10, "no", 2, 16, 6, 5),
(0, "female", 32, 10, "yes", 5, 14, 5, 5),
(0, "male", 37, 1.5, "yes", 4, 18, 5, 3),
(0, "male", 32, 1.5, "no", 2, 18, 4, 4),
(0, "female", 32, 10, "yes", 4, 14, 1, 4),
(0, "female", 47, 15, "yes", 4, 18, 5, 4),
(0, "female", 27, 10, "yes", 5, 12, 1, 5),
(0, "male", 27, 4, "yes", 3, 16, 4, 5),
(0, "female", 37, 15, "yes", 4, 12, 4, 2),
(0, "female", 27, 0.75, "no", 4, 16, 5, 5),
(0, "female", 37, 15, "yes", 4, 16, 1, 5),
(0, "female", 32, 15, "yes", 3, 16, 1, 5),
(0, "female", 27, 10, "yes", 2, 16, 1, 5),
(0, "male", 27, 7, "no", 2, 20, 6, 5),
(0, "female", 37, 15, "yes", 2, 14, 1, 3),
(0, "male", 27, 1.5, "yes", 2, 17, 4, 4),
(0, "female", 22, 0.75, "yes", 2, 14, 1, 5),
(0, "male", 22, 4, "yes", 4, 14, 2, 4),
(0, "male", 42, 0.125, "no", 4, 17, 6, 4),
(0, "male", 27, 1.5, "yes", 4, 18, 6, 5),
(0, "male", 27, 7, "yes", 3, 16, 6, 3),
(0, "female", 52, 15, "yes", 4, 14, 1, 3),
(0, "male", 27, 1.5, "no", 5, 20, 5, 2),
(0, "female", 27, 1.5, "no", 2, 16, 5, 5),
(0, "female", 27, 1.5, "no", 3, 17, 5, 5),
(0, "male", 22, 0.125, "no", 5, 16, 4, 4),
(0, "female", 27, 4, "yes", 4, 16, 1, 5),
(0, "female", 27, 4, "yes", 4, 12, 1, 5),
(0, "female", 47, 15, "yes", 2, 14, 5, 5),
(0, "female", 32, 15, "yes", 3, 14, 5, 3),
(0, "male", 42, 7, "yes", 2, 16, 5, 5),
(0, "male", 22, 0.75, "no", 4, 16, 6, 4),
(0, "male", 27, 0.125, "no", 3, 20, 6, 5),
(0, "male", 32, 10, "yes", 3, 20, 6, 5),
(0, "female", 22, 0.417, "no", 5, 14, 4, 5),
(0, "female", 47, 15, "yes", 5, 14, 1, 4),
(0, "female", 32, 10, "yes", 3, 14, 1, 5),
(0, "male", 57, 15, "yes", 4, 17, 5, 5),
(0, "male", 27, 4, "yes", 3, 20, 6, 5),
(0, "female", 32, 7, "yes", 4, 17, 1, 5),
(0, "female", 37, 10, "yes", 4, 16, 1, 5),
(0, "female", 32, 10, "yes", 1, 18, 1, 4),
(0, "female", 22, 4, "no", 3, 14, 1, 4),
(0, "female", 27, 7, "yes", 4, 14, 3, 2),
(0, "male", 57, 15, "yes", 5, 18, 5, 2),
(0, "male", 32, 7, "yes", 2, 18, 5, 5),
(0, "female", 27, 1.5, "no", 4, 17, 1, 3),
(0, "male", 22, 1.5, "no", 4, 14, 5, 5),
(0, "female", 22, 1.5, "yes", 4, 14, 5, 4),
(0, "female", 32, 7, "yes", 3, 16, 1, 5),
(0, "female", 47, 15, "yes", 3, 16, 5, 4),
(0, "female", 22, 0.75, "no", 3, 16, 1, 5),
(0, "female", 22, 1.5, "yes", 2, 14, 5, 5),
(0, "female", 27, 4, "yes", 1, 16, 5, 5),
(0, "male", 52, 15, "yes", 4, 16, 5, 5),
(0, "male", 32, 10, "yes", 4, 20, 6, 5),
(0, "male", 47, 15, "yes", 4, 16, 6, 4),
(0, "female", 27, 7, "yes", 2, 14, 1, 2),
(0, "female", 22, 1.5, "no", 4, 14, 4, 5),
(0, "female", 32, 10, "yes", 2, 16, 5, 4),
(0, "female", 22, 0.75, "no", 2, 16, 5, 4),
(0, "female", 22, 1.5, "no", 2, 16, 5, 5),
(0, "female", 42, 15, "yes", 3, 18, 6, 4),
(0, "female", 27, 7, "yes", 5, 14, 4, 5),
(0, "male", 42, 15, "yes", 4, 16, 4, 4),
(0, "female", 57, 15, "yes", 3, 18, 5, 2),
(0, "male", 42, 15, "yes", 3, 18, 6, 2),
(0, "female", 32, 7, "yes", 2, 14, 1, 2),
(0, "male", 22, 4, "no", 5, 12, 4, 5),
(0, "female", 22, 1.5, "no", 1, 16, 6, 5),
(0, "female", 22, 0.75, "no", 1, 14, 4, 5),
(0, "female", 32, 15, "yes", 4, 12, 1, 5),
(0, "male", 22, 1.5, "no", 2, 18, 5, 3),
(0, "male", 27, 4, "yes", 5, 17, 2, 5),
(0, "female", 27, 4, "yes", 4, 12, 1, 5),
(0, "male", 42, 15, "yes", 5, 18, 5, 4),
(0, "male", 32, 1.5, "no", 2, 20, 7, 3),
(0, "male", 57, 15, "no", 4, 9, 3, 1),
(0, "male", 37, 7, "no", 4, 18, 5, 5),
(0, "male", 52, 15, "yes", 2, 17, 5, 4),
(0, "male", 47, 15, "yes", 4, 17, 6, 5),
(0, "female", 27, 7, "no", 2, 17, 5, 4),
(0, "female", 27, 7, "yes", 4, 14, 5, 5),
(0, "female", 22, 4, "no", 2, 14, 3, 3),
(0, "male", 37, 7, "yes", 2, 20, 6, 5),
(0, "male", 27, 7, "no", 4, 12, 4, 3),
(0, "male", 42, 10, "yes", 4, 18, 6, 4),
(0, "female", 22, 1.5, "no", 3, 14, 1, 5),
(0, "female", 22, 4, "yes", 2, 14, 1, 3),
(0, "female", 57, 15, "no", 4, 20, 6, 5),
(0, "male", 37, 15, "yes", 4, 14, 4, 3),
(0, "female", 27, 7, "yes", 3, 18, 5, 5),
(0, "female", 17.5, 10, "no", 4, 14, 4, 5),
(0, "male", 22, 4, "yes", 4, 16, 5, 5),
(0, "female", 27, 4, "yes", 2, 16, 1, 4),
(0, "female", 37, 15, "yes", 2, 14, 5, 1),
(0, "female", 22, 1.5, "no", 5, 14, 1, 4),
(0, "male", 27, 7, "yes", 2, 20, 5, 4),
(0, "male", 27, 4, "yes", 4, 14, 5, 5),
(0, "male", 22, 0.125, "no", 1, 16, 3, 5),
(0, "female", 27, 7, "yes", 4, 14, 1, 4),
(0, "female", 32, 15, "yes", 5, 16, 5, 3),
(0, "male", 32, 10, "yes", 4, 18, 5, 4),
(0, "female", 32, 15, "yes", 2, 14, 3, 4),
(0, "female", 22, 1.5, "no", 3, 17, 5, 5),
(0, "male", 27, 4, "yes", 4, 17, 4, 4),
(0, "female", 52, 15, "yes", 5, 14, 1, 5),
(0, "female", 27, 7, "yes", 2, 12, 1, 2),
(0, "female", 27, 7, "yes", 3, 12, 1, 4),
(0, "female", 42, 15, "yes", 2, 14, 1, 4),
(0, "female", 42, 15, "yes", 4, 14, 5, 4),
(0, "male", 27, 7, "yes", 4, 14, 3, 3),
(0, "male", 27, 7, "yes", 2, 20, 6, 2),
(0, "female", 42, 15, "yes", 3, 12, 3, 3),
(0, "male", 27, 4, "yes", 3, 16, 3, 5),
(0, "female", 27, 7, "yes", 3, 14, 1, 4),
(0, "female", 22, 1.5, "no", 2, 14, 4, 5),
(0, "female", 27, 4, "yes", 4, 14, 1, 4),
(0, "female", 22, 4, "no", 4, 14, 5, 5),
(0, "female", 22, 1.5, "no", 2, 16, 4, 5),
(0, "male", 47, 15, "no", 4, 14, 5, 4),
(0, "male", 37, 10, "yes", 2, 18, 6, 2),
(0, "male", 37, 15, "yes", 3, 17, 5, 4),
(0, "female", 27, 4, "yes", 2, 16, 1, 4),
(3, "male", 27, 1.5, "no", 3, 18, 4, 4),
(3, "female", 27, 4, "yes", 3, 17, 1, 5),
(7, "male", 37, 15, "yes", 5, 18, 6, 2),
(12, "female", 32, 10, "yes", 3, 17, 5, 2),
(1, "male", 22, 0.125, "no", 4, 16, 5, 5),
(1, "female", 22, 1.5, "yes", 2, 14, 1, 5),
(12, "male", 37, 15, "yes", 4, 14, 5, 2),
(7, "female", 22, 1.5, "no", 2, 14, 3, 4),
(2, "male", 37, 15, "yes", 2, 18, 6, 4),
(3, "female", 32, 15, "yes", 4, 12, 3, 2),
(1, "female", 37, 15, "yes", 4, 14, 4, 2),
(7, "female", 42, 15, "yes", 3, 17, 1, 4),
(12, "female", 42, 15, "yes", 5, 9, 4, 1),
(12, "male", 37, 10, "yes", 2, 20, 6, 2),
(12, "female", 32, 15, "yes", 3, 14, 1, 2),
(3, "male", 27, 4, "no", 1, 18, 6, 5),
(7, "male", 37, 10, "yes", 2, 18, 7, 3),
(7, "female", 27, 4, "no", 3, 17, 5, 5),
(1, "male", 42, 15, "yes", 4, 16, 5, 5),
(1, "female", 47, 15, "yes", 5, 14, 4, 5),
(7, "female", 27, 4, "yes", 3, 18, 5, 4),
(1, "female", 27, 7, "yes", 5, 14, 1, 4),
(12, "male", 27, 1.5, "yes", 3, 17, 5, 4),
(12, "female", 27, 7, "yes", 4, 14, 6, 2),
(3, "female", 42, 15, "yes", 4, 16, 5, 4),
(7, "female", 27, 10, "yes", 4, 12, 7, 3),
(1, "male", 27, 1.5, "no", 2, 18, 5, 2),
(1, "male", 32, 4, "no", 4, 20, 6, 4),
(1, "female", 27, 7, "yes", 3, 14, 1, 3),
(3, "female", 32, 10, "yes", 4, 14, 1, 4),
(3, "male", 27, 4, "yes", 2, 18, 7, 2),
(1, "female", 17.5, 0.75, "no", 5, 14, 4, 5),
(1, "female", 32, 10, "yes", 4, 18, 1, 5),
(7, "female", 32, 7, "yes", 2, 17, 6, 4),
(7, "male", 37, 15, "yes", 2, 20, 6, 4),
(7, "female", 37, 10, "no", 1, 20, 5, 3),
(12, "female", 32, 10, "yes", 2, 16, 5, 5),
(7, "male", 52, 15, "yes", 2, 20, 6, 4),
(7, "female", 42, 15, "yes", 1, 12, 1, 3),
(1, "male", 52, 15, "yes", 2, 20, 6, 3),
(2, "male", 37, 15, "yes", 3, 18, 6, 5),
(12, "female", 22, 4, "no", 3, 12, 3, 4),
(12, "male", 27, 7, "yes", 1, 18, 6, 2),
(1, "male", 27, 4, "yes", 3, 18, 5, 5),
(12, "male", 47, 15, "yes", 4, 17, 6, 5),
(12, "female", 42, 15, "yes", 4, 12, 1, 1),
(7, "male", 27, 4, "no", 3, 14, 3, 4),
(7, "female", 32, 7, "yes", 4, 18, 4, 5),
(1, "male", 32, 0.417, "yes", 3, 12, 3, 4),
(3, "male", 47, 15, "yes", 5, 16, 5, 4),
(12, "male", 37, 15, "yes", 2, 20, 5, 4),
(7, "male", 22, 4, "yes", 2, 17, 6, 4),
(1, "male", 27, 4, "no", 2, 14, 4, 5),
(7, "female", 52, 15, "yes", 5, 16, 1, 3),
(1, "male", 27, 4, "no", 3, 14, 3, 3),
(1, "female", 27, 10, "yes", 4, 16, 1, 4),
(1, "male", 32, 7, "yes", 3, 14, 7, 4),
(7, "male", 32, 7, "yes", 2, 18, 4, 1),
(3, "male", 22, 1.5, "no", 1, 14, 3, 2),
(7, "male", 22, 4, "yes", 3, 18, 6, 4),
(7, "male", 42, 15, "yes", 4, 20, 6, 4),
(2, "female", 57, 15, "yes", 1, 18, 5, 4),
(7, "female", 32, 4, "yes", 3, 18, 5, 2),
(1, "male", 27, 4, "yes", 1, 16, 4, 4),
(7, "male", 32, 7, "yes", 4, 16, 1, 4),
(2, "male", 57, 15, "yes", 1, 17, 4, 4),
(7, "female", 42, 15, "yes", 4, 14, 5, 2),
(7, "male", 37, 10, "yes", 1, 18, 5, 3),
(3, "male", 42, 15, "yes", 3, 17, 6, 1),
(1, "female", 52, 15, "yes", 3, 14, 4, 4),
(2, "female", 27, 7, "yes", 3, 17, 5, 3),
(12, "male", 32, 7, "yes", 2, 12, 4, 2),
(1, "male", 22, 4, "no", 4, 14, 2, 5),
(3, "male", 27, 7, "yes", 3, 18, 6, 4),
(12, "female", 37, 15, "yes", 1, 18, 5, 5),
(7, "female", 32, 15, "yes", 3, 17, 1, 3),
(7, "female", 27, 7, "no", 2, 17, 5, 5),
(1, "female", 32, 7, "yes", 3, 17, 5, 3),
(1, "male", 32, 1.5, "yes", 2, 14, 2, 4),
(12, "female", 42, 15, "yes", 4, 14, 1, 2),
(7, "male", 32, 10, "yes", 3, 14, 5, 4),
(7, "male", 37, 4, "yes", 1, 20, 6, 3),
(1, "female", 27, 4, "yes", 2, 16, 5, 3),
(12, "female", 42, 15, "yes", 3, 14, 4, 3),
(1, "male", 27, 10, "yes", 5, 20, 6, 5),
(12, "male", 37, 10, "yes", 2, 20, 6, 2),
(12, "female", 27, 7, "yes", 1, 14, 3, 3),
(3, "female", 27, 7, "yes", 4, 12, 1, 2),
(3, "male", 32, 10, "yes", 2, 14, 4, 4),
(12, "female", 17.5, 0.75, "yes", 2, 12, 1, 3),
(12, "female", 32, 15, "yes", 3, 18, 5, 4),
(2, "female", 22, 7, "no", 4, 14, 4, 3),
(1, "male", 32, 7, "yes", 4, 20, 6, 5),
(7, "male", 27, 4, "yes", 2, 18, 6, 2),
(1, "female", 22, 1.5, "yes", 5, 14, 5, 3),
(12, "female", 32, 15, "no", 3, 17, 5, 1),
(12, "female", 42, 15, "yes", 2, 12, 1, 2),
(7, "male", 42, 15, "yes", 3, 20, 5, 4),
(12, "male", 32, 10, "no", 2, 18, 4, 2),
(12, "female", 32, 15, "yes", 3, 9, 1, 1),
(7, "male", 57, 15, "yes", 5, 20, 4, 5),
(12, "male", 47, 15, "yes", 4, 20, 6, 4),
(2, "female", 42, 15, "yes", 2, 17, 6, 3),
(12, "male", 37, 15, "yes", 3, 17, 6, 3),
(12, "male", 37, 15, "yes", 5, 17, 5, 2),
(7, "male", 27, 10, "yes", 2, 20, 6, 4),
(2, "male", 37, 15, "yes", 2, 16, 5, 4),
(12, "female", 32, 15, "yes", 1, 14, 5, 2),
(7, "male", 32, 10, "yes", 3, 17, 6, 3),
(2, "male", 37, 15, "yes", 4, 18, 5, 1),
(7, "female", 27, 1.5, "no", 2, 17, 5, 5),
(3, "female", 47, 15, "yes", 2, 17, 5, 2),
(12, "male", 37, 15, "yes", 2, 17, 5, 4),
(12, "female", 27, 4, "no", 2, 14, 5, 5),
(2, "female", 27, 10, "yes", 4, 14, 1, 5),
(1, "female", 22, 4, "yes", 3, 16, 1, 3),
(12, "male", 52, 7, "no", 4, 16, 5, 5),
(2, "female", 27, 4, "yes", 1, 16, 3, 5),
(7, "female", 37, 15, "yes", 2, 17, 6, 4),
(2, "female", 27, 4, "no", 1, 17, 3, 1),
(12, "female", 17.5, 0.75, "yes", 2, 12, 3, 5),
(7, "female", 32, 15, "yes", 5, 18, 5, 4),
(7, "female", 22, 4, "no", 1, 16, 3, 5),
(2, "male", 32, 4, "yes", 4, 18, 6, 4),
(1, "female", 22, 1.5, "yes", 3, 18, 5, 2),
(3, "female", 42, 15, "yes", 2, 17, 5, 4),
(1, "male", 32, 7, "yes", 4, 16, 4, 4),
(12, "male", 37, 15, "no", 3, 14, 6, 2),
(1, "male", 42, 15, "yes", 3, 16, 6, 3),
(1, "male", 27, 4, "yes", 1, 18, 5, 4),
(2, "male", 37, 15, "yes", 4, 20, 7, 3),
(7, "male", 37, 15, "yes", 3, 20, 6, 4),
(3, "male", 22, 1.5, "no", 2, 12, 3, 3),
(3, "male", 32, 4, "yes", 3, 20, 6, 2),
(2, "male", 32, 15, "yes", 5, 20, 6, 5),
(12, "female", 52, 15, "yes", 1, 18, 5, 5),
(12, "male", 47, 15, "no", 1, 18, 6, 5),
(3, "female", 32, 15, "yes", 4, 16, 4, 4),
(7, "female", 32, 15, "yes", 3, 14, 3, 2),
(7, "female", 27, 7, "yes", 4, 16, 1, 2),
(12, "male", 42, 15, "yes", 3, 18, 6, 2),
(7, "female", 42, 15, "yes", 2, 14, 3, 2),
(12, "male", 27, 7, "yes", 2, 17, 5, 4),
(3, "male", 32, 10, "yes", 4, 14, 4, 3),
(7, "male", 47, 15, "yes", 3, 16, 4, 2),
(1, "male", 22, 1.5, "yes", 1, 12, 2, 5),
(7, "female", 32, 10, "yes", 2, 18, 5, 4),
(2, "male", 32, 10, "yes", 2, 17, 6, 5),
(2, "male", 22, 7, "yes", 3, 18, 6, 2),
(1, "female", 32, 15, "yes", 3, 14, 1, 5)) val data = dataList.toDF("affairs", "gender", "age", "yearsmarried", "children", "religiousness", "education", "occupation", "rating")
GBT建模
data.createOrReplaceTempView("data") // 字符类型转换成数值
val labelWhere = "affairs as label"
val genderWhere = "case when gender='female' then 0 else cast(1 as double) end as gender"
val childrenWhere = "case when children='no' then 0 else cast(1 as double) end as children" val dataLabelDF = spark.sql(s"select $labelWhere, $genderWhere,age,yearsmarried,$childrenWhere,religiousness,education,occupation,rating from data") val featuresArray = Array("gender", "age", "yearsmarried", "children", "religiousness", "education", "occupation", "rating") // 字段转换成特征向量
val assembler = new VectorAssembler().setInputCols(featuresArray).setOutputCol("features")
val vecDF: DataFrame = assembler.transform(dataLabelDF)
vecDF.show(10, truncate = false) // 将数据分为训练和测试集(30%进行测试)
val Array(trainingDF, testDF) = vecDF.randomSplit(Array(0.7, 0.3)) // 自动识别分类的特征,并对它们进行索引
// 具有大于5个不同的值的特征被视为连续。
val featureIndexer = new VectorIndexer().setInputCol("features").setOutputCol("indexedFeatures").setMaxCategories(5) // 训练GBT模型
val gbt = new GBTRegressor().setLabelCol("label").setFeaturesCol("indexedFeatures").setImpurity("variance").setLossType("squared").setMaxIter(100).setMinInstancesPerNode(100) // Chain indexer and GBT in a Pipeline.
val pipeline = new Pipeline().setStages(Array(featureIndexer, gbt)) // Train model. This also runs the indexer.
val model = pipeline.fit(trainingDF) // 做出预测
val predictions = model.transform(testDF) // 预测样本展示
predictions.select("prediction", "label", "features").show(20,false) // 选择(预测标签,实际标签),并计算测试误差。
val evaluator = new RegressionEvaluator().setLabelCol("label").setPredictionCol("prediction").setMetricName("rmse")
val rmse = evaluator.evaluate(predictions)
println("Root Mean Squared Error (RMSE) on test data = " + rmse) val gbtModel = model.stages(1).asInstanceOf[GBTRegressionModel]
println("Learned regression GBT model:\n" + gbtModel.toDebugString)
代码执行结果
// 预测样本展示
predictions.select("prediction", "label", "features").show(20,false)
+--------------------+-----+-------------------------------------+
|prediction |label|features |
+--------------------+-----+-------------------------------------+
|0.4101891901517728 |0.0 |[0.0,22.0,0.125,0.0,2.0,14.0,4.0,5.0]|
|-0.1761972212866274 |0.0 |[0.0,22.0,0.125,0.0,4.0,12.0,4.0,5.0]|
|-0.1761972212866274 |0.0 |[0.0,22.0,0.125,0.0,4.0,14.0,4.0,5.0]|
|0.27341988209156776 |0.0 |[0.0,22.0,0.417,1.0,3.0,14.0,3.0,5.0]|
|1.3762204060172503 |0.0 |[0.0,22.0,0.75,0.0,2.0,12.0,1.0,3.0] |
|0.7076853285807452 |0.0 |[0.0,22.0,0.75,0.0,3.0,16.0,5.0,4.0] |
|-0.03713901460785563|0.0 |[0.0,22.0,0.75,0.0,4.0,16.0,1.0,5.0] |
|-0.06232021237014856|0.0 |[0.0,22.0,0.75,0.0,5.0,14.0,3.0,5.0] |
|1.3658576179015465 |0.0 |[0.0,22.0,1.5,0.0,2.0,17.0,5.0,4.0] |
|0.5855203584610474 |0.0 |[0.0,22.0,1.5,0.0,2.0,18.0,5.0,5.0] |
|1.3423069921702913 |0.0 |[0.0,22.0,1.5,0.0,3.0,16.0,5.0,3.0] |
|-0.04277366447290868|0.0 |[0.0,22.0,1.5,0.0,5.0,16.0,5.0,5.0] |
|0.15390822331003562 |0.0 |[0.0,22.0,1.5,1.0,3.0,16.0,5.0,5.0] |
|-0.05759270231176094|0.0 |[0.0,22.0,1.5,1.0,4.0,12.0,1.0,5.0] |
|0.9937700279999649 |0.0 |[0.0,27.0,4.0,0.0,3.0,17.0,5.0,5.0] |
|0.07881499915541987 |0.0 |[0.0,27.0,4.0,0.0,4.0,14.0,5.0,4.0] |
|0.8853324368229462 |0.0 |[0.0,27.0,4.0,1.0,2.0,18.0,5.0,5.0] |
|2.470441722865642 |0.0 |[0.0,27.0,4.0,1.0,2.0,18.0,6.0,1.0] |
|1.8994848597314158 |0.0 |[0.0,27.0,4.0,1.0,3.0,17.0,5.0,4.0] |
|1.2016151328027989 |0.0 |[0.0,27.0,7.0,0.0,3.0,16.0,5.0,4.0] |
+--------------------+-----+-------------------------------------+
only showing top 20 rows // 选择(预测标签,实际标签),并计算测试误差。
val evaluator = new RegressionEvaluator().setLabelCol("label").setPredictionCol("prediction").setMetricName("rmse")
evaluator: org.apache.spark.ml.evaluation.RegressionEvaluator = regEval_ac9cce181927 val rmse = evaluator.evaluate(predictions)
rmse: Double = 3.398154308642416 println("Root Mean Squared Error (RMSE) on test data = " + rmse)
Root Mean Squared Error (RMSE) on test data = 3.398154308642416 val gbtModel = model.stages(1).asInstanceOf[GBTRegressionModel]
gbtModel: org.apache.spark.ml.regression.GBTRegressionModel = GBTRegressionModel (uid=gbtr_fef8e464e0a9) with 100 trees println("Learned regression GBT model:\n" + gbtModel.toDebugString)
Learned regression GBT model:
GBTRegressionModel (uid=gbtr_fef8e464e0a9) with 100 trees
Tree 0 (weight 1.0):
If (feature 7 in {3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.5493827160493827
Else (feature 5 > 16.0)
Predict: 1.4025974025974026
Else (feature 7 not in {3.0,4.0})
Predict: 2.3275862068965516
Tree 1 (weight 0.1):
If (feature 4 in {3.0,4.0})
Predict: -1.2041803848556716
Else (feature 4 not in {3.0,4.0})
If (feature 2 <= 4.0)
Predict: -0.23528687185418157
Else (feature 2 > 4.0)
Predict: 2.122676104681004
Tree 2 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 4 in {3.0,4.0})
Predict: -1.656323757972103
Else (feature 4 not in {3.0,4.0})
Predict: -0.15543767468869207
Else (feature 7 not in {2.0,4.0})
Predict: 1.0278733947646754
Tree 3 (weight 0.1):
If (feature 4 in {3.0,4.0})
Predict: -0.8641507684538178
Else (feature 4 not in {3.0,4.0})
If (feature 2 <= 4.0)
Predict: -0.2273383819199587
Else (feature 2 > 4.0)
Predict: 1.5798596443417063
Tree 4 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 4 in {2.0,3.0})
Predict: -1.236525064691553
Else (feature 4 not in {2.0,3.0})
Predict: 0.012163057801348584
Else (feature 7 not in {2.0,4.0})
Predict: 0.7792547820010268
Tree 5 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.9113096501035378
Else (feature 7 not in {2.0,4.0})
Predict: 0.29094960891340704
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.9943737179675912
Tree 6 (weight 0.1):
If (feature 4 in {3.0,4.0})
Predict: -0.5816029069016012
Else (feature 4 not in {3.0,4.0})
If (feature 2 <= 4.0)
Predict: -0.20084493904163633
Else (feature 2 > 4.0)
Predict: 1.109569351901809
Tree 7 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 4 in {3.0,4.0})
Predict: -1.206216468680912
Else (feature 4 not in {3.0,4.0})
Predict: 0.08655545395654013
Else (feature 7 not in {2.0,3.0})
If (feature 1 <= 27.0)
Predict: -0.20724446825839268
Else (feature 1 > 27.0)
Predict: 1.2660056558164223
Tree 8 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 0 in {1.0})
Predict: -1.0182659703495558
Else (feature 0 not in {1.0})
Predict: 0.024231870307628158
Else (feature 7 not in {2.0,4.0})
Predict: 0.5318939487492129
Tree 9 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 4 in {3.0,4.0})
Predict: -0.9976742554437054
Else (feature 4 not in {3.0,4.0})
Predict: 0.0200794486795141
Else (feature 7 not in {2.0,3.0})
If (feature 1 <= 27.0)
Predict: -0.12395645984936833
Else (feature 1 > 27.0)
Predict: 1.0545881786994915
Tree 10 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 0 in {1.0})
Predict: -0.8521104101261413
Else (feature 0 not in {1.0})
Predict: 4.984317868844511E-4
Else (feature 7 not in {2.0,4.0})
Predict: 0.45849128239680126
Tree 11 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 4 in {3.0,4.0})
Predict: -0.8266429201133548
Else (feature 4 not in {3.0,4.0})
Predict: -0.02631141136282202
Else (feature 7 not in {2.0,3.0})
If (feature 1 <= 27.0)
Predict: -0.062192679809529076
Else (feature 1 > 27.0)
Predict: 0.8790672857730457
Tree 12 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.5817255532116069
Else (feature 7 not in {2.0,4.0})
Predict: 0.22193937162964048
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.5907959823435813
Tree 13 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 0 in {0.0})
Predict: -0.7172113654395978
Else (feature 0 not in {0.0})
Predict: 0.006042105742806256
Else (feature 7 not in {2.0,3.0})
If (feature 4 in {2.0,3.0})
Predict: -0.10106364169472773
Else (feature 4 not in {2.0,3.0})
Predict: 0.7978475987081632
Tree 14 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.43106846024675494
Else (feature 2 > 4.0)
If (feature 0 in {0.0})
Predict: -0.24358569405700833
Else (feature 0 not in {0.0})
Predict: 0.8430302370437416
Tree 15 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 0 in {1.0})
Predict: -0.7548596599426589
Else (feature 0 not in {1.0})
Predict: 0.08592188188354978
Else (feature 7 not in {2.0,4.0})
Predict: 0.3483003891556437
Tree 16 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 4 in {3.0,4.0})
Predict: -0.6305692411738641
Else (feature 4 not in {3.0,4.0})
Predict: -0.03294875487717117
Else (feature 7 not in {2.0,3.0})
If (feature 5 <= 16.0)
Predict: 0.6769789481885423
Else (feature 5 > 16.0)
Predict: -0.09745409631073557
Tree 17 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 17.0)
If (feature 5 <= 14.0)
Predict: -0.08997529948919183
Else (feature 5 > 14.0)
Predict: 0.329830215921939
Else (feature 5 > 17.0)
Predict: -0.7669351353559263
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.4823947721214674
Tree 18 (weight 0.1):
If (feature 2 <= 1.5)
Predict: -0.5555885187209292
Else (feature 2 > 1.5)
If (feature 7 in {2.0,3.0})
Predict: -0.22796338045378814
Else (feature 7 not in {2.0,3.0})
Predict: 0.6263893424099629
Tree 19 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 4 in {1.0,2.0})
Predict: -0.8774721304893098
Else (feature 4 not in {1.0,2.0})
Predict: 0.2508177659024886
Else (feature 7 not in {2.0,4.0})
Predict: 0.3374172716953837
Tree 20 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.6771642657012377
Else (feature 7 not in {2.0,4.0})
Predict: 0.42281474905416766
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.35053210010281294
Tree 21 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 17.0)
If (feature 5 <= 14.0)
Predict: -0.08877452416140048
Else (feature 5 > 14.0)
Predict: 0.2745756432464146
Else (feature 5 > 17.0)
Predict: -0.6587419697090034
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.43241117032884024
Tree 22 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.6185527002758889
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.45411581627673897
Else (feature 6 > 5.0)
Predict: 0.4365068498808643
Tree 23 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.30885690781314273
Else (feature 2 > 4.0)
If (feature 0 in {0.0})
Predict: -0.3023921469776914
Else (feature 0 not in {0.0})
Predict: 0.7430519171140063
Tree 24 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.5879792368509512
Else (feature 7 not in {2.0,4.0})
Predict: 0.37672042118327953
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.29665456956343084
Tree 25 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 5 <= 16.0)
Predict: -0.4358101720832422
Else (feature 5 > 16.0)
Predict: 0.004291841246162318
Else (feature 7 not in {2.0,3.0})
If (feature 4 in {2.0,3.0})
Predict: -0.09212211469331538
Else (feature 4 not in {2.0,3.0})
Predict: 0.5390477982838969
Tree 26 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 17.0)
If (feature 5 <= 14.0)
Predict: -0.002870097057736064
Else (feature 5 > 14.0)
Predict: 0.24176485735488987
Else (feature 5 > 17.0)
Predict: -0.6526018743363831
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.3789197752633368
Tree 27 (weight 0.1):
If (feature 2 <= 1.5)
Predict: -0.40670356052123396
Else (feature 2 > 1.5)
If (feature 5 <= 14.0)
Predict: -0.3423186434168276
Else (feature 5 > 14.0)
If (feature 1 <= 32.0)
Predict: 0.07310002678020948
Else (feature 1 > 32.0)
Predict: 0.6220211186229235
Tree 28 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 2 <= 7.0)
Predict: -0.37077050934682493
Else (feature 2 > 7.0)
Predict: -0.013168403089436417
Else (feature 7 not in {2.0,3.0})
If (feature 4 in {1.0,2.0})
Predict: -0.13649988018105869
Else (feature 4 not in {1.0,2.0})
Predict: 0.5307658578968613
Tree 29 (weight 0.1):
If (feature 5 <= 17.0)
If (feature 2 <= 7.0)
Predict: 0.3743438409942865
Else (feature 2 > 7.0)
Predict: -0.19784197849605942
Else (feature 5 > 17.0)
Predict: -0.26391914047591847
Tree 30 (weight 0.1):
If (feature 2 <= 1.5)
Predict: -0.3542028568716046
Else (feature 2 > 1.5)
If (feature 0 in {0.0})
Predict: -0.20390871143361886
Else (feature 0 not in {0.0})
Predict: 0.41078338397447534
Tree 31 (weight 0.1):
If (feature 7 in {2.0,4.0})
If (feature 4 in {1.0,2.0})
Predict: -0.6976532686788715
Else (feature 4 not in {1.0,2.0})
Predict: 0.305128042791237
Else (feature 7 not in {2.0,4.0})
Predict: 0.19996604836748177
Tree 32 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.5026109921920161
Else (feature 7 not in {2.0,4.0})
Predict: 0.2987696061070014
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.2722787792862316
Tree 33 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.210843945397363
Else (feature 5 > 16.0)
Predict: -0.5101274394699526
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.3566655122216068
Tree 34 (weight 0.1):
If (feature 7 in {2.0,3.0})
If (feature 5 <= 16.0)
Predict: -0.38259410181020964
Else (feature 5 > 16.0)
Predict: 0.014040427378239158
Else (feature 7 not in {2.0,3.0})
If (feature 4 in {2.0,3.0})
Predict: -0.0849154281925315
Else (feature 4 not in {2.0,3.0})
Predict: 0.46724301245027106
Tree 35 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.18214237271776318
Else (feature 5 > 16.0)
Predict: -0.4336716289604328
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.299121819193453
Tree 36 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.46344255624122804
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.3640577311836569
Else (feature 6 > 5.0)
Predict: 0.29888044555378185
Tree 37 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.21827462552678883
Else (feature 2 > 4.0)
If (feature 4 in {1.0,2.0,4.0})
Predict: -0.27188720417988843
Else (feature 4 not in {1.0,2.0,4.0})
Predict: 0.6789439047090412
Tree 38 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.44714482741915457
Else (feature 7 not in {2.0,4.0})
Predict: 0.2834580745796812
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.22803431309861022
Tree 39 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 17.0)
If (feature 5 <= 14.0)
Predict: -0.007567675735672283
Else (feature 5 > 14.0)
Predict: 0.19528462943330932
Else (feature 5 > 17.0)
Predict: -0.4793181468190617
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.2674592141367692
Tree 40 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.4058905159858142
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.3146287783924926
Else (feature 6 > 5.0)
Predict: 0.26675364810481134
Tree 41 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.1962735566727834
Else (feature 2 > 4.0)
If (feature 4 in {1.0,2.0,4.0})
Predict: -0.2198867197911281
Else (feature 4 not in {1.0,2.0,4.0})
Predict: 0.5783627397068297
Tree 42 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.40458335821187674
Else (feature 7 not in {2.0,4.0})
Predict: 0.2500008588513438
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.21153528262965707
Tree 43 (weight 0.1):
If (feature 0 in {0.0})
If (feature 4 in {1.0,2.0})
Predict: -0.5272784668998509
Else (feature 4 not in {1.0,2.0})
Predict: 0.27964029342808727
Else (feature 0 not in {0.0})
Predict: 0.1521276760243921
Tree 44 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.15476481680084098
Else (feature 5 > 16.0)
Predict: -0.404648885656257
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.20041323422811966
Tree 45 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 2 <= 10.0)
Predict: 0.08760703216804985
Else (feature 2 > 10.0)
Predict: -0.4363843462222189
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.26125493904601726
Tree 46 (weight 0.1):
If (feature 3 in {0.0})
Predict: -0.24273871330852773
Else (feature 3 not in {0.0})
If (feature 1 <= 32.0)
Predict: 0.4194956858219603
Else (feature 1 > 32.0)
Predict: -0.2641351223987055
Tree 47 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.1842536884228515
Else (feature 2 > 4.0)
If (feature 0 in {0.0})
Predict: -0.2556437505158
Else (feature 0 not in {0.0})
Predict: 0.5250957711438612
Tree 48 (weight 0.1):
If (feature 5 <= 17.0)
If (feature 2 <= 7.0)
Predict: 0.3097249980758783
Else (feature 2 > 7.0)
Predict: -0.20927194758789183
Else (feature 5 > 17.0)
Predict: -0.17974425051995072
Tree 49 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.4391662932031461
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.14899682915441242
Else (feature 2 > 7.0)
Predict: 0.17135087498922727
Tree 50 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.34595892539052775
Else (feature 7 not in {2.0,4.0})
Predict: 0.18864305733321962
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.2010882111695174
Tree 51 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.37928770492554514
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.14598978080630404
Else (feature 2 > 7.0)
Predict: 0.13789872815456017
Tree 52 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 0 in {0.0})
Predict: -0.3561599449500433
Else (feature 0 not in {0.0})
Predict: 0.13480317862464578
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.20022083229153956
Tree 53 (weight 0.1):
If (feature 7 in {0.0,2.0,3.0})
If (feature 2 <= 7.0)
Predict: -0.3034759538679022
Else (feature 2 > 7.0)
Predict: 0.030832254829924348
Else (feature 7 not in {0.0,2.0,3.0})
If (feature 4 in {2.0,3.0})
Predict: -0.09791161435829351
Else (feature 4 not in {2.0,3.0})
Predict: 0.37430560009039743
Tree 54 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 5 <= 17.0)
If (feature 5 <= 14.0)
Predict: 0.0032991310676856803
Else (feature 5 > 14.0)
Predict: 0.16323825545485057
Else (feature 5 > 17.0)
Predict: -0.3944469633207582
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.20930077591956386
Tree 55 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.3423717432439813
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.2845950114476868
Else (feature 6 > 5.0)
Predict: 0.20229881713282846
Tree 56 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 4 in {0.0,2.0,4.0})
Predict: -0.34473853796161436
Else (feature 4 not in {0.0,2.0,4.0})
Predict: 0.06509817623441427
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.29637410144956194
Tree 57 (weight 0.1):
If (feature 4 in {1.0,3.0})
If (feature 7 in {0.0,2.0,4.0})
Predict: -0.4106960501148285
Else (feature 7 not in {0.0,2.0,4.0})
Predict: 0.3067013100269527
Else (feature 4 not in {1.0,3.0})
Predict: 0.14212125967385864
Tree 58 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 2 <= 4.0)
Predict: 0.14321927963357617
Else (feature 2 > 4.0)
Predict: -0.24134920569281398
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.24427269014743427
Tree 59 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.1614525889780999
Else (feature 2 > 4.0)
If (feature 4 in {1.0,2.0})
Predict: -0.3282296392038987
Else (feature 4 not in {1.0,2.0})
Predict: 0.4000388393084363
Tree 60 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.11970240371799991
Else (feature 5 > 16.0)
Predict: -0.32629555023475065
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.16650169466955037
Tree 61 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 2 <= 10.0)
Predict: 0.0785346253080802
Else (feature 2 > 10.0)
Predict: -0.3597426698174828
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.2043621605717289
Tree 62 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.16092189760093678
Else (feature 2 > 4.0)
If (feature 4 in {1.0,2.0})
Predict: -0.2777794408515309
Else (feature 4 not in {1.0,2.0})
Predict: 0.3648602619594364
Tree 63 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.28929221043435893
Else (feature 7 not in {2.0,4.0})
Predict: 0.16866103762864476
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.159374360780632
Tree 64 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 2 <= 10.0)
Predict: 0.06551610731177633
Else (feature 2 > 10.0)
Predict: -0.3256517139452475
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.1947184133018806
Tree 65 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.3907242793892747
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.14983189044748124
Else (feature 2 > 7.0)
Predict: 0.14238312259616695
Tree 66 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 0 in {0.0})
Predict: -0.3052694134166843
Else (feature 0 not in {0.0})
Predict: 0.1242437441599561
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.16364917831715908
Tree 67 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.3374888895457584
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.13796807928365779
Else (feature 2 > 7.0)
Predict: 0.11799951195954451
Tree 68 (weight 0.1):
If (feature 4 in {2.0,3.0})
If (feature 2 <= 7.0)
Predict: 0.11037446342692632
Else (feature 2 > 7.0)
Predict: -0.3691154257571632
Else (feature 4 not in {2.0,3.0})
If (feature 1 <= 27.0)
Predict: -0.1067359768344909
Else (feature 1 > 27.0)
Predict: 0.3469652449886723
Tree 69 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.09765499691255237
Else (feature 5 > 16.0)
Predict: -0.2815290474503235
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.14906241645292465
Tree 70 (weight 0.1):
If (feature 7 in {0.0,2.0,3.0})
If (feature 5 <= 16.0)
Predict: -0.29299461722232156
Else (feature 5 > 16.0)
Predict: 0.09747540373437305
Else (feature 7 not in {0.0,2.0,3.0})
If (feature 4 in {1.0,2.0})
Predict: -0.10994079878853985
Else (feature 4 not in {1.0,2.0})
Predict: 0.3523743079378049
Tree 71 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 0 in {1.0})
Predict: -0.3422083471951224
Else (feature 0 not in {1.0})
Predict: 0.13300441855841866
Else (feature 2 > 7.0)
Predict: 0.10695163170240178
Tree 72 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.31582473516501897
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.2796042594325624
Else (feature 6 > 5.0)
Predict: 0.16641824158295654
Tree 73 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 2 <= 4.0)
Predict: 0.15145985374076318
Else (feature 2 > 4.0)
Predict: -0.25337987124956984
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.2550491173591116
Tree 74 (weight 0.1):
If (feature 3 in {0.0})
Predict: -0.17047319029247388
Else (feature 3 not in {0.0})
If (feature 1 <= 32.0)
Predict: 0.35333760032570316
Else (feature 1 > 32.0)
Predict: -0.2519783337953501
Tree 75 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 0 in {1.0})
Predict: -0.31803815956744486
Else (feature 0 not in {1.0})
Predict: 0.07062037654003865
Else (feature 2 > 7.0)
Predict: 0.13215020722610155
Tree 76 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.2849060057188383
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.10599732481645478
Else (feature 2 > 7.0)
Predict: 0.10572016578088146
Tree 77 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.29204411697391675
Else (feature 7 not in {2.0,4.0})
Predict: 0.17154183331704606
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.1598642924832302
Tree 78 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 2 <= 4.0)
Predict: 0.15620197855107712
Else (feature 2 > 4.0)
Predict: -0.2358472594212062
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.21805292474450014
Tree 79 (weight 0.1):
If (feature 2 <= 4.0)
Predict: -0.1310122593821202
Else (feature 2 > 4.0)
If (feature 0 in {0.0})
Predict: -0.20525206330385296
Else (feature 0 not in {0.0})
Predict: 0.3988936865730646
Tree 80 (weight 0.1):
If (feature 6 <= 4.0)
Predict: 0.118723210443705
Else (feature 6 > 4.0)
If (feature 2 <= 7.0)
Predict: -0.5009441711869456
Else (feature 2 > 7.0)
Predict: 0.37560154066955664
Tree 81 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 5 <= 16.0)
Predict: 0.1011898275621567
Else (feature 5 > 16.0)
Predict: -0.27541549529142817
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.1403917694564152
Tree 82 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 2 <= 10.0)
Predict: 0.10485592624097106
Else (feature 2 > 10.0)
Predict: -0.3561693608362045
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.1550785478603467
Tree 83 (weight 0.1):
If (feature 6 <= 5.0)
If (feature 7 in {1.0,2.0,3.0})
Predict: -0.29578292364809544
Else (feature 7 not in {1.0,2.0,3.0})
Predict: 0.27307326206821303
Else (feature 6 > 5.0)
Predict: 0.14259778729589817
Tree 84 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 2 <= 10.0)
If (feature 0 in {1.0})
Predict: -0.4968444641407045
Else (feature 0 not in {1.0})
Predict: 0.039833192482040626
Else (feature 2 > 10.0)
Predict: 0.23547722042459557
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.20092157887884146
Tree 85 (weight 0.1):
If (feature 0 in {0.0})
If (feature 4 in {1.0,2.0})
Predict: -0.41927295132296866
Else (feature 4 not in {1.0,2.0})
Predict: 0.27264426276668075
Else (feature 0 not in {0.0})
Predict: 0.09473118321732256
Tree 86 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.2627520575537636
Else (feature 7 not in {2.0,4.0})
Predict: 0.16852637689996566
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.13242206940974757
Tree 87 (weight 0.1):
If (feature 4 in {1.0,3.0,4.0})
If (feature 2 <= 10.0)
Predict: 0.0968195867364572
Else (feature 2 > 10.0)
Predict: -0.33632764976664026
Else (feature 4 not in {1.0,3.0,4.0})
Predict: 0.15026643957145142
Tree 88 (weight 0.1):
If (feature 5 <= 16.0)
If (feature 4 in {1.0,2.0})
Predict: -0.5956659813535735
Else (feature 4 not in {1.0,2.0})
Predict: 0.4529037429667299
Else (feature 5 > 16.0)
Predict: 0.08159901911739971
Tree 89 (weight 0.1):
If (feature 4 in {3.0,4.0})
Predict: -0.12934611014945963
Else (feature 4 not in {3.0,4.0})
If (feature 5 <= 16.0)
Predict: -0.40930103952472296
Else (feature 5 > 16.0)
Predict: 0.6895088054273292
Tree 90 (weight 0.1):
If (feature 5 <= 17.0)
If (feature 2 <= 7.0)
Predict: 0.34370866252824434
Else (feature 2 > 7.0)
Predict: -0.2630177858922842
Else (feature 5 > 17.0)
Predict: -0.17338519514465173
Tree 91 (weight 0.1):
If (feature 5 <= 17.0)
If (feature 4 in {0.0,3.0})
Predict: -0.25104546806534994
Else (feature 4 not in {0.0,3.0})
Predict: 0.2702826069825862
Else (feature 5 > 17.0)
Predict: -0.13870815611572082
Tree 92 (weight 0.1):
If (feature 2 <= 7.0)
If (feature 4 in {0.0,1.0,4.0})
Predict: -0.3031434977322535
Else (feature 4 not in {0.0,1.0,4.0})
Predict: 0.13250771045104892
Else (feature 2 > 7.0)
Predict: 0.10098942121784923
Tree 93 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 0 in {0.0})
Predict: -0.2757474131110731
Else (feature 0 not in {0.0})
Predict: 0.13947524024110314
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.12289122084107594
Tree 94 (weight 0.1):
If (feature 6 <= 4.0)
Predict: 0.11785650049644145
Else (feature 6 > 4.0)
If (feature 2 <= 7.0)
Predict: -0.45759270568822835
Else (feature 2 > 7.0)
Predict: 0.33032979113507405
Tree 95 (weight 0.1):
If (feature 5 <= 17.0)
If (feature 2 <= 7.0)
Predict: 0.305333529673242
Else (feature 2 > 7.0)
Predict: -0.2699559779520363
Else (feature 5 > 17.0)
Predict: -0.12326900427506793
Tree 96 (weight 0.1):
If (feature 4 in {2.0,3.0,4.0})
If (feature 7 in {2.0,4.0})
Predict: -0.2082822352931695
Else (feature 7 not in {2.0,4.0})
Predict: 0.1344687038228447
Else (feature 4 not in {2.0,3.0,4.0})
Predict: 0.10426390938251325
Tree 97 (weight 0.1):
If (feature 7 in {0.0,2.0,3.0})
If (feature 4 in {0.0,3.0,4.0})
Predict: -0.24041237137909066
Else (feature 4 not in {0.0,3.0,4.0})
Predict: 0.10786460999909507
Else (feature 7 not in {0.0,2.0,3.0})
If (feature 4 in {1.0,2.0})
Predict: -0.12345549505611093
Else (feature 4 not in {1.0,2.0})
Predict: 0.3042271274045207
Tree 98 (weight 0.1):
If (feature 7 in {0.0,3.0,4.0})
If (feature 4 in {0.0,2.0,4.0})
Predict: -0.3300305557432017
Else (feature 4 not in {0.0,2.0,4.0})
Predict: 0.11539664128561841
Else (feature 7 not in {0.0,3.0,4.0})
Predict: 0.18650654204571715
Tree 99 (weight 0.1):
If (feature 4 in {1.0,3.0})
If (feature 1 <= 27.0)
Predict: -0.17881873531148437
Else (feature 1 > 27.0)
Predict: 0.021947906677333283
Else (feature 4 not in {1.0,3.0})
Predict: 0.11104367501262459
Spark Gradient-boosted trees (GBTs)梯度提升树的更多相关文章
- 机器学习 之梯度提升树GBDT
目录 1.基本知识点简介 2.梯度提升树GBDT算法 2.1 思路和原理 2.2 梯度代替残差建立CART回归树 1.基本知识点简介 在集成学习的Boosting提升算法中,有两大家族:第一是AdaB ...
- 【Spark机器学习速成宝典】模型篇07梯度提升树【Gradient-Boosted Trees】(Python版)
目录 梯度提升树原理 梯度提升树代码(Spark Python) 梯度提升树原理 待续... 返回目录 梯度提升树代码(Spark Python) 代码里数据:https://pan.baidu.co ...
- 梯度提升树 Gradient Boosting Decision Tree
Adaboost + CART 用 CART 决策树来作为 Adaboost 的基础学习器 但是问题在于,需要把决策树改成能接收带权样本输入的版本.(need: weighted DTree(D, u ...
- 梯度提升树GBD
转自 http://blog.csdn.net/u014568921/article/details/49383379 另外一个很容易理解的文章 :http://www.jianshu.com/p/0 ...
- 梯度提升树(GBDT)原理小结
在集成学习之Adaboost算法原理小结中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boosting De ...
- 笔记︱决策树族——梯度提升树(GBDT)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 本笔记来源于CDA DSC,L2-R语言课程所 ...
- 梯度提升树(GBDT)原理小结(转载)
在集成学习值Adaboost算法原理和代码小结(转载)中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boos ...
- 梯度提升树GBDT算法
转自https://zhuanlan.zhihu.com/p/29802325 本文对Boosting家族中一个重要的算法梯度提升树(Gradient Boosting Decison Tree, 简 ...
- GBDT(梯度提升树) 原理小结
在之前博客中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boosting Decison Tree, 以下简 ...
随机推荐
- set,env,export,source,exec傻傻分不清楚?
https://segmentfault.com/a/1190000013356532
- 使用Github添加标签
Github为我们提供了在页面上进行编辑发行版本的方式,如下图所示: 在Github上为项目打tag可在release页面,选择创建新tag并按下图所示填写即可.删除tag也同理.
- 重写$.ajax方法
/*重写Jquery中的ajax 封装壳*/ $(function () { (function ($) { //首先备份下jquery的ajax方法 var _ajax = $.ajax; //重写 ...
- 9.6 翻译系列:数据注解之Index特性【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/entityframework6/index-attribute-in-code-first.aspx EF ...
- flutter 环境安装以及配置
首先需要下载flutter源码,以下是github地址: https://github.com/flutter/flutter 然后需要安装git环境吧,下图红框可以自行下载安装 接下来需要安装flu ...
- react.js map遍历的问题
React遍历多个Ant Design中的Upload组件时,随意删除任一个Upload出现了bug,依次点击上传图片后,当点击删除时,倒着删除没有问题,从中间和从开头删问题出现了,出现了类似塌方的效 ...
- (4) MySQL中EXPLAIN执行计划分析
一. 执行计划能告诉我们什么? SQL如何使用索引 联接查询的执行顺序 查询扫描的数据函数 二. 执行计划中的内容 SQL执行计划的输出可能为多行,每一行代表对一个数据库对象的操作 1. ID列 ID ...
- [转]深刻理解Python中的元类(metaclass)以及元类实现单例模式
使用元类 深刻理解Python中的元类(metaclass)以及元类实现单例模式 在看一些框架源代码的过程中碰到很多元类的实例,看起来很吃力很晦涩:在看python cookbook中关于元类创建单例 ...
- 不8000就业,不还实习费的AICODER全栈实习二期开始报名
4月17日是个伟大的日子,AICODER全栈实习一期班,正式开始!伙伴们已经撸起袖子加油干了. 二期班开始报名 二期班定于5月17日开班,从二期班开始,实习费用调整如下: 三个月模式实习费,调整为12 ...
- 查看SQL SERVER数据库的连接数
1,查看连接到‘TestDB2’数据库的连接 select * from master.dbo.sysprocesses where dbid = DB_ID('TestDB2') *查询某个数据库用 ...