/** * Create an instance of {@link GeneralRegressionModel } * */ public GeneralRegressionModel createGeneralRegressionModel() { return new GeneralRegressionModel(); }
/** * Create an instance of {@link GeneralRegressionModel } * */ public GeneralRegressionModel createGeneralRegressionModel() { return new GeneralRegressionModel(); }
@Override public GeneralRegressionModel encodeModel(Schema schema){ RGenericVector earth = getObject(); RDoubleVector coefficients = (RDoubleVector)earth.getValue("coefficients"); Double intercept = coefficients.getValue(0); List<? extends Feature> features = schema.getFeatures(); if(coefficients.size() != (features.size() + 1)){ throw new IllegalArgumentException(); } List<Double> featureCoefficients = (coefficients.getValues()).subList(1, features.size() + 1); GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null) .setLinkFunction(GeneralRegressionModel.LinkFunction.IDENTITY); GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, featureCoefficients, intercept, null); return generalRegressionModel; }
@Override public Model encodeModel(RDoubleVector a0, RExp beta, int column, Schema schema){ Double intercept = a0.getValue(column); List<Double> coefficients = getCoefficients((S4Object)beta, column); GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERAL_LINEAR, MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null) .setDistribution(GeneralRegressionModel.Distribution.NORMAL); GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, schema.getFeatures(), coefficients, intercept, null); return generalRegressionModel; } }
@Override public Model encodeModel(RDoubleVector a0, RExp beta, int column, Schema schema){ Double intercept = a0.getValue(column); List<Double> coefficients = getCoefficients((S4Object)beta, column); GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERAL_LINEAR, MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null) .setDistribution(GeneralRegressionModel.Distribution.POISSON); GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, schema.getFeatures(), coefficients, intercept, null); return generalRegressionModel; } }
GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), null, null, null) .setLinkFunction(GeneralRegressionModel.LinkFunction.LOGIT) .setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));
@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; } List<Feature> features = new ArrayList<>(schema.getFeatures()); List<Double> coefficients = new ArrayList<>(VectorUtil.toList(model.coefficients())); RegressionTableUtil.simplify(this, targetCategory, features, coefficients); 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, features, coefficients, model.intercept(), targetCategory); return generalRegressionModel; }
GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, miningFunction, ModelUtil.createMiningSchema(label), null, null, null) .setDistribution(parseFamily(familyFamily.asScalar())) .setLinkFunction(parseLinkFunction(familyLink.asScalar()))
@Override public GeneralRegressionModel encodeModel(Schema schema){ RGenericVector mvr = getObject(); RDoubleVector coefficients = (RDoubleVector)mvr.getValue("coefficients"); RDoubleVector xMeans = (RDoubleVector)mvr.getValue("Xmeans"); RDoubleVector yMeans = (RDoubleVector)mvr.getValue("Ymeans"); RNumberVector<?> ncomp = (RNumberVector<?>)mvr.getValue("ncomp"); RStringVector rowNames = coefficients.dimnames(0); RStringVector columnNames = coefficients.dimnames(1); RStringVector compNames = coefficients.dimnames(2); int rows = rowNames.size(); int columns = columnNames.size(); int components = compNames.size(); List<? extends Feature> features = schema.getFeatures(); List<Double> featureCoefficients = FortranMatrixUtil.getColumn(coefficients.getValues(), rows, (columns * components), 0 + (ValueUtil.asInt(ncomp.asScalar()) - 1)); Double intercept = yMeans.getValue(0); for(int j = 0; j < rowNames.size(); j++){ intercept -= (featureCoefficients.get(j) * xMeans.getValue(j)); } GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null) .setLinkFunction(GeneralRegressionModel.LinkFunction.IDENTITY); GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, featureCoefficients, intercept, null); return generalRegressionModel; }
@Test public void inspectValueAnnotations(){ PMML pmml = createPMML(); FieldName name = FieldName.create("y"); Target target = new Target() .setField(name) .addTargetValues(createTargetValue("no event"), createTargetValue("event")); Targets targets = new Targets() .addTargets(target); GeneralRegressionModel model = new GeneralRegressionModel() .setTargets(targets); pmml.addModels(model); assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_3_0); PPMatrix ppMatrix = new PPMatrix() .addPPCells(new PPCell(), new PPCell()); model.setPPMatrix(ppMatrix); assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3); target.setField(null); assertVersionRange(pmml, Version.PMML_4_3, Version.PMML_4_3); }