Search in sources :

Example 1 with GeneralizedLinearRegressionModel

use of org.apache.spark.ml.regression.GeneralizedLinearRegressionModel in project jpmml-sparkml by jpmml.

the class GeneralizedLinearRegressionModelConverter method getMiningFunction.

@Override
public MiningFunction getMiningFunction() {
    GeneralizedLinearRegressionModel model = getTransformer();
    String family = model.getFamily();
    switch(family) {
        case "binomial":
            return MiningFunction.CLASSIFICATION;
        default:
            return MiningFunction.REGRESSION;
    }
}
Also used : GeneralizedLinearRegressionModel(org.apache.spark.ml.regression.GeneralizedLinearRegressionModel)

Example 2 with GeneralizedLinearRegressionModel

use of org.apache.spark.ml.regression.GeneralizedLinearRegressionModel in project jpmml-sparkml by jpmml.

the class GeneralizedLinearRegressionModelConverter method encodeModel.

@Override
public GeneralRegressionModel encodeModel(Schema schema) {
    GeneralizedLinearRegressionModel model = getTransformer();
    String targetCategory = null;
    MiningFunction miningFunction = getMiningFunction();
    switch(miningFunction) {
        case CLASSIFICATION:
            CategoricalLabel categoricalLabel = (CategoricalLabel) schema.getLabel();
            if (categoricalLabel.size() != 2) {
                throw new IllegalArgumentException();
            }
            targetCategory = categoricalLabel.getValue(1);
            break;
        default:
            break;
    }
    GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null).setDistribution(parseFamily(model.getFamily())).setLinkFunction(parseLinkFunction(model.getLink())).setLinkParameter(parseLinkParameter(model.getLink()));
    GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, schema.getFeatures(), model.intercept(), VectorUtil.toList(model.coefficients()), targetCategory);
    return generalRegressionModel;
}
Also used : GeneralizedLinearRegressionModel(org.apache.spark.ml.regression.GeneralizedLinearRegressionModel) CategoricalLabel(org.jpmml.converter.CategoricalLabel) GeneralRegressionModel(org.dmg.pmml.general_regression.GeneralRegressionModel) MiningFunction(org.dmg.pmml.MiningFunction)

Aggregations

GeneralizedLinearRegressionModel (org.apache.spark.ml.regression.GeneralizedLinearRegressionModel)2 MiningFunction (org.dmg.pmml.MiningFunction)1 GeneralRegressionModel (org.dmg.pmml.general_regression.GeneralRegressionModel)1 CategoricalLabel (org.jpmml.converter.CategoricalLabel)1