本文整理汇总了Java中org.jpmml.xgboost.Learner类的典型用法代码示例。如果您正苦于以下问题:Java Learner类的具体用法?Java Learner怎么用?Java Learner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Learner类属于org.jpmml.xgboost包,在下文中一共展示了Learner类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeBooster
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
static
public MiningModel encodeBooster(Booster booster, Schema schema){
byte[] bytes = booster.toByteArray();
Learner learner;
try(InputStream is = new ByteArrayInputStream(bytes)){
learner = XGBoostUtil.loadLearner(is);
} catch(IOException ioe){
throw new RuntimeException(ioe);
}
Function<Feature, Feature> function = new Function<Feature, Feature>(){
@Override
public Feature apply(Feature feature){
if(feature instanceof BinaryFeature){
BinaryFeature binaryFeature = (BinaryFeature)feature;
return binaryFeature;
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature(DataType.FLOAT);
return continuousFeature;
}
}
};
Schema xgbSchema = schema.toTransformedSchema(function);
return learner.encodeMiningModel(null, false, xgbSchema);
}
示例2: getLearner
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
public Learner getLearner(){
if(this.learner == null){
this.learner = loadLearner();
}
return this.learner;
}
示例3: loadLearner
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
private Learner loadLearner(){
byte[] handle = getHandle();
try(InputStream is = new ByteArrayInputStream(handle)){
return XGBoostUtil.loadLearner(is);
} catch(IOException ioe){
throw new RuntimeException(ioe);
}
}
示例4: ensureLearner
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
private Learner ensureLearner(){
if(this.learner == null){
this.learner = loadLearner();
}
return this.learner;
}
示例5: loadLearner
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
private Learner loadLearner(){
RGenericVector booster = getObject();
RRaw raw = (RRaw)booster.getValue("raw");
try {
return loadLearner(raw);
} catch(IOException ioe){
throw new IllegalArgumentException(ioe);
}
}
示例6: getNumberOfFeatures
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
static
public <E extends Estimator & HasBooster> int getNumberOfFeatures(E estimator){
Learner learner = getLearner(estimator);
return learner.getNumFeatures();
}
示例7: getLearner
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
static
private Learner getLearner(HasBooster hasBooster){
Booster booster = hasBooster.getBooster();
return booster.getLearner();
}
示例8: encodeSchema
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
@Override
public void encodeSchema(RExpEncoder encoder){
RGenericVector booster = getObject();
RGenericVector schema = (RGenericVector)booster.getValue("schema", true);
RVector<?> fmap;
try {
fmap = (RVector<?>)booster.getValue("fmap");
} catch(IllegalArgumentException iae){
throw new IllegalArgumentException("No feature map information. Please initialize the \'fmap\' element");
}
FeatureMap featureMap;
try {
featureMap = loadFeatureMap(fmap);
} catch(IOException ioe){
throw new IllegalArgumentException(ioe);
}
if(schema != null){
RVector<?> missing = (RVector<?>)schema.getValue("missing", true);
if(missing != null){
featureMap.addMissingValue(ValueUtil.formatValue(missing.asScalar()));
}
}
Learner learner = ensureLearner();
// Dependent variable
{
ObjFunction obj = learner.getObj();
FieldName targetField = FieldName.create("_target");
List<String> targetCategories = null;
if(schema != null){
RStringVector responseName = (RStringVector)schema.getValue("response_name", true);
RStringVector responseLevels = (RStringVector)schema.getValue("response_levels", true);
if(responseName != null){
targetField = FieldName.create(responseName.asScalar());
} // End if
if(responseLevels != null){
targetCategories = responseLevels.getValues();
}
}
Label label = obj.encodeLabel(targetField, targetCategories, encoder);
encoder.setLabel(label);
}
// Independent variables
{
List<Feature> features = featureMap.encodeFeatures(encoder);
for(Feature feature : features){
encoder.addFeature(feature);
}
}
}
示例9: encodeBooster
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
static
public <E extends Estimator & HasBooster & HasXGBoostOptions> MiningModel encodeBooster(E estimator, Schema schema){
Learner learner = getLearner(estimator);
Integer ntreeLimit = (Integer)estimator.getOption(HasXGBoostOptions.OPTION_NTREE_LIMIT, null);
Boolean compact = (Boolean)estimator.getOption(HasXGBoostOptions.OPTION_COMPACT, Boolean.TRUE);
Schema xgbSchema = XGBoostUtil.toXGBoostSchema(schema);
MiningModel miningModel = learner.encodeMiningModel(ntreeLimit, compact, xgbSchema);
return miningModel;
}
示例10: encodeModel
import org.jpmml.xgboost.Learner; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
RGenericVector booster = getObject();
RNumberVector<?> ntreeLimit = (RNumberVector<?>)booster.getValue("ntreelimit", true);
RBooleanVector compact = (RBooleanVector)booster.getValue("compact", true);
Learner learner = ensureLearner();
MiningModel miningModel = learner.encodeMiningModel((ntreeLimit != null ? ValueUtil.asInteger(ntreeLimit.asScalar()) : null), (compact != null ? compact.asScalar() : false), schema);
return miningModel;
}