Class RegressionFactory

java.lang.Object
org.tribuo.regression.RegressionFactory
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable, com.oracle.labs.mlrg.olcut.provenance.Provenancable<OutputFactoryProvenance>, Serializable, OutputFactory<Regressor>, ProtoSerializable<org.tribuo.protos.core.OutputFactoryProto>

public final class RegressionFactory extends Object implements OutputFactory<Regressor>
A factory for creating Regressors and RegressionInfos.

It parses the regression dimensions by toStringing the input and calling Regressor.parseString(java.lang.String), unless the input is a collection, in which case it extracts the elements.

This OutputFactory has mutable state, namely the character which the dimension input is split on. In most cases the default DEFAULT_SPLIT_CHAR is fine.

See Also:
  • Field Details

    • DEFAULT_SPLIT_CHAR

      public static final char DEFAULT_SPLIT_CHAR
      The default character to split the string form of a multidimensional regressor.
      See Also:
    • UNKNOWN_REGRESSOR

      public static final Regressor UNKNOWN_REGRESSOR
      The sentinel unknown regressor, used when there is no ground truth regressor value.
    • UNKNOWN_MULTIPLE_REGRESSOR

      @Deprecated public static final Regressor UNKNOWN_MULTIPLE_REGRESSOR
      Deprecated.
      Deprecated when regression was made multidimensional by default. Use UNKNOWN_REGRESSOR instead.
  • Constructor Details

    • RegressionFactory

      public RegressionFactory()
      Builds a regression factory using the default split character DEFAULT_SPLIT_CHAR.
    • RegressionFactory

      public RegressionFactory(char splitChar)
      Sets the split character used to parse Regressor instances from Strings.
      Parameters:
      splitChar - The split character.
  • Method Details

    • postConfig

      public void postConfig()
      Used by the OLCUT configuration system, and should not be called by external code.
      Specified by:
      postConfig in interface com.oracle.labs.mlrg.olcut.config.Configurable
    • deserializeFromProto

      public static RegressionFactory deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException
      Deserialization factory.
      Parameters:
      version - The serialized object version.
      className - The class name.
      message - The serialized data.
      Returns:
      The deserialized object.
      Throws:
      com.google.protobuf.InvalidProtocolBufferException - If the protobuf could not be parsed from the message.
    • serialize

      public org.tribuo.protos.core.OutputFactoryProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<org.tribuo.protos.core.OutputFactoryProto>
      Returns:
      The protobuf.
    • generateOutput

      public <V> Regressor generateOutput(V label)
      Parses the Regressor value either by toStringing the input and calling Regressor.parseString(java.lang.String) or if it's a collection iterating over the elements calling toString on each element in turn and using Regressor.parseElement(int, java.lang.String).
      Specified by:
      generateOutput in interface OutputFactory<Regressor>
      Type Parameters:
      V - The type of the input value.
      Parameters:
      label - An input value.
      Returns:
      A MultipleRegressor with sentinel variances.
    • getUnknownOutput

      public Regressor getUnknownOutput()
      Description copied from interface: OutputFactory
      Returns the singleton unknown output of type T which can be used for prediction time examples.
      Specified by:
      getUnknownOutput in interface OutputFactory<Regressor>
      Returns:
      An unknown output.
    • generateInfo

      public MutableOutputInfo<Regressor> generateInfo()
      Description copied from interface: OutputFactory
      Generates the appropriate MutableOutputInfo so the output values can be tracked by a Dataset or other aggregate.
      Specified by:
      generateInfo in interface OutputFactory<Regressor>
      Returns:
      The appropriate subclass of MutableOutputInfo initialised to zero.
    • constructInfoForExternalModel

      public ImmutableOutputInfo<Regressor> constructInfoForExternalModel(Map<Regressor,Integer> mapping)
      Description copied from interface: OutputFactory
      Creates an ImmutableOutputInfo from the supplied mapping. Requires that the mapping is dense in the integers [0,mapping.size()) and each mapping is unique.

      This call is used to import external models, and should not be used for other purposes.

      Specified by:
      constructInfoForExternalModel in interface OutputFactory<Regressor>
      Parameters:
      mapping - The mapping to use.
      Returns:
      The appropriate subclass of ImmutableOutputInfo with a single observation of each element.
    • getEvaluator

      public Evaluator<Regressor,RegressionEvaluation> getEvaluator()
      Description copied from interface: OutputFactory
      Gets an Evaluator suitable for measuring performance of predictions for the Output subclass.

      Evaluator instances are thread safe and immutable, and commonly this is a singleton stored in the OutputFactory implementation.

      Specified by:
      getEvaluator in interface OutputFactory<Regressor>
      Returns:
      An evaluator.
    • getTypeWitness

      public Class<Regressor> getTypeWitness()
      Description copied from interface: OutputFactory
      Gets the output class that this factory supports.
      Specified by:
      getTypeWitness in interface OutputFactory<Regressor>
      Returns:
      The output class.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getProvenance

      public OutputFactoryProvenance getProvenance()
      Specified by:
      getProvenance in interface com.oracle.labs.mlrg.olcut.provenance.Provenancable<OutputFactoryProvenance>