0

In spark mllib there are some classifers algorithm like Random Forest, Gradient-Boosted Trees, etc. I try to general before and after process then only change algorithm class for each time.

train(ProbabilisticClassifier<Vector, ? extends Predictor, ? extends Transformer> classifier) {
    ...
    classifier.setLabelCol(myLabel).setFeaturesCol(myFeatures)
    ...
}

which then I can pass

GBTClassifier gbtClassifier = new GBTClassifier()
train(gbtClassifier)

I need to custom paramenters for setLabelCol() and setFeaturesCol(). Predictor abstact class contains these 2 function. That why I have to use:

ProbabilisticClassifier<Vector, ? extends Predictor, ? extends Transformer> classifier

But keyword Predictor show the message "Raw use of parameterized class". Predictor require some castings and also self casting.

I can still run code well but I guess there some potential issue with that.

Predictor class from spark java doc here

Dina
  • 146
  • 2
  • 13
  • 1
    I think you already know the problem, the `Predictor` has 3 type parameters, while you're just using the type itself, so that's a compile warning, and you're right, it MIGHT result in some issues somewhere in your code during runtime. I think you can use some wildcards to fix this `..., ? extends Predictor, ? extends Predictor, ?, ?>, ?>, ...` maybe? I'm not sure, have not done java in a while now :) – AminMal May 25 '22 at 10:14
  • @AminMal Thank you. I read generic and wildcard few days ago. Your solution help me. I guess I should deepen more. – Dina May 26 '22 at 02:00

0 Answers0