embed_dataset
Reduce the dataset to an n-dimensional numeric vector embedding.
Works like vectorize_dataset
, but instead of converting the input dataset to a new dataset of
N numeric columns, it creates a single column in the original dataset containing vectors (lists) of N components. In other words,
the result of vectorize_dataset
is converted to a column of embeddings, where each embedding is a numerical representation
of the corresponding row in the original dataset.
Many machine learning and AI algorithms expect their input data to be in pure numerical form, i.e. not containing categorical variables, missing values etc. This step converts arbitrary datasets, potentially containing non-numerical variables and NaNs, into this expected form. It does this by defining for each possible type of input column a transformation from non-numeric to numeric values. As an example, ordered categorical variables (ordinals) such as the day of week, may be converted into a series of numbers (0..7). Non-ordered categorical variables of low-cardinality (containing few different categories) may be expanded into multiple new columns of 0s and 1s, indicating whether each row belongs to a specific category or not. Similar transformations are applied to dates, multivalued categoricals etc.
NaNs are imputed (replaced) with an appropriate value from the corresponding column (e.g. the median in a quantitative column). In addition, a new component of 0s and 1s is added, indicating whether the original column had a missing value or not.
The resulting embeddings will almost certainly not contain the same number of components as the original dataset’s columns (as the example of categorical variables shows).
The n_components
parameter controls how many components the embeddings should have, and if this is smaller than would result
normally, a dimensionality reduction will be applied (UMAP by default).
The resulting numerical representation of the original data points aims to preserve the structure of similarities. I.e. if two original rows are similar to each other, than their (potentially reduced) numerical representations should also be similar. Equally, two very different rows should have representations that are also very different.
Usage
The following examples show how the step can be used in a recipe.
Examples
Examples
The following, simplest, example, creates a new column of vector embeddings, each containing numeric components only, and hopefully capturing the same or most of the information in the corresponding original row.
The following, simplest, example, creates a new column of vector embeddings, each containing numeric components only, and hopefully capturing the same or most of the information in the corresponding original row.
The following example will convert and reduce the input dataset to a single column of embedding vectors (lists of numbers) each having 10 components. After normalization, the date
component will be multiplied by 0.5 to reduces its weight relative to the others. The column age
on the other hand will be given more importance. Also, 15 neighbours are considered for each data point in UMAP, so that we give more importance to the similarity between nearby points and less importance to the global structure of the data when calculating the embeddings.
General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.
Inputs & Outputs
The following are the inputs expected by the step and the outputs it produces. These are generally
columns (ds.first_name
), datasets (ds
or ds[["first_name", "last_name"]]
) or models (referenced
by name e.g. "churn-clf"
).
Inputs
Inputs
An arbitrary input dataset.
Outputs
Outputs
Configuration
The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last “input” to the step, i.e. step(..., {"param": "value", ...}) -> (output)
.
Parameters
Parameters
Algorithm. The name of a supported dimensionality reduction algorithm.
Values must be one of the following:
umap
Toggle encoding of feature columns.
When enabled, Graphext will auto-convert any column types to the numeric type before
(optionally) reducing the data’s dimensionality. How this conversion is done can be
configured using the feature_encoder
option below.
Configures encoding of feature columns.
By default (null
), Graphext chooses automatically how to convert any column types the model
may not understand natively to a numeric type.
A configuration object can be passed instead to overwrite specific parameter values with respect to their default values.
Properties
Properties
Numeric encoder. Configures encoding of numeric features.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
Mean
Median
MostFrequent
Const
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
Further parameters passed to the scaler
function.
Details depend no the particular scaler used.
Boolean encoder. Configures encoding of boolean features.
Ordinal encoder. Configures encoding of categorical features that have a natural order.
Category encoder. May contain either a single configuration for all categorical variables, or two different configurations for low- and high-cardinality variables. For further details pick one of the two options below.
Options
Options
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
MostFrequent
Const
None
Maximum number of unique categories to encode. Only the N-1 most common categories will be encoded, and the rest will be grouped into a single “Others” category.
Values must be in the following range:
How to encode categories.
Values must be one of the following:
OneHot
Label
Ordinal
Binary
Frequency
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
MostFrequent
Const
None
Maximum number of unique categories to encode. Only the N-1 most common categories will be encoded, and the rest will be grouped into a single “Others” category.
Values must be in the following range:
How to encode categories.
Values must be one of the following:
OneHot
Label
Ordinal
Binary
Frequency
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
Condition for application of low- or high-cardinality configuration.
Number of unique categories below which the low_cardinality
configuration is used,
and above which the high_cardinality
configuration is used.
Values must be in the following range:
Low cardinality configuration.
Used for categories with fewer than cardinality_threshold
unique categories.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
MostFrequent
Const
None
Maximum number of unique categories to encode. Only the N-1 most common categories will be encoded, and the rest will be grouped into a single “Others” category.
Values must be in the following range:
How to encode categories.
Values must be one of the following:
OneHot
Label
Ordinal
Binary
Frequency
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
High cardinality configuration.
Used for categories with more than cardinality_threshold
unique categories.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
MostFrequent
Const
None
Maximum number of unique categories to encode. Only the N-1 most common categories will be encoded, and the rest will be grouped into a single “Others” category.
Values must be in the following range:
How to encode categories.
Values must be one of the following:
OneHot
Label
Ordinal
Binary
Frequency
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
Multilabel encoder.
Configures encoding of multivalued categorical features (variable length lists of categories,
or the semantic type list[category]
for short). May contain either a single configuration for
all multilabel variables, or two different configurations for low- and high-cardinality variables.
For further details pick one of the two options below.
Options
Options
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
How to encode categories/labels in multilabel (list[category]) columns.
Values must be one of the following:
Binarizer
TfIdf
None
Maximum number of categories/labels to encode. If a number is provided, the result of the encoding will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. When applied together with (after a) Tf-Idf encoding, this performs a kind of latent semantic analysis.
Values must be in the following range:
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
How to encode categories/labels in multilabel (list[category]) columns.
Values must be one of the following:
Binarizer
TfIdf
None
Maximum number of categories/labels to encode. If a number is provided, the result of the encoding will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. When applied together with (after a) Tf-Idf encoding, this performs a kind of latent semantic analysis.
Values must be in the following range:
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Condition for application of low- or high-cardinality configuration.
Number of unique categories below which the low_cardinality
configuration is used,
and above which the high_cardinality
configuration is used.
Values must be in the following range:
Low cardinality configuration.
Used for mulitabel columns with fewer than cardinality_threshold
unique categories/labels.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
How to encode categories/labels in multilabel (list[category]) columns.
Values must be one of the following:
Binarizer
TfIdf
None
Maximum number of categories/labels to encode. If a number is provided, the result of the encoding will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. When applied together with (after a) Tf-Idf encoding, this performs a kind of latent semantic analysis.
Values must be in the following range:
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
High cardinality configuration.
Used for categories with more than cardinality_threshold
unique categories.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
How to encode categories/labels in multilabel (list[category]) columns.
Values must be one of the following:
Binarizer
TfIdf
None
Maximum number of categories/labels to encode. If a number is provided, the result of the encoding will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. When applied together with (after a) Tf-Idf encoding, this performs a kind of latent semantic analysis.
Values must be in the following range:
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Datetime encoder. Configures encoding of datetime (timestamp) features.
Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
A list of numerical components to extract. Will create one numeric column for each component.
Array items
Array items
Each item in array.
Values must be one of the following:
day
dayofweek
dayofyear
hour
minute
month
quarter
season
second
week
weekday
weekofyear
year
A list of cyclical time features to extract. “Cycles” are numerical transformations of features that should be represented on a circle. E.g. months, ranging from 1 to 12, should be arranged such that 12 and 1 are next to each other, rather than on opposite ends of a linear scale. We represent such cyclical time features on a circle by creating two columns for each original feature: the sin and cos of the numerical feature after appropriate scaling.
Array items
Array items
Each item in array.
Values must be one of the following:
day
dayofweek
dayofyear
hour
month
Whether to include the epoch as new feature (seconds since 01/01/1970).
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
Mean
Median
MostFrequent
Const
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Embedding/vector encoder.
Configures encoding of multivalued numerical features (variable length lists of numbers, i.e. vectors, or the semantic type list[number]
for short).
Text encoder. Configures encoding of text (natural language) features. Currently only allows Tf-Idf embeddings to represent texts. If you wish to use other embeddings, e.g. semantic, Word2Vec etc., transform your text column first using another step, and then use that result instead of the original texts.
include_text_features
below to active it.Properties
Properties
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Parameters to be passed to the text encoder (Tf-Idf parameters only for now). See scikit-learn’s documentation for detailed parameters and their explanation.
How many output features to generate. The resulting Tf-Idf vectors will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. This performs a kind of latent semantic analysis. By default we will reduce to 200 components.
Values must be in the following range:
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Whether to include or ignore text columns during the processing of input data.
Enabling this will convert texts to their Tf-Idf representation. Each text will be
converted to an N-dimensional vector in which each component measures the relative
“over-representation” of a specific word (or n-gram) relative to its overall
frequency in the whole dataset. This is disabled by default because it will
often be better to convert texts explicitly using a previous step, such as
embed_text
or embed_text_with_model
.
Weights used to multiply the normalized columns/features after vectorization.
Should be a dictionary/object of {"column_name": weight, ...}
items. Will be scaled using the
parameters weights_max
, and weights_exp
before being applied. So only the relative weight of
the columns is important here, not their absolute values.
Item properties
Item properties
A "column_name": numeric_weight
pair.
Each column name must refer to an existing column in the dataset.
Examples
Examples
{"date": 0.5, "age": 2}
Weights used to multiply the normalized columns/features after vectorization.
Should be a dictionary/object of "type": weight"
items. Will be scaled using the parameters
weights_max
, and weights_exp
before being applied. So only the relative weight of the columns
is important here, not their absolute values.
Properties
Properties
Weight for columns of type Number
Weight for columns of type Datetime
Weight for columns of type Category
Weight for columns of type Ordinal
Weight for columns of type Embedding
(List[Number]
).
Weight for columns of type Multilabel
(List[Category]
).
Maximum weight to scale the normalized columns with.
Values must be in the following range:
Weight exponent.
Weights will be raised to this power before(!) scaling to weights_max
. This allows for a non-linear
mapping from input weights to those used eventually to multiply the normalized columns.
Number of neighbours. Use smaller numbers to concentrate on the local structure in the data, and larger values to focus on the more global structure.
For further details see here.
Values must be in the following range:
Minimum distance between reduced data points. Controls how tightly UMAP is allowed to pack points together in the reduced space. Smaller values will lead to points more tightly packed together (potentially useful if result is used to cluster the points). Larger values will distribute points with more space between them (which may be desirable for visualization, or to focus more on the global structure of the date).
For further details see here.
Values must be in the following range:
Dimensionality of the reduced data.
Values must be in the following range:
Metric to use for measuring similarity between data points.
Values must be one of the following:
euclidean
manhattan
chebyshev
minkowski
canberra
braycurtis
haversine
mahalanobis
wminkowski
seuclidean
cosine
correlation
hamming
jaccard
dice
russellrao
kulsinski
rogerstanimoto
sokalmichener
sokalsneath
yule
Number of training iterations used in optimizing the embedding.
Larger values result in more accurate embeddings. If null
is specified a value will be
selected based on the size of the input dataset (200 for large datasets, 500 for small).
How to initialize the low dimensional embedding.
When “spectral”, uses a (relatively expensive) spectral embedding. “pca” uses the first n_components
from a principal component analysis. “tswspectral” is a cheaper alternative to “spectral”. When “random”,
assigns initial embedding positions at random. This uses the least amount of memory and time but may make UMAP
slower to converge on the optimal embedding. “auto” selects between “spectral” and “random” automatically
depending on the size of the dataset.
Values must be one of the following:
spectral
pca
tswspectral
random
auto
Avoid excessive memory use.
For some datasets nearest neighbor computations can consume a lot of memory. If you find
the step is failing due to memory constraints, consider setting this option to true
.
This approach is more computationally expensive, but avoids excessive memory use. Setting
it to “auto”, will enable this mode automatically depending on the size of the dataset.
Values must be one of the following:
True
False
auto
None
Target variable (labels) for supervised dimensionality reduction. Name of the column that contains your target values (labels).
Weighting factor between features and target. A value of 0.0 weights entirely on data, and a value of 1.0 weights entirely on target. The default of 0.5 balances the weighting equally between data and target.
Try to better preserve local densities in the data. Specifies whether the density-augmented objective of densMAP should be used for optimization. Turning on this option generates an embedding where the local densities are encouraged to be correlated with those in the original space.
Strength of local density preservation. Controls the regularization weight of the density correlation term in densMAP. Higher values prioritize density preservation over the UMAP objective, and vice versa for values closer to zero. Setting this parameter to zero is equivalent to running the original UMAP algorithm.
Drop duplicate rows before embedding.
If you have more duplicates than you have n_neighbors
you can have the identical data points lying
in different regions of your space. It also violates the definition of a metric. This option will
remove duplicates before embedding, and then map the original data points back to the reduced space. Duplicate
data points will be placed in the exact same location as the original data points.
A random number to initialize the algorithm for reproducibility.
Maintain links for n nearest neighbours only in graph.
Values must be in the following range: