Class CategoricalMeasure

java.lang.Object
smile.data.measure.CategoricalMeasure
All Implemented Interfaces:
Serializable, Measure
Direct Known Subclasses:
NominalScale, OrdinalScale

public abstract class CategoricalMeasure extends Object implements Measure
Categorical data can be stored into groups or categories with the aid of names or labels. Also known as qualitative data, each element of a categorical data can be placed in only one category according to its qualities, where each of the categories is mutually exclusive.

Categorical data may be subdivided into nominal data and ordinal data.

Both integer and string variables can be made into categorical measure, but a categorical measure's levels will always be string values.

See Also:
  • Constructor Details

    • CategoricalMeasure

      public CategoricalMeasure(String... levels)
      Constructor.
      Parameters:
      levels - the levels of discrete values.
    • CategoricalMeasure

      public CategoricalMeasure(List<String> levels)
      Constructor.
      Parameters:
      levels - the levels of discrete values.
    • CategoricalMeasure

      public CategoricalMeasure(int[] values)
      Constructor.
      Parameters:
      values - the valid values.
    • CategoricalMeasure

      public CategoricalMeasure(int[] values, String[] levels)
      Constructor.
      Parameters:
      values - the valid values.
      levels - the levels of discrete values.
  • Method Details

    • size

      public int size()
      Returns the number of levels.
      Returns:
      the number of levels.
    • values

      public int[] values()
      Returns the valid value set.
      Returns:
      the valid value set.
    • levels

      public String[] levels()
      Returns the levels.
      Returns:
      the levels.
    • level

      public String level(int value)
      Returns the level string representation.
      Parameters:
      value - the level value.
      Returns:
      the level string representation.
    • factor

      public int factor(int value)
      Returns the factor value (in range [0, size)) of level.
      Parameters:
      value - the level value.
      Returns:
      the factor value.
    • type

      public DataType type()
      Returns the data type that is suitable for this measure scale.
      Returns:
      the data type that is suitable for this measure scale.
    • toString

      public String toString(int value)
      Returns the string value of a level.
      Parameters:
      value - the level value.
      Returns:
      the string value of a level.
    • toString

      public String toString(Object o)
      Description copied from interface: Measure
      Returns the string representation of an object in the measure.
      Specified by:
      toString in interface Measure
      Parameters:
      o - an object.
      Returns:
      the string representation
    • valueOf

      public Number valueOf(String s)
      Description copied from interface: Measure
      Returns a measurement value object represented by the argument string s.
      Specified by:
      valueOf in interface Measure
      Parameters:
      s - a string.
      Returns:
      the parsed value.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object