tensor_conversion
¶
Functions:
Name | Description |
---|---|
deque2rolling_tensor |
Convert a dictionary to a rolling tensor. |
df2tensor |
Convert a dataframe to a tensor. |
dict2tensor |
Convert a dictionary to a tensor. |
float2tensor |
Convert a float to a tensor. |
labels2onehot |
Convert a label or a list of labels to a one-hot encoded tensor. |
deque2rolling_tensor
¶
Convert a dictionary to a rolling tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window
|
Deque
|
Rolling window. |
required |
device
|
Device. |
'cpu'
|
|
dtype
|
Dtype. |
float32
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
|
Source code in deep_river/utils/tensor_conversion.py
df2tensor
¶
df2tensor(
X: DataFrame,
features: SortedSet,
default_value: float = 0,
device="cpu",
dtype=float32,
) -> Tensor
Convert a dataframe to a tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Dataframe. |
required |
features
|
SortedSet
|
Set of possible features. |
required |
default_value
|
float
|
Value to use for features not present in x. |
0
|
device
|
Device. |
'cpu'
|
|
dtype
|
Dtype. |
float32
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
|
Source code in deep_river/utils/tensor_conversion.py
dict2tensor
¶
dict2tensor(
x: dict,
features: SortedSet,
default_value: float = 0,
device: str = "cpu",
dtype: dtype = float32,
) -> Tensor
Convert a dictionary to a tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Dictionary. |
required |
features
|
SortedSet
|
Set of possible features. |
required |
default_value
|
float
|
Value to use for features not present in x. |
0
|
device
|
str
|
Device. |
'cpu'
|
dtype
|
dtype
|
Dtype. |
float32
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
|
Source code in deep_river/utils/tensor_conversion.py
float2tensor
¶
Convert a float to a tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Union[float, int, RegTarget, dict]
|
Float. |
required |
device
|
Device. |
'cpu'
|
|
dtype
|
Dtype. |
float32
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
|
Source code in deep_river/utils/tensor_conversion.py
labels2onehot
¶
labels2onehot(
y: Union[ClfTarget, Series],
classes: SortedSet[ClfTarget],
n_classes: Optional[int] = None,
device="cpu",
dtype=float32,
) -> Tensor
Convert a label or a list of labels to a one-hot encoded tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Union[ClfTarget, Series]
|
Label or list of labels. |
required |
classes
|
SortedSet[ClfTarget]
|
Classes. |
required |
n_classes
|
Optional[int]
|
Number of classes. |
None
|
device
|
Device. |
'cpu'
|
|
dtype
|
Dtype. |
float32
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
|