Java Code Examples for org.dmg.pmml.MiningFunction#REGRESSION

The following examples show how to use org.dmg.pmml.MiningFunction#REGRESSION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLMConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
static
private MiningFunction getMiningFunction(String family){
	GeneralRegressionModel.Distribution distribution = parseFamily(family);

	switch(distribution){
		case BINOMIAL:
			return MiningFunction.CLASSIFICATION;
		case NORMAL:
		case GAMMA:
		case IGAUSS:
		case POISSON:
			return MiningFunction.REGRESSION;
		default:
			throw new IllegalArgumentException();
	}
}
 
Example 2
Source File: RPartConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private TreeModel encodeRegression(RGenericVector frame, RIntegerVector rowNames, RIntegerVector var, RIntegerVector n, int[][] splitInfo, RNumberVector<?> splits, RIntegerVector csplit, Schema schema){
	RNumberVector<?> yval = frame.getNumericElement("yval");

	ScoreEncoder scoreEncoder = new ScoreEncoder(){

		@Override
		public Node encode(Node node, int offset){
			Number score = yval.getValue(offset);
			Number recordCount = n.getValue(offset);

			node
				.setScore(score)
				.setRecordCount(recordCount);

			return node;
		}
	};

	Node root = encodeNode(True.INSTANCE, 1, rowNames, var, n, splitInfo, splits, csplit, scoreEncoder, schema);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root);

	return configureTreeModel(treeModel);
}
 
Example 3
Source File: GeneralizedLinearRegressionModelConverter.java    From jpmml-sparkml with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public MiningFunction getMiningFunction(){
	GeneralizedLinearRegressionModel model = getTransformer();

	String family = model.getFamily();
	switch(family){
		case "binomial":
			return MiningFunction.CLASSIFICATION;
		default:
			return MiningFunction.REGRESSION;
	}
}
 
Example 4
Source File: BaseEstimator.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public MiningFunction getMiningFunction(){
	String estimatorType = getEstimatorType();

	switch(estimatorType){
		case "classifier":
			return MiningFunction.CLASSIFICATION;
		case "regressor":
			return MiningFunction.REGRESSION;
		default:
			throw new IllegalArgumentException(estimatorType);
	}
}
 
Example 5
Source File: ModelEvaluatorBuilderTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private ModelEvaluatorBuilder createModelEvaluatorBuilder(){
	Node root = new LeafNode(null, False.INSTANCE);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, new MiningSchema(), root);

	PMML pmml = new PMML()
		.addModels(treeModel);

	return new ModelEvaluatorBuilder(pmml, treeModel);
}
 
Example 6
Source File: LinearModelUtil.java    From jpmml-sparkml with GNU Affero General Public License v3.0 4 votes vote down vote up
static
public <C extends ModelConverter<?> & HasRegressionTableOptions> Model createRegression(C converter, Vector coefficients, double intercept, Schema schema){
	ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel();

	String representation = (String)converter.getOption(HasRegressionTableOptions.OPTION_REPRESENTATION, null);

	List<Feature> features = new ArrayList<>(schema.getFeatures());
	List<Double> featureCoefficients = new ArrayList<>(VectorUtil.toList(coefficients));

	RegressionTableUtil.simplify(converter, null, features, featureCoefficients);

	if(representation != null && (GeneralRegressionModel.class.getSimpleName()).equalsIgnoreCase(representation)){
		GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.REGRESSION, MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel), null, null, null);

		GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, featureCoefficients, intercept, null);

		return generalRegressionModel;
	}

	return RegressionModelUtil.createRegression(features, featureCoefficients, intercept, NormalizationMethod.NONE, schema);
}
 
Example 7
Source File: RegressionModelConverter.java    From jpmml-sparkml with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public MiningFunction getMiningFunction(){
	return MiningFunction.REGRESSION;
}
 
Example 8
Source File: Regressor.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public MiningFunction getMiningFunction(){
	return MiningFunction.REGRESSION;
}
 
Example 9
Source File: BinaryTreeConverter.java    From jpmml-r with GNU Affero General Public License v3.0 3 votes vote down vote up
private void encodeResponse(S4Object responses, RExpEncoder encoder){
	RGenericVector variables = responses.getGenericAttribute("variables");
	RBooleanVector is_nominal = responses.getBooleanAttribute("is_nominal");
	RGenericVector levels = responses.getGenericAttribute("levels");

	RStringVector variableNames = variables.names();

	String variableName = variableNames.asScalar();

	DataField dataField;

	Boolean categorical = is_nominal.getElement(variableName);
	if((Boolean.TRUE).equals(categorical)){
		this.miningFunction = MiningFunction.CLASSIFICATION;

		RExp targetVariable = variables.getElement(variableName);

		RStringVector targetVariableClass = RExpUtil.getClassNames(targetVariable);

		RStringVector targetCategories = levels.getStringElement(variableName);

		dataField = encoder.createDataField(FieldName.create(variableName), OpType.CATEGORICAL, RExpUtil.getDataType(targetVariableClass.asScalar()), targetCategories.getValues());
	} else

	if((Boolean.FALSE).equals(categorical)){
		this.miningFunction = MiningFunction.REGRESSION;

		dataField = encoder.createDataField(FieldName.create(variableName), OpType.CONTINUOUS, DataType.DOUBLE);
	} else

	{
		throw new IllegalArgumentException();
	}

	encoder.setLabel(dataField);
}