Search in sources :

Example 1 with LinearSVCModel

use of org.apache.spark.ml.classification.LinearSVCModel in project jpmml-sparkml by jpmml.

the class LinearSVCModelConverter method encodeModel.

@Override
public MiningModel encodeModel(Schema schema) {
    LinearSVCModel model = getTransformer();
    Transformation transformation = new AbstractTransformation() {

        @Override
        public FieldName getName(FieldName name) {
            return FieldNameUtil.create("threshold", name);
        }

        @Override
        public Expression createExpression(FieldRef fieldRef) {
            return PMMLUtil.createApply(PMMLFunctions.THRESHOLD).addExpressions(fieldRef, PMMLUtil.createConstant(model.getThreshold()));
        }
    };
    Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE);
    Model linearModel = LinearModelUtil.createRegression(this, model.coefficients(), model.intercept(), segmentSchema).setOutput(ModelUtil.createPredictedOutput(FieldName.create("margin"), OpType.CONTINUOUS, DataType.DOUBLE, transformation));
    return MiningModelUtil.createBinaryLogisticClassification(linearModel, 1d, 0d, RegressionModel.NormalizationMethod.NONE, false, schema);
}
Also used : Transformation(org.jpmml.converter.Transformation) AbstractTransformation(org.jpmml.converter.transformations.AbstractTransformation) FieldRef(org.dmg.pmml.FieldRef) AbstractTransformation(org.jpmml.converter.transformations.AbstractTransformation) Schema(org.jpmml.converter.Schema) RegressionModel(org.dmg.pmml.regression.RegressionModel) Model(org.dmg.pmml.Model) LinearSVCModel(org.apache.spark.ml.classification.LinearSVCModel) MiningModel(org.dmg.pmml.mining.MiningModel) FieldName(org.dmg.pmml.FieldName) LinearSVCModel(org.apache.spark.ml.classification.LinearSVCModel)

Aggregations

LinearSVCModel (org.apache.spark.ml.classification.LinearSVCModel)1 FieldName (org.dmg.pmml.FieldName)1 FieldRef (org.dmg.pmml.FieldRef)1 Model (org.dmg.pmml.Model)1 MiningModel (org.dmg.pmml.mining.MiningModel)1 RegressionModel (org.dmg.pmml.regression.RegressionModel)1 Schema (org.jpmml.converter.Schema)1 Transformation (org.jpmml.converter.Transformation)1 AbstractTransformation (org.jpmml.converter.transformations.AbstractTransformation)1