water.fvec.Frame.lastVec()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中water.fvec.Frame.lastVec()方法的一些代码示例,展示了Frame.lastVec()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Frame.lastVec()方法的具体详情如下:
包路径:water.fvec.Frame
类名称:Frame
方法名:lastVec

Frame.lastVec介绍

暂无

代码示例

代码示例来源:origin: h2oai/h2o-2

@Override public void setupLocal(){_fr.lastVec().preWriting();}
@Override public void map(Chunk [] chks) {

代码示例来源:origin: h2oai/h2o-2

private Frame setTrain() { Frame train = FrameTask.DataInfo.prepareFrame(source, response, ignored_cols, !regression /*toEnum is TRUE if regression is FALSE*/, false, false); if (train.lastVec().masterVec() != null && train.lastVec() != response) gtrash(train.lastVec()); return train; }
private Frame setTest() {

代码示例来源:origin: h2oai/h2o-2

private float[] setPriorDist(Frame train) { return classification ? new MRUtils.ClassDist(train.lastVec()).doAll(train.lastVec()).rel_dist() : null; }
public Frame score( Frame fr ) { return ((SpeeDRFModel)UKV.get(dest())).score(fr);  }

代码示例来源:origin: h2oai/h2o-3

private TwoDimTable createModelSummaryTable(KMeansModel.KMeansOutput output) {
 List<String> colHeaders = new ArrayList<>();
 List<String> colTypes = new ArrayList<>();
 List<String> colFormat = new ArrayList<>();
 colHeaders.add("Number of Rows"); colTypes.add("long"); colFormat.add("%d");
 colHeaders.add("Number of Clusters"); colTypes.add("long"); colFormat.add("%d");
 colHeaders.add("Number of Categorical Columns"); colTypes.add("long"); colFormat.add("%d");
 colHeaders.add("Number of Iterations"); colTypes.add("long"); colFormat.add("%d");
 colHeaders.add("Within Cluster Sum of Squares"); colTypes.add("double"); colFormat.add("%.5f");
 colHeaders.add("Total Sum of Squares"); colTypes.add("double"); colFormat.add("%.5f");
 colHeaders.add("Between Cluster Sum of Squares"); colTypes.add("double"); colFormat.add("%.5f");
 final int rows = 1;
 TwoDimTable table = new TwoDimTable(
     "Model Summary", null,
     new String[rows],
     colHeaders.toArray(new String[0]),
     colTypes.toArray(new String[0]),
     colFormat.toArray(new String[0]),
     "");
 int row = 0;
 int col = 0;
 table.set(row, col++, Math.round(_train.numRows() * (hasWeightCol() ? _train.lastVec().mean() : 1)));
 table.set(row, col++, output._centers_raw.length);
 table.set(row, col++, output._categorical_column_count);
 table.set(row, col++, output._k.length-1);
 table.set(row, col++, output._tot_withinss);
 table.set(row, col++, output._totss);
 table.set(row, col++, output._betweenss);
 return table;
}

代码示例来源:origin: h2oai/h2o-2

private Frame setTest() {
 if (validation == null) return null;
 Frame test = null;
 ArrayList<Integer> v_ignored_cols = new ArrayList<Integer>();
 for (int ignored_col : ignored_cols) if (validation.find(source.names()[ignored_col]) != -1) v_ignored_cols.add(ignored_col);
 int[] v_ignored = new int[v_ignored_cols.size()];
 for (int i = 0; i < v_ignored.length; ++i) v_ignored[i] = v_ignored_cols.get(i);
 if (validation != null) test = FrameTask.DataInfo.prepareFrame(validation, validation.vecs()[validation.find(source.names()[source.find(response)])], v_ignored, !regression, false, false);
 if (test != null && test.lastVec().masterVec() != null) gtrash(test.lastVec());
 return test;
}
private Frame setStrat(Frame train, Frame test, Vec resp) {

代码示例来源:origin: h2oai/h2o-3

@Override protected void checkMemoryFootPrint_impl() {
 if (_parms._checkpoint != null) return;
 long p = hex.util.LinearAlgebraUtils.numColsExp(_train,true) - (_parms._autoencoder ? 0 : _train.lastVec().cardinality());
 String[][] dom = _train.domains();
 long output = _parms._autoencoder ? p : Math.abs(_train.lastVec().cardinality());
 long model_size = 0;
 if (_parms._hidden.length==0) {

代码示例来源:origin: h2oai/h2o-3

protected void checkMemoryFootPrint(DataInfo activeData) {
 if (_parms._solver == Solver.IRLSM || _parms._solver == Solver.COORDINATE_DESCENT) {
  int p = activeData.fullN();
  HeartBeat hb = H2O.SELF._heartbeat;
  long mem_usage = (long) (hb._cpus_allowed * (p * p + activeData.largestCat()) * 8/*doubles*/ * (1 + .5 * Math.log((double) _train.lastVec().nChunks()) / Math.log(2.))); //one gram per core
  long max_mem = hb.get_free_mem();
  if (mem_usage > max_mem) {
   String msg = "Gram matrices (one per thread) won't fit in the driver node's memory ("
    + PrettyPrint.bytes(mem_usage) + " > " + PrettyPrint.bytes(max_mem)
    + ") - try reducing the number of columns and/or the number of categorical factors (or switch to the L-BFGS solver).";
   error("_train", msg);
  }
 }
}

代码示例来源:origin: h2oai/h2o-2

@Override protected void cleanup(){
 super.cleanup();
 if(toEnum && _srcDinfo != null){
  Futures fs = new Futures();
  _srcDinfo._adaptedFrame.lastVec().remove(fs);
  fs.blockForPending();
 }
}
@Override protected boolean filterNaCols(){return true;}

代码示例来源:origin: h2oai/h2o-3

@Override
protected void checkMemoryFootPrint_impl() {
 HeartBeat hb = H2O.SELF._heartbeat;
 double p = LinearAlgebraUtils.numColsExp(_train, true);
 double r = _train.numRows();
 boolean useGramSVD = _parms._svd_method == SVDParameters.Method.GramSVD;
 boolean usePower = _parms._svd_method == SVDParameters.Method.Power;
 boolean useRandomized = _parms._svd_method == SVDParameters.Method.Randomized;
 double gramSize =  _train.lastVec().nChunks()==1 ? 1 :
     Math.log((double) _train.lastVec().nChunks()) / Math.log(2.); // gets to zero if nChunks=1
 long mem_usage = (useGramSVD || usePower || useRandomized) ? (long) (hb._cpus_allowed * p * p * 8/*doubles*/
     * gramSize) : 1; //one gram per core
 long mem_usage_w = (useGramSVD || usePower || useRandomized) ? (long) (hb._cpus_allowed * r * r * 8/*doubles*/
     * gramSize) : 1; //one gram per core
 long max_mem = hb.get_free_mem();
 if ((mem_usage > max_mem) && (mem_usage_w > max_mem)) {
  String msg = "Gram matrices (one per thread) won't fit in the driver node's memory ("
      + PrettyPrint.bytes(mem_usage) + " > " + PrettyPrint.bytes(max_mem)
      + ") - try reducing the number of columns and/or the number of categorical factors.";
  error("_train", msg);
 }
 // _wideDataset is true if original memory does not fit.
 if (mem_usage > max_mem) {
  _wideDataset = true;  // have to set _wideDataset in this case
 } else {  // both ways fit into memory.  Want to choose wideDataset if p is too big.
  if ((p > 5000) && ( r < 5000)) {
   _wideDataset = true;
  }
 }
}

代码示例来源:origin: h2oai/h2o-3

double gramSize =  _train.lastVec().nChunks()==1 ? 1 :
    Math.log((double) _train.lastVec().nChunks()) / Math.log(2.);

代码示例来源:origin: h2oai/h2o-3

static DataInfo makeDataInfo(Frame train, Frame valid, DeepWaterParameters parms) {
 double x = 0.782347234;
 boolean identityLink = new Distribution(parms).link(x) == x;
 return new DataInfo(
   train,
   valid,
   parms._autoencoder ? 0 : 1, //nResponses
   parms._autoencoder || parms._use_all_factor_levels, //use all FactorLevels for auto-encoder
   parms._standardize ? (parms._autoencoder ? DataInfo.TransformType.NORMALIZE : parms._sparse ? DataInfo.TransformType.DESCALE : DataInfo.TransformType.STANDARDIZE) : DataInfo.TransformType.NONE, //transform predictors
   !parms._standardize || train.lastVec().isCategorical() ? DataInfo.TransformType.NONE : identityLink ? DataInfo.TransformType.STANDARDIZE : DataInfo.TransformType.NONE, //transform response for regression with identity link
   parms._missing_values_handling == DeepWaterParameters.MissingValuesHandling.Skip, //whether to skip missing
   false, // do not replace NAs in numeric cols with mean
   true,  // always add a bucket for missing values
   parms._weights_column != null, // observation weights
   parms._offset_column != null,
   parms._fold_column != null
 );
}

代码示例来源:origin: h2oai/h2o-2

private String report() {
 Frame res = UKV.get(dest());
 if (!pairwise)
 return "Created interaction feature " + res.names()[0]
     + " (order: " + factors.length + ") with " + res.lastVec().domain().length + " factor levels"
     + " in" + PrettyPrint.msecs(_time, true);
 else
  return "Created " + res.numCols() + " pair-wise interaction features " + Arrays.deepToString(res.names())
     + " (order: 2) in" + PrettyPrint.msecs(_time, true);
}

代码示例来源:origin: h2oai/h2o-2

/**
 * Helper to create a DataInfo object from the source and response
 * @return DataInfo object
 */
private DataInfo prepareDataInfo() {
 final boolean del_enum_resp = classification && !response.isEnum();
 final Frame train = FrameTask.DataInfo.prepareFrame(source, autoencoder ? null : response, ignored_cols, classification, ignore_const_cols, true /*drop >20% NA cols*/);
 final DataInfo dinfo = new FrameTask.DataInfo(train, autoencoder ? 0 : 1, true, autoencoder || use_all_factor_levels, //use all FactorLevels for auto-encoder
     autoencoder ? DataInfo.TransformType.NORMALIZE : DataInfo.TransformType.STANDARDIZE, //transform predictors
     classification ? DataInfo.TransformType.NONE : DataInfo.TransformType.STANDARDIZE);  //transform response
 if (!autoencoder) {
  final Vec resp = dinfo._adaptedFrame.lastVec(); //convention from DataInfo: response is the last Vec
  assert (!classification ^ resp.isEnum()) : "Must have enum response for classification!"; //either regression or enum response
  if (del_enum_resp) ltrash(resp);
 }
 return dinfo;
}

代码示例来源:origin: h2oai/h2o-3

@Override
protected void checkMemoryFootPrint_impl() {
 // compute memory usage for pcond matrix
 long mem_usage = (_train.numCols() - 1) * _train.lastVec().cardinality();
 String[][] domains = _train.domains();
 long count = 0;
 for (int i = 0; i < _train.numCols() - 1; i++) {
  count += domains[i] == null ? 2 : domains[i].length;
 }
 mem_usage *= count;
 mem_usage *= 8; //doubles
 long max_mem = H2O.SELF._heartbeat.get_free_mem();
 if (mem_usage > max_mem) {
  String msg = "Conditional probabilities won't fit in the driver node's memory ("
      + PrettyPrint.bytes(mem_usage) + " > " + PrettyPrint.bytes(max_mem)
      + ") - try reducing the number of columns, the number of response classes or the number of categorical factors of the predictors.";
  error("_train", msg);
 }
}

代码示例来源:origin: h2oai/h2o-3

@Override
protected ModelMetrics.MetricBuilder scoreMetrics(Frame adaptFrm) {
 final boolean makeNative = model_info()._backend ==null;
 if (makeNative) model_info().javaToNative();
 final boolean computeMetrics = (!isSupervised() || (adaptFrm.vec(_output.responseName()) != null && !adaptFrm.vec(_output.responseName()).isBad()));
 // Build up the names & domains.
 String [] domain = !computeMetrics ? _output._domains[_output._domains.length-1] : adaptFrm.lastVec().domain();
 // Score the dataset, building the class distribution & predictions
 BigScore bs = new DeepWaterBigScore(domain,0,adaptFrm.means(),_output.hasWeights() && adaptFrm.find(_output.weightsName()) >= 0,computeMetrics, false /*no preds*/, null).doAll(adaptFrm);
 if (makeNative) removeNativeState();
 return bs._mb;
}

代码示例来源:origin: h2oai/h2o-3

private GLMScore makeScoringTask(Frame adaptFrm, boolean generatePredictions, Job j){
 int responseId = adaptFrm.find(_output.responseName());
 if(responseId > -1 && adaptFrm.vec(responseId).isBad()) { // remove inserted invalid response
  adaptFrm = new Frame(adaptFrm.names(),adaptFrm.vecs());
  adaptFrm.remove(responseId);
 }
 // Build up the names & domains.
 final boolean computeMetrics = adaptFrm.vec(_output.responseName()) != null && !adaptFrm.vec(_output.responseName()).isBad();
 String [] domain = _output.nclasses()<=1 ? null : !computeMetrics ? _output._domains[_output._domains.length-1] : adaptFrm.lastVec().domain();
 // Score the dataset, building the class distribution & predictions
 return new GLMScore(j, this, _output._dinfo.scoringInfo(_output._names,adaptFrm),domain,computeMetrics, generatePredictions);
}
/** Score an already adapted frame.  Returns a new Frame with new result

代码示例来源:origin: h2oai/h2o-2

/**
 * Create an initial Deep Learning model, typically to be trained by trainModel(model)
 * @return Randomly initialized model
 */
public final DeepLearningModel initModel() {
 try {
  lock_data();
  checkParams();
  final DataInfo dinfo = prepareDataInfo();
  final Vec resp = dinfo._adaptedFrame.lastVec(); //convention from DataInfo: response is the last Vec
  float[] priorDist = classification ? new MRUtils.ClassDist(resp).doAll(resp).rel_dist() : null;
  final DeepLearningModel model = new DeepLearningModel(dest(), self(), source._key, dinfo, (DeepLearning)this.clone(), priorDist);
  model.model_info().initializeMembers();
  return model;
 }
 finally {
  unlock_data();
 }
}

代码示例来源:origin: h2oai/h2o-3

@BeforeClass
public static void setup() {
 stall_till_cloudsize(1);
 _covtype = parse_test_file("smalldata/covtype/covtype.20k.data");
 _covtype.replace(_covtype.numCols()-1,_covtype.lastVec().toCategoricalVec()).remove();
 Key[] keys = new Key[]{Key.make("train"),Key.make("test")};
 H2O.submitTask(new FrameSplitter(_covtype, new double[]{.8},keys,null)).join();
 _train = DKV.getGet(keys[0]);
 _test = DKV.getGet(keys[1]);
}

代码示例来源:origin: h2oai/h2o-3

@Override public ModelMetrics makeModelMetrics(Model m, Frame f, Frame adaptedFrame, Frame preds) {
 GLMModel gm = (GLMModel)m;
 computeAIC();
 ModelMetrics metrics = _metricBuilder.makeModelMetrics(gm, f, null, null);
 if (_glmf._family == Family.binomial || _glmf._family == Family.quasibinomial) {
  ModelMetricsBinomial metricsBinommial = (ModelMetricsBinomial) metrics;
  GainsLift gl = null;
  if (preds!=null) {
   Vec resp = f.vec(m._parms._response_column);
   Vec weights = f.vec(m._parms._weights_column);
   if (resp != null) {
    gl = new GainsLift(preds.lastVec(), resp, weights);
    gl.exec(m._output._job);
   }
  }
  metrics = new ModelMetricsBinomialGLM(m, f, metrics._nobs, metrics._MSE, _domain, metricsBinommial._sigma, metricsBinommial._auc, metricsBinommial._logloss, residualDeviance(), null_devince, _aic, nullDOF(), resDOF(), gl, _customMetric);
 } else if( _glmf._family == Family.multinomial) {
  ModelMetricsMultinomial metricsMultinomial = (ModelMetricsMultinomial) metrics;
  metrics = new ModelMetricsMultinomialGLM(m, f, metricsMultinomial._nobs,metricsMultinomial._MSE, metricsMultinomial._domain, metricsMultinomial._sigma, metricsMultinomial._cm, metricsMultinomial._hit_ratios, metricsMultinomial._logloss, residualDeviance(), null_devince, _aic, nullDOF(), resDOF(), _customMetric);
 } else if ( _glmf._family == Family.ordinal) { // ordinal should have a different resDOF()
  ModelMetricsOrdinal metricsOrdinal = (ModelMetricsOrdinal) metrics;
  metrics = new ModelMetricsOrdinalGLM(m, f, metricsOrdinal._nobs,metricsOrdinal._MSE, metricsOrdinal._domain, metricsOrdinal._sigma, metricsOrdinal._cm, metricsOrdinal._hit_ratios, metricsOrdinal._logloss, residualDeviance(), null_devince, _aic, nullDOF(), resDOF(), _customMetric);
 } else {
  ModelMetricsRegression metricsRegression = (ModelMetricsRegression) metrics;
  metrics = new ModelMetricsRegressionGLM(m, f, metricsRegression._nobs, metricsRegression._MSE, metricsRegression._sigma, metricsRegression._mean_absolute_error, metricsRegression._root_mean_squared_log_error, residualDeviance(), residualDeviance()/_wcount, null_devince, _aic, nullDOF(), resDOF(), _customMetric);
 }
 return gm.addModelMetrics(metrics); // Update the metrics in-place with the GLM version
}

代码示例来源:origin: h2oai/h2o-3

double sq_err = new MathUtils.SquareError().doAll(vfr.lastVec(),pred.vecs()[0])._sum;
double mse = sq_err/pred.numRows();
assertEquals(3.0199, mse, 1e-15); //same results

相关文章