SPARK-25959 - Difference in featureImportances results on computed vs saved models

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

SPARK-25959 - Difference in featureImportances results on computed vs saved models

Suraj Nayak
Hi Spark Users,

I tried to implement GBT and found that the feature Importance computed while the model was fit is different when the same model was saved into a storage and loaded back. 


I also found that once the persistent model is loaded and saved back again and loaded, the feature importance remains the same. 


Not sure if its bug while storing and reading the model first time or am missing some parameter that need to be set before saving the model (thus model is picking some defaults - causing feature importance to change)


*Below is the test code:*

val testDF = Seq(
(1, 3, 2, 1, 1),
(3, 2, 1, 2, 0),
(2, 2, 1, 1, 0),
(3, 4, 2, 2, 0),
(2, 2, 1, 3, 1)
).toDF("a", "b", "c", "d", "e")

val featureColumns = testDF.columns.filter(_ != "e")
// Assemble the features into a vector
val assembler = new VectorAssembler().setInputCols(featureColumns).setOutputCol("features")
// Transform the data to get the feature data set
val featureDF = assembler.transform(testDF)

// Train a GBT model.
val gbt = new GBTClassifier()


// Write out the model
/* Prints



println("Reading model again")
val gbtload = GBTClassificationModel.load("file:///tmp/test123")






val gbtload2 = GBTClassificationModel.load("file:///tmp/test123_rewrite")

/* prints


Any help is appreciated in making sure the feature importance is maintenaned as is while the model is first stored.