2

I want to declare method in Scala which will have a parameter of type ProbabilisticClassifer from Spark MLlib. Here is its signature from github (https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/classification/ProbabilisticClassifier.scala):

   abstract class ProbabilisticClassificationModel[
    FeaturesType,
    M <: ProbabilisticClassificationModel[FeaturesType, M]]
  extends ClassificationModel[FeaturesType, M] with ProbabilisticClassifierParams

In other words, I want that parameter to be able to predict class probabilities. The purpose is to have an opportunity to pass different probabilistic classifiers (logistic regression, random forest etc.) to this method.

So if I declare this method as

  def method[
    FeaturesType,
    M <: ProbabilisticClassificationModel[FeaturesType, M]
  ] (c: ProbabilisticClassificationModel[FeatureType, M]): M = {...}

... we will be prohibited to call method without template specification. I.e.

 var x = method(RandomF);

won't work. Instead we should write

 var x = method[Vector, RandomForestClassificationModel](RandomF);

Is there any way to define this method to be able to avoid it's every call specification?

zero323
  • 322,348
  • 103
  • 959
  • 935
y.kemaev
  • 91
  • 1
  • 6

0 Answers0