• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RegressionTable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.dmg.pmml.regression.RegressionTable的典型用法代码示例。如果您正苦于以下问题:Java RegressionTable类的具体用法?Java RegressionTable怎么用?Java RegressionTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RegressionTable类属于org.dmg.pmml.regression包,在下文中一共展示了RegressionTable类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: marshal

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
@Test
public void marshal() throws Exception {
	RegressionModel regressionModel = new RegressionModel()
		.addRegressionTables(new RegressionTable());

	PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary())
		.addModels(regressionModel);

	JAXBContext context = JAXBContextFactory.createContext(new Class[]{org.dmg.pmml.ObjectFactory.class, org.dmg.pmml.regression.ObjectFactory.class}, null);

	Marshaller marshaller = context.createMarshaller();

	ByteArrayOutputStream os = new ByteArrayOutputStream();

	marshaller.marshal(pmml, os);

	String string = os.toString("UTF-8");

	assertTrue(string.contains("<PMML xmlns=\"http://www.dmg.org/PMML-4_3\" version=\"4.3\">"));
	assertTrue(string.contains("<RegressionModel>"));
	assertTrue(string.contains("</RegressionModel>"));
	assertTrue(string.contains("</PMML>"));
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:24,代码来源:MarshallerTest.java


示例2: createBinaryLogisticClassification

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
static
public RegressionModel createBinaryLogisticClassification(MathContext mathContext, List<? extends Feature> features, List<Double> coefficients, Double intercept, RegressionModel.NormalizationMethod normalizationMethod, boolean hasProbabilityDistribution, Schema schema){
	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	if(categoricalLabel.size() != 2){
		throw new IllegalArgumentException();
	} // End if

	if(normalizationMethod != null){

		switch(normalizationMethod){
			case NONE:
			case LOGIT:
			case PROBIT:
			case CLOGLOG:
			case LOGLOG:
			case CAUCHIT:
				break;
			default:
				throw new IllegalArgumentException();
		}
	}

	RegressionTable activeRegressionTable = RegressionModelUtil.createRegressionTable(features, coefficients, intercept)
		.setTargetCategory(categoricalLabel.getValue(1));

	RegressionTable passiveRegressionTable = RegressionModelUtil.createRegressionTable(Collections.<Feature>emptyList(), Collections.<Double>emptyList(), null)
		.setTargetCategory(categoricalLabel.getValue(0));

	RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), null)
		.setNormalizationMethod(normalizationMethod)
		.setMathContext(ModelUtil.simplifyMathContext(mathContext))
		.addRegressionTables(activeRegressionTable, passiveRegressionTable)
		.setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(mathContext, categoricalLabel) : null);

	return regressionModel;
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:38,代码来源:RegressionModelUtil.java


示例3: assertState

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
static
private void assertState(RegressionTable regressionTable, double intercept, boolean hasNumericTerms, boolean hasCategoricalTerms, boolean hasInteractionTerms){
	assertEquals((Double)intercept, (Double)regressionTable.getIntercept());

	assertEquals(hasNumericTerms, regressionTable.hasNumericPredictors());
	assertEquals(hasCategoricalTerms, regressionTable.hasCategoricalPredictors());
	assertEquals(hasInteractionTerms, regressionTable.hasPredictorTerms());
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:9,代码来源:RegressionModelUtilTest.java


示例4: isDefault

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
static
private boolean isDefault(RegressionTable regressionTable){

	if(regressionTable.hasExtensions()){
		return false;
	} // End if

	if(regressionTable.hasNumericPredictors() || regressionTable.hasCategoricalPredictors() || regressionTable.hasPredictorTerms()){
		return false;
	}

	return (regressionTable.getIntercept() == 0d);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:14,代码来源:RegressionModelEvaluator.java


示例5: visit

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
@Override
public VisitorAction visit(RegressionTable regressionTable){

	if(regressionTable.hasCategoricalPredictors()){
		List<CategoricalPredictor> categoricalPredictors = regressionTable.getCategoricalPredictors();

		for(ListIterator<CategoricalPredictor> it = categoricalPredictors.listIterator(); it.hasNext(); ){
			it.set(new RichCategoricalPredictor(it.next()));
		}
	}

	return super.visit(regressionTable);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:14,代码来源:RegressionModelOptimizer.java


示例6: encodeModel

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(TensorFlowEncoder encoder){
	DataField dataField = encoder.createDataField(FieldName.create("_target"), OpType.CATEGORICAL, DataType.INTEGER);

	RegressionModel regressionModel = encodeRegressionModel(encoder);

	List<RegressionTable> regressionTables = regressionModel.getRegressionTables();

	List<String> categories;

	if(regressionTables.size() == 1){
		categories = Arrays.asList("0", "1");

		RegressionTable activeRegressionTable = regressionTables.get(0)
			.setTargetCategory(categories.get(1));

		RegressionTable passiveRegressionTable = new RegressionTable(0)
			.setTargetCategory(categories.get(0));

		regressionModel.addRegressionTables(passiveRegressionTable);
	} else

	if(regressionTables.size() > 2){
		categories = new ArrayList<>();

		for(int i = 0; i < regressionTables.size(); i++){
			RegressionTable regressionTable = regressionTables.get(i);
			String category = String.valueOf(i);

			regressionTable.setTargetCategory(category);

			categories.add(category);
		}
	} else

	{
		throw new IllegalArgumentException();
	}

	dataField = encoder.toCategorical(dataField.getName(), categories);

	CategoricalLabel categoricalLabel = new CategoricalLabel(dataField);

	regressionModel
		.setMiningFunction(MiningFunction.CLASSIFICATION)
		.setNormalizationMethod(RegressionModel.NormalizationMethod.SOFTMAX)
		.setMiningSchema(ModelUtil.createMiningSchema(categoricalLabel))
		.setOutput(ModelUtil.createProbabilityOutput(DataType.FLOAT, categoricalLabel));

	return regressionModel;
}
 
开发者ID:jpmml,项目名称:jpmml-tensorflow,代码行数:52,代码来源:LinearClassifier.java


示例7: createClassification

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
static
public MiningModel createClassification(List<? extends Model> models, RegressionModel.NormalizationMethod normalizationMethod, boolean hasProbabilityDistribution, Schema schema){
	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	if(categoricalLabel.size() < 3 || categoricalLabel.size() != models.size()){
		throw new IllegalArgumentException();
	} // End if

	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;
		} // End if

		if(mathContext == null){
			mathContext = modelMathContext;
		} else

		{
			if(!Objects.equals(mathContext, modelMathContext)){
				throw new IllegalArgumentException();
			}
		}

		Feature feature = MiningModelUtil.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);
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:61,代码来源:MiningModelUtil.java


示例8: encodeModel

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(Schema schema){
	int[] shape = getCoefShape();

	int numberOfClasses = shape[0];
	int numberOfFeatures = shape[1];

	boolean hasProbabilityDistribution = hasProbabilityDistribution();

	List<? extends Number> coef = getCoef();
	List<? extends Number> intercepts = getIntercept();

	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	List<Feature> features = schema.getFeatures();

	if(numberOfClasses == 1){
		ClassifierUtil.checkSize(2, categoricalLabel);

		return RegressionModelUtil.createBinaryLogisticClassification(features, ValueUtil.asDoubles(CMatrixUtil.getRow(coef, numberOfClasses, numberOfFeatures, 0)), ValueUtil.asDouble(intercepts.get(0)), RegressionModel.NormalizationMethod.LOGIT, hasProbabilityDistribution, schema);
	} else

	if(numberOfClasses >= 3){
		ClassifierUtil.checkSize(numberOfClasses, categoricalLabel);

		List<RegressionTable> regressionTables = new ArrayList<>();

		for(int i = 0, rows = categoricalLabel.size(); i < rows; i++){
			RegressionTable regressionTable = RegressionModelUtil.createRegressionTable(features, ValueUtil.asDoubles(CMatrixUtil.getRow(coef, numberOfClasses, numberOfFeatures, i)), ValueUtil.asDouble(intercepts.get(i)))
				.setTargetCategory(categoricalLabel.getValue(i));

			regressionTables.add(regressionTable);
		}

		RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), regressionTables)
			.setNormalizationMethod(RegressionModel.NormalizationMethod.LOGIT)
			.setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel) : null);

		return regressionModel;
	} else

	{
		throw new IllegalArgumentException();
	}
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:46,代码来源:BaseLinearClassifier.java


示例9: createClassification

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
static
public 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();
    } // End if

    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;
        } // End if

        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);
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:62,代码来源:MiningModelUtil.java


示例10: evaluateRegression

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
private <V extends Number> Map<FieldName, ?> evaluateRegression(ValueFactory<V> valueFactory, EvaluationContext context){
	RegressionModel regressionModel = getModel();

	TargetField targetField = getTargetField();

	FieldName targetFieldName = regressionModel.getTargetFieldName();
	if(targetFieldName != null && !Objects.equals(targetField.getName(), targetFieldName)){
		throw new InvalidAttributeException(regressionModel, PMMLAttributes.REGRESSIONMODEL_TARGETFIELDNAME, targetFieldName);
	}

	List<RegressionTable> regressionTables = regressionModel.getRegressionTables();
	if(regressionTables.size() != 1){
		throw new InvalidElementListException(regressionTables);
	}

	RegressionTable regressionTable = regressionTables.get(0);

	Value<V> result = evaluateRegressionTable(valueFactory, regressionTable, context);
	if(result == null){
		return TargetUtil.evaluateRegressionDefault(valueFactory, targetField);
	}

	RegressionModel.NormalizationMethod normalizationMethod = regressionModel.getNormalizationMethod();
	switch(normalizationMethod){
		case NONE:
		case SOFTMAX:
		case LOGIT:
		case EXP:
		case PROBIT:
		case CLOGLOG:
		case LOGLOG:
		case CAUCHIT:
			RegressionModelUtil.normalizeRegressionResult(result, normalizationMethod);
			break;
		case SIMPLEMAX:
			throw new InvalidAttributeException(regressionModel, normalizationMethod);
		default:
			throw new UnsupportedAttributeException(regressionModel, normalizationMethod);
	}

	return TargetUtil.evaluateRegression(targetField, result);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:43,代码来源:RegressionModelEvaluator.java


示例11: createRegressionTable

import org.dmg.pmml.regression.RegressionTable; //导入依赖的package包/类
@Test
public void createRegressionTable(){
	ModelEncoder encoder = new ModelEncoder();

	RegressionTable regressionTable = RegressionModelUtil.createRegressionTable(Collections.<Feature>emptyList(), Collections.<Double>emptyList(), null);

	assertState(regressionTable, 0d, false, false, false);

	Feature feature = SchemaUtil.createConstantFeature(encoder, 3d);

	regressionTable = RegressionModelUtil.createRegressionTable(Collections.singletonList(feature), Collections.singletonList(2d), 1d);

	assertState(regressionTable, 1d + (2d * 3d), false, false, false);

	feature = SchemaUtil.createInteractionFeature(encoder, 3d, FieldName.create("x"), 7d);

	regressionTable = RegressionModelUtil.createRegressionTable(Collections.singletonList(feature), Collections.singletonList(2d), 1d);

	assertState(regressionTable, 1d, true, false, false);

	NumericPredictor numericPredictor = Iterables.getOnlyElement(regressionTable.getNumericPredictors());

	assertEquals(FieldName.create("x"), numericPredictor.getName());
	assertEquals((Double)(2d * 3d * 7d), (Double)numericPredictor.getCoefficient());

	feature = SchemaUtil.createInteractionFeature(encoder, FieldName.create("x1"), 5d, FieldName.create("x2"));

	regressionTable = RegressionModelUtil.createRegressionTable(Collections.singletonList(feature), Collections.singletonList(2d), 1d);

	assertState(regressionTable, 1d, false, false, true);

	PredictorTerm predictorTerm = Iterables.getOnlyElement(regressionTable.getPredictorTerms());

	assertEquals((Double)(2d * 5d), (Double)predictorTerm.getCoefficient());

	List<FieldRef> fieldRefs = predictorTerm.getFieldRefs();

	assertEquals(FieldName.create("x1"), (fieldRefs.get(0)).getField());
	assertEquals(FieldName.create("x2"), (fieldRefs.get(1)).getField());
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:41,代码来源:RegressionModelUtilTest.java



注:本文中的org.dmg.pmml.regression.RegressionTable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Pools类代码示例发布时间:2022-05-23
下一篇:
Java PaymentInfo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap