Search in sources :

Example 6 with MININGFUNCTION

use of org.dmg.pmml.MININGFUNCTION 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

MiningFunction (org.dmg.pmml.MiningFunction)6 CategoricalLabel (org.jpmml.converter.CategoricalLabel)5 Label (org.jpmml.converter.Label)3 DataField (org.dmg.pmml.DataField)2 OutputField (org.dmg.pmml.OutputField)2 GeneralRegressionModel (org.dmg.pmml.general_regression.GeneralRegressionModel)2 ArrayList (java.util.ArrayList)1 PredictionModel (org.apache.spark.ml.PredictionModel)1 ClassificationModel (org.apache.spark.ml.classification.ClassificationModel)1 HasLabelCol (org.apache.spark.ml.param.shared.HasLabelCol)1 GeneralizedLinearRegressionModel (org.apache.spark.ml.regression.GeneralizedLinearRegressionModel)1 Field (org.dmg.pmml.Field)1 TreeModel (org.dmg.pmml.tree.TreeModel)1 CategoricalFeature (org.jpmml.converter.CategoricalFeature)1 ContinuousFeature (org.jpmml.converter.ContinuousFeature)1 ContinuousLabel (org.jpmml.converter.ContinuousLabel)1 Feature (org.jpmml.converter.Feature)1 Schema (org.jpmml.converter.Schema)1