Class Regressor
java.lang.Object
org.tribuo.regression.Regressor
- All Implemented Interfaces:
Serializable
,Iterable<Regressor.DimensionTuple>
,Output<Regressor>
- Direct Known Subclasses:
Regressor.DimensionTuple
public class Regressor
extends Object
implements Output<Regressor>, Iterable<Regressor.DimensionTuple>
An
Output
for n-dimensional real valued regression.
In addition to the regressed values, it may optionally contain
variances. Otherwise the variances are set to Double.NaN
.
Within a DataSource
or Dataset
each Regressor must contain the same set of named dimensions. The dimensions stored in a
Regressor are sorted by the natural ordering of their names (i.e., using the String comparator).
This allows the use of direct indexing into the elements.
Note fullEquals(org.tribuo.regression.Regressor)
compares the dimensions, the regressed values and the
variances. However unlike Double.equals(java.lang.Object)
, if the two variances being compared are
set to the sentinel value of Double.NaN
, then they are considered equal.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
ARegressor
which contains a single dimension, used internally when the model implementation doesn't natively support multi-dimensional regression outputs. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a regressor from the supplied named values.Constructs a regressor from the supplied named values.Constructs a regressor containing a single dimension, usingDouble.NaN
as the variance.Constructs a regressor containing a single dimension.Regressor
(Regressor.DimensionTuple[] dimensions) Constructs a regressor from the supplied dimension tuples. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Deep copy of the output up to it's immutable state.static Regressor
createFromPairList
(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Double>> dimensions) Creates a Regressor from a list of dimension tuples.boolean
Regressors are equal if they have the same number of dimensions and equal dimension names.static String[]
extractNames
(OutputInfo<Regressor> info) Extracts the names from the supplied Regressor domain in their canonical order.boolean
fullEquals
(Regressor other) Compares other to this output.getDimension
(String name) Returns a dimension tuple for the requested dimension, or optional empty if it's not valid.Returns a comma separated list of the dimension names.getDimensionNamesString
(char separator) Returns a delimiter separated list of the dimension names.String[]
getNames()
The names of the dimensions.getSerializableForm
(boolean includeConfidence) Generates a String suitable for writing to a csv or json file.double[]
Returns the regression values.double[]
The variances of the regressed values, if known.int
hashCode()
Regressor's hashcode is based on the hash of the dimension names.iterator()
parseElement
(int idx, String s) Parses a string of the form:static Regressor
Parses a string of the form:static Regressor
parseString
(String s, char splitChar) Parses a string of the form:int
size()
Returns the number of dimensions in this regressor.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
TOLERANCE
- See Also:
-
DEFAULT_NAME
- See Also:
-
-
Constructor Details
-
Regressor
Constructs a regressor from the supplied named values. ThrowsIllegalArgumentException
if the arrays are not all the same size.- Parameters:
names
- The names of the dimensions.values
- The values of the dimensions.variances
- The variances of the specified values.
-
Regressor
Constructs a regressor from the supplied named values. UsesDouble.NaN
as the variances.- Parameters:
names
- The names of the dimensions.values
- The values of the dimensions.
-
Regressor
Constructs a regressor from the supplied dimension tuples.- Parameters:
dimensions
- The named values to use.
-
Regressor
Constructs a regressor containing a single dimension, usingDouble.NaN
as the variance.- Parameters:
name
- The name of the dimension.value
- The value of the dimension.
-
Regressor
-
-
Method Details
-
size
Returns the number of dimensions in this regressor.- Returns:
- The number of dimensions.
-
getNames
-
getValues
-
getVariances
The variances of the regressed values, if known. Returns Double.NaN otherwise.- Returns:
- The variance of the regressed values.
-
toString
-
getDimension
Returns a dimension tuple for the requested dimension, or optional empty if it's not valid.- Parameters:
name
- The dimension name.- Returns:
- A tuple representing that dimension.
-
iterator
- Specified by:
iterator
in interfaceIterable<Regressor.DimensionTuple>
-
copy
-
getSerializableForm
Description copied from interface:Output
Generates a String suitable for writing to a csv or json file.- Specified by:
getSerializableForm
in interfaceOutput<Regressor>
- Parameters:
includeConfidence
- Include whatever confidence score the label contains, if known.- Returns:
- A String representation of this Output.
-
fullEquals
Description copied from interface:Output
Compares other to this output. Uses all score values and the strings.- Specified by:
fullEquals
in interfaceOutput<Regressor>
- Parameters:
other
- Another output instance.- Returns:
- True if the other instance has value equality to this instance. False otherwise.
-
equals
-
hashCode
-
getDimensionNamesString
Returns a comma separated list of the dimension names.- Returns:
- The dimension names comma separated.
-
getDimensionNamesString
Returns a delimiter separated list of the dimension names.- Parameters:
separator
- The separator to use.- Returns:
- The dimension names.
-
extractNames
Extracts the names from the supplied Regressor domain in their canonical order.- Parameters:
info
- The OutputInfo to use.- Returns:
- The dimension names from this domain.
-
parseString
Parses a string of the form:dimension-name=output,...,dimension-name=output
where output must be readable byDouble.parseDouble(java.lang.String)
.- Parameters:
s
- The string form of a multiple regressor.- Returns:
- A regressor parsed from the input string.
-
parseString
Parses a string of the form:dimension-name=output<splitChar>...<splitChar>dimension-name=output
where output must be readable byDouble.parseDouble(java.lang.String)
.- Parameters:
s
- The string form of a regressor.splitChar
- The char to split on.- Returns:
- A regressor parsed from the input string.
-
parseElement
Parses a string of the form:dimension-name=output-double
where the output must be readable byDouble.parseDouble(java.lang.String)
.- Parameters:
idx
- The index of this string in a list.s
- The string form of a single dimension from a regressor.- Returns:
- A tuple representing the dimension name and the value.
-
createFromPairList
public static Regressor createFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Double>> dimensions) Creates a Regressor from a list of dimension tuples.- Parameters:
dimensions
- The dimensions to use.- Returns:
- A Regressor representing these dimensions.
-