ml.dmlc.xgboost4j.LabeledPoint Java Examples
The following examples show how to use
ml.dmlc.xgboost4j.LabeledPoint.
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: MLXGBoost.java From RecSys2018 with Apache License 2.0 | 6 votes |
public static String toLIBSVMString(final LabeledPoint vec) { float target = vec.label(); StringBuilder builder = new StringBuilder(); if (target == (int) target) { builder.append((int) target); } else { builder.append(String.format("%.5f", target)); } for (int i = 0; i < vec.indices().length; i++) { float val = vec.values()[i]; if (val == Math.round(val)) { builder.append(" " + (vec.indices()[i]) + ":" + ((int) val)); } else { builder.append(" " + (vec.indices()[i]) + ":" + String.format("%.5f", val)); } } return builder.toString(); }
Example #2
Source File: XGBoostUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static DMatrix createDMatrix(@Nonnull final List<LabeledPointWithRowId> data) throws XGBoostError { final List<LabeledPoint> points = new ArrayList<>(data.size()); for (LabeledPointWithRowId d : data) { points.add(d); } return new DMatrix(points.iterator(), ""); }
Example #3
Source File: XGBoostInstance.java From samantha with MIT License | 5 votes |
public LabeledPoint getLabeledPoint() { Int2DoubleMap features = instance.getFeatures(); float[] values = new float[features.size()]; double[] froms = features.values().toDoubleArray(); for (int i=0; i<froms.length; i++) { values[i] = (float) froms[i]; } return new LabeledPoint((float) instance.getLabel(), features.keySet().toIntArray(), values); }
Example #4
Source File: XGBoostIterator.java From samantha with MIT License | 5 votes |
@Override public LabeledPoint next() { XGBoostInstance back = instance; instance = null; num++; return back.getLabeledPoint(); }
Example #5
Source File: FeatranExtractFns.java From zoltar with Apache License 2.0 | 2 votes |
/** * Extract features as {@link LabeledPoint}. * * @param featureSpec Featran's {@link FeatureSpec}. * @param settings JSON settings from a previous session. * @param <InputT> type of the input to feature extraction. * @return feature extraction result. */ public static <InputT> ExtractFn<InputT, LabeledPoint> labeledPoints( final FeatureSpec<InputT> featureSpec, final String settings) { return labeledPoints(JFeatureSpec.wrap(featureSpec), settings); }
Example #6
Source File: FeatranExtractFns.java From zoltar with Apache License 2.0 | 2 votes |
/** * Extract features as {@link LabeledPoint}. * * @param featureSpec Featran's {@link JFeatureSpec}. * @param settings JSON settings from a previous session. * @param <InputT> type of the input to feature extraction. * @return feature extraction result. */ public static <InputT> ExtractFn<InputT, LabeledPoint> labeledPoints( final JFeatureSpec<InputT> featureSpec, final String settings) { return ExtractFn.lift(featureSpec.extractWithSettingsLabeledPoint(settings)::featureValue); }