@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; }
.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; }
.setLinkFunction(parseLinkFunction(familyLink.asScalar())) .setLinkParameter(parseLinkParameter(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; }