use of org.dmg.pmml.MathContext in project pyramid by cheng-li.
the class MiningModelUtil method createClassification.
public static MiningModel createClassification(List<? extends Model> models, RegressionModel.NormalizationMethod normalizationMethod, boolean hasProbabilityDistribution, Schema schema) {
CategoricalLabel categoricalLabel = (CategoricalLabel) schema.getLabel();
// modified here
if (categoricalLabel.size() != models.size()) {
throw new IllegalArgumentException();
}
if (normalizationMethod != null) {
switch(normalizationMethod) {
case NONE:
case SIMPLEMAX:
case SOFTMAX:
break;
default:
throw new IllegalArgumentException();
}
}
MathContext mathContext = null;
List<RegressionTable> regressionTables = new ArrayList<>();
for (int i = 0; i < categoricalLabel.size(); i++) {
Model model = models.get(i);
MathContext modelMathContext = model.getMathContext();
if (modelMathContext == null) {
modelMathContext = MathContext.DOUBLE;
}
if (mathContext == null) {
mathContext = modelMathContext;
} else {
if (!Objects.equals(mathContext, modelMathContext)) {
throw new IllegalArgumentException();
}
}
Feature feature = MODEL_PREDICTION.apply(model);
RegressionTable regressionTable = RegressionModelUtil.createRegressionTable(Collections.singletonList(feature), Collections.singletonList(1d), null).setTargetCategory(categoricalLabel.getValue(i));
regressionTables.add(regressionTable);
}
RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), regressionTables).setNormalizationMethod(normalizationMethod).setMathContext(ModelUtil.simplifyMathContext(mathContext)).setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(mathContext, categoricalLabel) : null);
List<Model> segmentationModels = new ArrayList<>(models);
segmentationModels.add(regressionModel);
return createModelChain(segmentationModels, schema);
}
use of org.dmg.pmml.MathContext in project drools by kiegroup.
the class KiePMMLUtilTest method getTargetDataType.
@Test
public void getTargetDataType() {
MiningFunction miningFunction = MiningFunction.REGRESSION;
MathContext mathContext = MathContext.DOUBLE;
DataType retrieved = KiePMMLUtil.getTargetDataType(miningFunction, mathContext);
assertEquals(DataType.DOUBLE, retrieved);
mathContext = MathContext.FLOAT;
retrieved = KiePMMLUtil.getTargetDataType(miningFunction, mathContext);
assertEquals(DataType.FLOAT, retrieved);
miningFunction = MiningFunction.CLASSIFICATION;
retrieved = KiePMMLUtil.getTargetDataType(miningFunction, mathContext);
assertEquals(DataType.STRING, retrieved);
miningFunction = MiningFunction.CLUSTERING;
retrieved = KiePMMLUtil.getTargetDataType(miningFunction, mathContext);
assertEquals(DataType.STRING, retrieved);
List<MiningFunction> notMappedMiningFunctions = Arrays.asList(MiningFunction.ASSOCIATION_RULES, MiningFunction.MIXED, MiningFunction.SEQUENCES, MiningFunction.TIME_SERIES);
notMappedMiningFunctions.forEach(minFun -> assertNull(KiePMMLUtil.getTargetDataType(minFun, MathContext.DOUBLE)));
}
Aggregations