本文整理汇总了Java中org.dmg.pmml.MiningFunction类的典型用法代码示例。如果您正苦于以下问题:Java MiningFunction类的具体用法?Java MiningFunction怎么用?Java MiningFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MiningFunction类属于org.dmg.pmml包,在下文中一共展示了MiningFunction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: validatePMMLVsSchema
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
/**
* Validates that the encoded PMML model received matches expected schema.
*
* @param pmml {@link PMML} encoding of KMeans Clustering
* @param schema expected schema attributes of KMeans Clustering
*/
public static void validatePMMLVsSchema(PMML pmml, InputSchema schema) {
List<Model> models = pmml.getModels();
Preconditions.checkArgument(models.size() == 1,
"Should have exactly one model, but had %s", models.size());
Model model = models.get(0);
Preconditions.checkArgument(model instanceof ClusteringModel);
Preconditions.checkArgument(model.getMiningFunction() == MiningFunction.CLUSTERING);
DataDictionary dictionary = pmml.getDataDictionary();
Preconditions.checkArgument(
schema.getFeatureNames().equals(AppPMMLUtils.getFeatureNames(dictionary)),
"Feature names in schema don't match names in PMML");
MiningSchema miningSchema = model.getMiningSchema();
Preconditions.checkArgument(schema.getFeatureNames().equals(
AppPMMLUtils.getFeatureNames(miningSchema)));
}
开发者ID:oncewang,项目名称:oryx2,代码行数:26,代码来源:KMeansPMMLUtils.java
示例2: encodeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
GBTClassificationModel model = getTransformer();
String lossType = model.getLossType();
switch(lossType){
case "logistic":
break;
default:
throw new IllegalArgumentException("Loss function " + lossType + " is not supported");
}
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, segmentSchema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(segmentSchema.getLabel()))
.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, Doubles.asList(model.treeWeights())))
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbtValue"), OpType.CONTINUOUS, DataType.DOUBLE));
return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, false, schema);
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:23,代码来源:GBTClassificationModelConverter.java
示例3: encodeTreeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
static
public TreeModel encodeTreeModel(org.apache.spark.ml.tree.Node node, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema){
Node root = encodeNode(node, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), miningFunction, schema)
.setPredicate(new True());
TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
String compact = TreeModelOptions.COMPACT;
if(compact != null && Boolean.valueOf(compact)){
Visitor visitor = new TreeModelCompactor();
visitor.applyTo(treeModel);
}
return treeModel;
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:18,代码来源:TreeModelUtil.java
示例4: registerOutputFields
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){
List<OutputField> result = super.registerOutputFields(label, encoder);
MiningFunction miningFunction = getMiningFunction();
switch(miningFunction){
case CLASSIFICATION:
CategoricalLabel categoricalLabel = (CategoricalLabel)label;
result = new ArrayList<>(result);
result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues()));
break;
default:
break;
}
return result;
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:19,代码来源:GeneralizedLinearRegressionModelConverter.java
示例5: encodeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public ClusteringModel encodeModel(Schema schema){
KMeansModel model = getTransformer();
List<Cluster> clusters = new ArrayList<>();
Vector[] clusterCenters = model.clusterCenters();
for(int i = 0; i < clusterCenters.length; i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i))
.setArray(PMMLUtil.createRealArray(VectorUtil.toList(clusterCenters[i])));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
return new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, clusters.size(), ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters);
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:22,代码来源:KMeansModelConverter.java
示例6: encodeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
List<? extends Classifier> estimators = getEstimators();
List<List<Integer>> estimatorsFeatures = getEstimatorsFeatures();
Segmentation.MultipleModelMethod multipleModelMethod = Segmentation.MultipleModelMethod.AVERAGE;
for(Classifier estimator : estimators){
if(!estimator.hasProbabilityDistribution()){
multipleModelMethod = Segmentation.MultipleModelMethod.MAJORITY_VOTE;
break;
}
}
MiningModel miningModel = BaggingUtil.encodeBagging(estimators, estimatorsFeatures, multipleModelMethod, MiningFunction.CLASSIFICATION, schema)
.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)schema.getLabel()));
return miningModel;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:22,代码来源:BaggingClassifier.java
示例7: encodeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
List<? extends Regressor> estimators = getEstimators();
List<? extends Number> estimatorWeights = getEstimatorWeights();
Schema segmentSchema = schema.toAnonymousSchema();
List<Model> models = new ArrayList<>();
for(Regressor estimator : estimators){
Model model = estimator.encodeModel(segmentSchema);
models.add(model);
}
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()))
.setSegmentation(MiningModelUtil.createSegmentation(MultipleModelMethod.WEIGHTED_MEDIAN, models, estimatorWeights));
return miningModel;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:21,代码来源:AdaBoostRegressor.java
示例8: encodeTreeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
static
public <E extends Estimator & HasTree> TreeModel encodeTreeModel(E estimator, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema){
Tree tree = estimator.getTree();
int[] leftChildren = tree.getChildrenLeft();
int[] rightChildren = tree.getChildrenRight();
int[] features = tree.getFeature();
double[] thresholds = tree.getThreshold();
double[] values = tree.getValues();
Node root = new Node()
.setId("1")
.setPredicate(new True());
encodeNode(root, predicateManager, 0, leftChildren, rightChildren, features, thresholds, values, miningFunction, schema);
TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
return treeModel;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:22,代码来源:TreeModelUtil.java
示例9: encodeRegression
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
private MiningModel encodeRegression(RGenericVector ranger, Schema schema){
RGenericVector forest = (RGenericVector)ranger.getValue("forest");
ScoreEncoder scoreEncoder = new ScoreEncoder(){
@Override
public void encode(Node node, Number splitValue, RNumberVector<?> terminalClassCount){
node.setScore(ValueUtil.formatValue(splitValue));
}
};
List<TreeModel> treeModels = encodeForest(forest, MiningFunction.REGRESSION, scoreEncoder, schema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()))
.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.AVERAGE, treeModels));
return miningModel;
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:19,代码来源:RangerConverter.java
示例10: encodeForest
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
private List<TreeModel> encodeForest(RGenericVector forest, MiningFunction miningFunction, ScoreEncoder scoreEncoder, Schema schema){
RNumberVector<?> numTrees = (RNumberVector<?>)forest.getValue("num.trees");
RGenericVector childNodeIDs = (RGenericVector)forest.getValue("child.nodeIDs");
RGenericVector splitVarIDs = (RGenericVector)forest.getValue("split.varIDs");
RGenericVector splitValues = (RGenericVector)forest.getValue("split.values");
RGenericVector terminalClassCounts = (RGenericVector)forest.getValue("terminal.class.counts", true);
Schema segmentSchema = schema.toAnonymousSchema();
List<TreeModel> treeModels = new ArrayList<>();
for(int i = 0; i < ValueUtil.asInt(numTrees.asScalar()); i++){
TreeModel treeModel = encodeTreeModel(miningFunction, scoreEncoder, (RGenericVector)childNodeIDs.getValue(i), (RNumberVector<?>)splitVarIDs.getValue(i), (RNumberVector<?>)splitValues.getValue(i), (terminalClassCounts != null ? (RGenericVector)terminalClassCounts.getValue(i) : null), segmentSchema);
treeModels.add(treeModel);
}
return treeModels;
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:20,代码来源:RangerConverter.java
示例11: encodeSchema
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public void encodeSchema(RExpEncoder encoder){
RGenericVector glm = getObject();
RGenericVector family = (RGenericVector)glm.getValue("family");
RGenericVector model = (RGenericVector)glm.getValue("model");
RStringVector familyFamily = (RStringVector)family.getValue("family");
super.encodeSchema(encoder);
MiningFunction miningFunction = getMiningFunction(familyFamily.asScalar());
switch(miningFunction){
case CLASSIFICATION:
Label label = encoder.getLabel();
RIntegerVector variable = (RIntegerVector)model.getValue((label.getName()).getValue());
DataField dataField = (DataField)encoder.toCategorical(label.getName(), RExpUtil.getFactorLevels(variable));
encoder.setLabel(dataField);
break;
default:
break;
}
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:27,代码来源:GLMConverter.java
示例12: getMiningFunction
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
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();
}
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:17,代码来源:GLMConverter.java
示例13: getDataField
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
/**
* @return A synthetic {@link DataField} element describing the default target field.
*/
protected DataField getDataField(){
MiningFunction miningFunction = getMiningFunction();
switch(miningFunction){
case REGRESSION:
MathContext mathContext = getMathContext();
switch(mathContext){
case FLOAT:
return ModelEvaluator.DEFAULT_TARGET_CONTINUOUS_FLOAT;
default:
return ModelEvaluator.DEFAULT_TARGET_CONTINUOUS_DOUBLE;
}
case CLASSIFICATION:
case CLUSTERING:
return ModelEvaluator.DEFAULT_TARGET_CATEGORICAL_STRING;
default:
return null;
}
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:24,代码来源:ModelEvaluator.java
示例14: createTreeModelEvaluator
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
static
private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){
Node root = new Node()
.setPredicate(new False());
Targets targets = new Targets()
.addTargets(target);
TreeModel treeModel = new TreeModel(miningFunction, new MiningSchema(), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
.setMathContext(mathContext)
.setTargets(targets);
PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary())
.addModels(treeModel);
return new TreeModelEvaluator(pmml);
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:19,代码来源:TargetUtilTest.java
示例15: visit
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public VisitorAction visit(Node node){
TreeModel treeModel = getTreeModel();
MiningFunction miningFunction = treeModel.getMiningFunction();
switch(miningFunction){
case REGRESSION:
if(node.hasScoreDistributions()){
List<ScoreDistribution> scoreDistributions = node.getScoreDistributions();
scoreDistributions.clear();
}
break;
default:
break;
}
return super.visit(node);
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:20,代码来源:ScoreDistributionCleaner.java
示例16: clean
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Test
public void clean(){
Node node = new Node()
.setPredicate(new True())
.setScore("1")
.addScoreDistributions(new ScoreDistribution("0", 0), new ScoreDistribution("1", 100));
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, new MiningSchema(), node);
ScoreDistributionCleaner cleaner = new ScoreDistributionCleaner();
cleaner.applyTo(treeModel);
assertTrue(node.hasScoreDistributions());
treeModel.setMiningFunction(MiningFunction.REGRESSION);
cleaner.applyTo(treeModel);
assertFalse(node.hasScoreDistributions());
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:21,代码来源:ScoreDistributionCleanerTest.java
示例17: encodeTreeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
public TreeModel encodeTreeModel(PredicateManager predicateManager, Schema schema){
Node root = new Node()
.setPredicate(new True());
encodeNode(root, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), 0, schema);
TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);
return treeModel;
}
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:13,代码来源:Tree.java
示例18: encodeModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(TensorFlowEncoder encoder){
DataField dataField = encoder.createDataField(FieldName.create("_target"), OpType.CONTINUOUS, DataType.FLOAT);
Label label = new ContinuousLabel(dataField);
RegressionModel regressionModel = encodeRegressionModel(encoder)
.setMiningFunction(MiningFunction.REGRESSION)
.setMiningSchema(ModelUtil.createMiningSchema(label));
return regressionModel;
}
开发者ID:jpmml,项目名称:jpmml-tensorflow,代码行数:13,代码来源:LinearRegressor.java
示例19: validatePMMLVsSchema
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
/**
* Validates that the encoded PMML model received matches expected schema.
*
* @param pmml {@link PMML} encoding of a decision forest
* @param schema expected schema attributes of decision forest
*/
public static void validatePMMLVsSchema(PMML pmml, InputSchema schema) {
List<Model> models = pmml.getModels();
Preconditions.checkArgument(models.size() == 1,
"Should have exactly one model, but had %s", models.size());
Model model = models.get(0);
MiningFunction function = model.getMiningFunction();
if (schema.isClassification()) {
Preconditions.checkArgument(function == MiningFunction.CLASSIFICATION,
"Expected classification function type but got %s",
function);
} else {
Preconditions.checkArgument(function == MiningFunction.REGRESSION,
"Expected regression function type but got %s",
function);
}
DataDictionary dictionary = pmml.getDataDictionary();
Preconditions.checkArgument(
schema.getFeatureNames().equals(AppPMMLUtils.getFeatureNames(dictionary)),
"Feature names in schema don't match names in PMML");
MiningSchema miningSchema = model.getMiningSchema();
Preconditions.checkArgument(schema.getFeatureNames().equals(
AppPMMLUtils.getFeatureNames(miningSchema)));
Integer pmmlIndex = AppPMMLUtils.findTargetIndex(miningSchema);
if (schema.hasTarget()) {
int schemaIndex = schema.getTargetFeatureIndex();
Preconditions.checkArgument(
pmmlIndex != null && schemaIndex == pmmlIndex,
"Configured schema expects target at index %s, but PMML has target at index %s",
schemaIndex, pmmlIndex);
} else {
Preconditions.checkArgument(pmmlIndex == null);
}
}
开发者ID:oncewang,项目名称:oryx2,代码行数:44,代码来源:RDFPMMLUtils.java
示例20: buildDummyModel
import org.dmg.pmml.MiningFunction; //导入依赖的package包/类
private static PMML buildDummyModel() {
Node node = new Node().setRecordCount(123.0);
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, null, node);
PMML pmml = PMMLUtils.buildSkeletonPMML();
pmml.addModels(treeModel);
return pmml;
}
开发者ID:oncewang,项目名称:oryx2,代码行数:8,代码来源:AppPMMLUtilsTest.java
注:本文中的org.dmg.pmml.MiningFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论