0

I made a list of feature list. I want to train a model for each feature list to test which feature list is the best

Finally I want to save the model with the name of the feature list used... How to get this name???

I saw this post: In Scala, how do I get the *name* of an `object` (not an instance of a class)?

But when I do:

featureList1.getClass.getName 

I get:

String = [Ljava.lang.String;

I want to get

java.lang.String = featureList1$

Here is my code:

val featureList1 = ["feature1", "feature2", "feature3"]
val featureList2 = ["feature1", "feature3", "feature4"]
val featureList3 = ["feature5", "feature6", "feature7"]

val liste_featureList_to_test = List(featureList1, featureList2, featureList3)

for (featureList <- liste_featureList_to_test) {
    model_RF = trainModel (train, featureList)
    nomFeaturesList = ?????
    model_RF.write.overwrite.save("models/" + nomFeaturesList)
}

Thank you everyone

Anneso
  • 583
  • 2
  • 11
  • 20

1 Answers1

2

Actually you can do it using reflection but why are you want to save feature lists using object field names? Just specify name for each feature list and save them by this name:

val featureList1 = "featureList1" -> List("feature1", "feature2", "feature3")
val featureList2 = "featureList2" -> List("feature1", "feature3", "feature4")
val featureList3 = "featureList3" -> List("feature5", "feature6", "feature7")

val liste_featureList_to_test = List(featureList1, featureList2, featureList3)

for ((name, featureList) <- liste_featureList_to_test) {
  model_RF = trainModel (train, featureList)
  model_RF.write.overwrite.save("models/" + name)
}
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28