Safe Haskell | None |
---|---|
Language | Haskell2010 |
DataFrame.Hasktorch
Documentation
toTensor :: DataFrame -> Tensor Source #
Converts a dataframe to a floating-point tensor.
This function converts all columns in the dataframe to floats and creates a tensor suitable for machine learning operations. The tensor dimensions are determined by the dataframe's shape.
Dimensional behavior
- Multi-column dataframe: Creates a 2D tensor with shape
[rows, columns]
- Single-column dataframe: Creates a 1D tensor with shape
[rows]
Conversion process
- Converts the dataframe to a float matrix using
toFloatMatrix
- Flattens the matrix features into a 1D representation
- Reshapes into the appropriate tensor dimensions
Throws
DataFrameException
- if any column cannot be converted to float
Examples
>>>
toTensor df -- where df has shape (100, 5)
Tensor with shape [100, 5]
>>>
toTensor df -- where df has shape (100, 1)
Tensor with shape [100]
See also
toIntTensor
- for integer tensor conversion
toIntTensor :: DataFrame -> Tensor Source #
Converts a dataframe to an integer tensor.
This function converts all columns in the dataframe to integers and creates a tensor suitable for machine learning operations (e.g., classification labels, discrete features). The tensor dimensions are determined by the dataframe's shape.
Dimensional behavior
- Multi-column dataframe: Creates a 2D tensor with shape
[rows, columns]
- Single-column dataframe: Creates a 1D tensor with shape
[rows]
Conversion process
- Converts the dataframe to an int matrix using
toIntMatrix
- Flattens the matrix features into a 1D representation
- Reshapes into the appropriate tensor dimensions
Throws
DataFrameException
- if any column cannot be converted to int
Examples
>>>
toIntTensor labelsDf -- where labelsDf has shape (100, 1)
Tensor with shape [100]
>>>
toIntTensor featuresDf -- where featuresDf has shape (100, 3)
Tensor with shape [100, 3]
Note
Floating-point values in the dataframe will be rounded to the nearest integer.
See toIntMatrix
for details on the conversion behavior.
See also
toTensor
- for floating-point tensor conversion