dataframe-hasktorch-0.1.0.2: Converts between dataframes and hasktorch tensors
Safe HaskellNone
LanguageHaskell2010

DataFrame.Hasktorch

Synopsis

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

Expand
  • Multi-column dataframe: Creates a 2D tensor with shape [rows, columns]
  • Single-column dataframe: Creates a 1D tensor with shape [rows]

Conversion process

Expand
  1. Converts the dataframe to a float matrix using toFloatMatrix
  2. Flattens the matrix features into a 1D representation
  3. Reshapes into the appropriate tensor dimensions

Throws

Expand
  • DataFrameException - if any column cannot be converted to float

Examples

Expand
>>> 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

Expand

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

Expand
  • Multi-column dataframe: Creates a 2D tensor with shape [rows, columns]
  • Single-column dataframe: Creates a 1D tensor with shape [rows]

Conversion process

Expand
  1. Converts the dataframe to an int matrix using toIntMatrix
  2. Flattens the matrix features into a 1D representation
  3. Reshapes into the appropriate tensor dimensions

Throws

Expand
  • DataFrameException - if any column cannot be converted to int

Examples

Expand
>>> 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

Expand

Floating-point values in the dataframe will be rounded to the nearest integer. See toIntMatrix for details on the conversion behavior.

See also

Expand
  • toTensor - for floating-point tensor conversion