jsat.datatransform
Class NumericalToHistogram
- java.lang.Object
-
- jsat.datatransform.NumericalToHistogram
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DataTransform
public class NumericalToHistogram extends java.lang.Object implements DataTransform
This transform converts numerical features into categorical ones via a simple histogram. Bins will be created for each numeric feature of equal sizes. Each numeric feature will be converted to the same number of bins.
This transform will handle missing values by simply ignoring them, and leaving the value missing in the transformed categorical variable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description NumericalToHistogram()Creates a new transform which will use at most 25 bins when converting numeric features.NumericalToHistogram(DataSet dataSet)Creates a new transform which will use O(sqrt(n)) bins for each numeric feature, where n is the number of data points in the dataset.NumericalToHistogram(DataSet dataSet, int n)Creates a new transform which will use the specified number of bins for each numeric feature.NumericalToHistogram(int n)Creates a new transform which will use at most the specified number of bins
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description NumericalToHistogramclone()voidfit(DataSet dataSet)Fits this transform to the given dataset.intgetNumberOfBins()static DistributionguessNumberOfBins(DataSet data)Attempts to guess the number of bins to usevoidsetNumberOfBins(int n)Sets the maximum number of histogram bins to use when creating the categorical version of numeric features.DataPointtransform(DataPoint dp)Returns a new data point that is a transformation of the original data point.
-
-
-
Constructor Detail
-
NumericalToHistogram
public NumericalToHistogram()
Creates a new transform which will use at most 25 bins when converting numeric features. This may not be optimal for any given dataset
-
NumericalToHistogram
public NumericalToHistogram(DataSet dataSet)
Creates a new transform which will use O(sqrt(n)) bins for each numeric feature, where n is the number of data points in the dataset.- Parameters:
dataSet- the data set to create the transform from
-
NumericalToHistogram
public NumericalToHistogram(int n)
Creates a new transform which will use at most the specified number of bins- Parameters:
n- the number of bins to create
-
NumericalToHistogram
public NumericalToHistogram(DataSet dataSet, int n)
Creates a new transform which will use the specified number of bins for each numeric feature.- Parameters:
dataSet- the data set to create the transform fromn- the number of bins to create
-
-
Method Detail
-
fit
public void fit(DataSet dataSet)
Description copied from interface:DataTransformFits this transform to the given dataset. Some transforms can only be learned from classification or regression datasets. If an incompatible dataset type is given, aFailedToFitExceptionexception may be thrown.- Specified by:
fitin interfaceDataTransform- Parameters:
dataSet- the dataset to fir this transform to
-
setNumberOfBins
public void setNumberOfBins(int n)
Sets the maximum number of histogram bins to use when creating the categorical version of numeric features.- Parameters:
n- the number of bins to create
-
getNumberOfBins
public int getNumberOfBins()
- Returns:
- the maximum number of bins to create
-
guessNumberOfBins
public static Distribution guessNumberOfBins(DataSet data)
Attempts to guess the number of bins to use- Parameters:
data- the dataset to be transforms- Returns:
- a distribution of the guess
-
transform
public DataPoint transform(DataPoint dp)
Description copied from interface:DataTransformReturns a new data point that is a transformation of the original data point. This new data point is a different object, but may contain the same references as the original data point. It is not guaranteed that you can mutate the transformed point without having a side effect on the original point.- Specified by:
transformin interfaceDataTransform- Parameters:
dp- the data point to apply a transformation to- Returns:
- a transformed data point
-
clone
public NumericalToHistogram clone()
- Specified by:
clonein interfaceDataTransform- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG