public abstract class Model<M extends Model<M,P,O>,P extends Model.Parameters,O extends Model.Output> extends Lockable<M>
Modifier and Type | Class and Description |
---|---|
static interface |
Model.DeepFeatures |
static class |
Model.Output
Model-specific output class.
|
static class |
Model.Parameters
Model-specific parameter class.
|
Keyed.BinarySerializer<X extends Keyed>
Modifier and Type | Field and Description |
---|---|
O |
_output |
P |
_parms |
java.lang.String[] |
_warnings |
_key, EMPTY_KEY_LIST
Constructor and Description |
---|
Model(Key selfKey,
P parms,
O output)
Full constructor
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
adaptTestForTrain(Frame test,
boolean expensive,
boolean computeMetrics)
Adapt a Test/Validation Frame to be compatible for a Training Frame.
|
static java.lang.String[] |
adaptTestForTrain(java.lang.String[] names,
java.lang.String weights,
java.lang.String offset,
java.lang.String response,
java.lang.String[][] domains,
Frame test,
double missing,
boolean expensive,
boolean computeMetrics) |
ModelMetrics |
addMetrics(ModelMetrics mm) |
void |
addWarning(java.lang.String s) |
protected long |
checksum_impl()
High-quality 64-bit checksum of the content of the
object.
|
protected static void |
cleanup_adapt(Frame adaptFr,
Frame fr) |
double |
defaultThreshold() |
java.util.List<Key> |
getPublishedKeys()
Returns a list of keys which are published by this object.
|
boolean |
isSupervised() |
abstract ModelMetrics.MetricBuilder |
makeMetricBuilder(java.lang.String[] domain) |
protected Futures |
remove_impl(Futures fs)
Override to remove subparts, but not self, of composite Keyed objects.
|
double |
score(double[] data) |
Frame |
score(Frame fr)
Bulk score the frame, and auto-name the resulting predictions frame.
|
Frame |
score(Frame fr,
java.lang.String destination_key)
Bulk score the frame
fr , producing a Frame result; the 1st
Vec is the predicted class, the remaining Vecs are the probability
distributions. |
double[] |
score0(Chunk[] chks,
double weight,
double offset,
int row_in_chunk,
double[] tmp,
double[] preds) |
double[] |
score0(Chunk[] chks,
int row_in_chunk,
double[] tmp,
double[] preds)
Bulk scoring API for one row.
|
protected abstract double[] |
score0(double[] data,
double[] preds)
Subclasses implement the scoring logic.
|
protected double[] |
score0(double[] data,
double[] preds,
double weight,
double offset) |
protected Frame |
scoreImpl(Frame fr,
Frame adaptFrm,
java.lang.String destination_key)
Score an already adapted frame.
|
boolean |
testJavaScoring(Frame data,
Frame model_predictions,
double rel_epsilon) |
java.lang.String |
toJava(boolean preview)
Return a String which is a valid Java program representing a class that
implements the Model.
|
SB |
toJava(SB sb,
boolean preview) |
protected boolean |
toJavaCheckTooBig() |
protected SB |
toJavaInit(SB sb,
SB fileContext) |
protected SB |
toJavaNCLASSES(SB sb) |
protected void |
toJavaPredictBody(SB body,
SB cls,
SB file) |
protected SB |
toJavaPROB(SB sb) |
protected SB |
toJavaSuper(java.lang.String modelName,
SB sb)
Generate implementation for super class.
|
delete_and_lock, delete, delete, delete, read_lock, read_lock, unlock_all, unlock, update, write_lock
checksum, getBinarySerializer, remove, remove, remove, remove
clone, frozenType, read_impl, read, readExternal, readJSON_impl, readJSON, toJsonString, write_impl, write, writeExternal, writeHTML_impl, writeHTML, writeJSON_impl, writeJSON
public P extends Model.Parameters _parms
public java.lang.String[] _warnings
public O extends Model.Output _output
public double defaultThreshold()
public final boolean isSupervised()
public void addWarning(java.lang.String s)
public ModelMetrics addMetrics(ModelMetrics mm)
public abstract ModelMetrics.MetricBuilder makeMetricBuilder(java.lang.String[] domain)
public java.lang.String[] adaptTestForTrain(Frame test, boolean expensive, boolean computeMetrics)
missingColumnsType
). This will issue a warning,
and if the "expensive" flag is false won't actually make the column
replacement column but instead will bail-out on the whole adaption (but
will continue looking for more warnings).
- If all columns are missing, issue an error.
- Renumber matching cat levels to match the Train levels; this might make
"holes" in the Test set cat levels, if some are not in the Test set.
- Extra Test levels are renumbered past the end of the Train set, hence
the train and test levels match up to all the train levels; there might
be extra Test levels past that.
- For all mis-matched levels, issue a warning.
The test
frame is updated in-place to be compatible, by altering
the names and Vecs; make a defensive copy if you do not want it modified.
There is a fast-path cutout if the test set is already compatible. Since
the test-set is conditionally modifed with extra EnumWrappedVec optionally
added it is recommended to use a Scope enter/exit to track Vec lifetimes.test
- Testing Frame, updated in-placeexpensive
- Try hard to adapt; this might involve the creation of
whole Vecs and thus get expensive. If false
, then only adapt if
no warnings and errors; otherwise just the messages are produced.
Created Vecs have to be deleted by the caller (e.g. Scope.enter/exit).IllegalArgumentException
if no columns are in common, or
if any factor column has no levels in common.public static java.lang.String[] adaptTestForTrain(java.lang.String[] names, java.lang.String weights, java.lang.String offset, java.lang.String response, java.lang.String[][] domains, Frame test, double missing, boolean expensive, boolean computeMetrics) throws java.lang.IllegalArgumentException
names
- Training column namesweights
- Name of column with observation weights, weights are NOT filled in if missing in test frameoffset
- Name of column with offset, if not null (i.e. trained with offset), offset MUST be present in test data as well, otherwise can not scorew and IAE is thrown.response
- Name of response column, response is NOT filled in if missing in test framedomains
- Training column levelsmissing
- Substitute for missing columns; usually NaNjava.lang.IllegalArgumentException
public Frame score(Frame fr) throws java.lang.IllegalArgumentException
fr
- frame which should be scoredjava.lang.IllegalArgumentException
score(Frame, String)
public Frame score(Frame fr, java.lang.String destination_key) throws java.lang.IllegalArgumentException
fr
, producing a Frame result; the 1st
Vec is the predicted class, the remaining Vecs are the probability
distributions. For Regression (single-class) models, the 1st and only
Vec is the prediction value. The result is in the DKV; caller is
responsible for deleting.fr
- frame which should be scoredjava.lang.IllegalArgumentException
protected Frame scoreImpl(Frame fr, Frame adaptFrm, java.lang.String destination_key)
adaptFrm
- Already adapted framepublic double[] score0(Chunk[] chks, int row_in_chunk, double[] tmp, double[] preds)
public double[] score0(Chunk[] chks, double weight, double offset, int row_in_chunk, double[] tmp, double[] preds)
protected abstract double[] score0(double[] data, double[] preds)
protected double[] score0(double[] data, double[] preds, double weight, double offset)
public double score(double[] data)
protected long checksum_impl()
Keyed
public final java.lang.String toJava(boolean preview)
class UUIDxxxxModel { public static final String NAMES[] = { ....column names... } public static final String DOMAINS[][] = { ....domain names... } // Pass in data in a double[], pre-aligned to the Model's requirements. // Jam predictions into the preds[] array; preds[0] is reserved for the // main prediction (class for classifiers or value for regression), // and remaining columns hold a probability distribution for classifiers. double[] predict( double data[], double preds[] ); double[] map( HashMap < String,Double > row, double data[] ); // Does the mapping lookup for every row, no allocation double[] predict( HashMap < String,Double > row, double data[], double preds[] ); // Allocates a double[] for every row double[] predict( HashMap < String,Double > row, double preds[] ); // Allocates a double[] and a double[] for every row double[] predict( HashMap < String,Double > row ); }
protected SB toJavaSuper(java.lang.String modelName, SB sb)
protected boolean toJavaCheckTooBig()
public boolean testJavaScoring(Frame data, Frame model_predictions, double rel_epsilon)