Skip to main content
Dimensionality reduction with “Uniform Manifold Approximation and Projection” (UMAP) Generates numeric embeddings (vectors) of the input data with reduced dimensionality, preserving local and global similarities between data points. Can be used for visualisation, for example, to arrange data in 2 dimensions according to their similarity, or to create nearest neighbour graphs/networks (also see step link_embeddings in the latter case). Can be used in supervised mode (providing a target column as parameter) or unsupervised (without target). The output will always be a new column with the trained model’s predictions on the training data, as well as a saved and named model file that can be used in other projects for prediction of new data.

Usage

The following examples show how the step can be used in a recipe.

Examples

  • Example 1
  • Example 2
  • Signature
Train an unsupervised UMAP model.
train_embeddings(ds) -> (ds.predicted, model)

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").
ds
dataset
required
Should contain the target column and the feature columns you wish to use in the model.
predicted
column[list[number]]
required
Column containing results of the model.
model
file[model_dimensionality_reduction[ds]]
required
Zip file containing the trained model and associated information.
info
file.hidden
required

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

target
string (ds.column)
Target variable. Name of the column that contains your target values.
encode_features
boolean
default:"true"
Toggle encoding of feature columns. When enabled, Graphext will auto-convert any column types to the numeric type before fitting the model. How this conversion is done can be configured using the feature_encoder option below.
If disabled, any model trained in this step will assume that input data is already in an appropriate format (e.g. numerical and not containing any missing values).
feature_encoder
[null, object]
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.
number
object
Numeric encoder. Configures encoding of numeric features.
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
imputer
[null, string]
Whether and how to impute (replace/fill) missing values.Values must be one of the following:
  • Mean
  • Median
  • MostFrequent
  • Const
  • None
scaler
[null, string]
Whether and how to scale the final numerical values (across a single column).Values must be one of the following:
  • Standard
  • Robust
  • KNN
  • None
scaler_params
object
Further parameters passed to the scaler function. Details depend no the particular scaler used.
bool
object
Boolean encoder. Configures encoding of boolean features.
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
imputer
[null, string]
Whether and how to impute (replace/fill) missing values.Values must be one of the following:
  • MostFrequent
  • Const
  • None
ordinal
object
Ordinal encoder. Configures encoding of categorical features that have a natural order.
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
imputer
[null, string]
Whether and how to impute (replace/fill) missing values.Values must be one of the following:
  • MostFrequent
  • Const
  • None
category
[object, object]
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.
  • Simple category encoder
  • Conditional category encoder
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
imputer
[null, string]
Whether and how to impute (replace/fill) missing values.Values must be one of the following:
  • MostFrequent
  • Const
  • None
max_categories
[null, integer]
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:
1max_categories < inf
encoder
[null, string]
How to encode categories.Values must be one of the following:OneHot Label Ordinal Binary Frequency None
scaler
[null, string]
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
[object, object]
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.
  • Simple multilabel encoder
  • Conditional multilabel encoder
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
encoder
[null, string]
How to encode categories/labels in multilabel (list[category]) columns.Values must be one of the following:
  • Binarizer
  • TfIdf
  • None
max_categories
[null, integer]
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:
2max_categories < inf
scaler
[null, string]
How to scale the encoded (numerical columns).Values must be one of the following:
  • Euclidean
  • KNN
  • Norm
  • None
datetime
object
Datetime encoder. Configures encoding of datetime (timestamp) features.
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
components
array[string]
A list of numerical components to extract. Will create one numeric column for each component.
Item
string
Each item in array.Values must be one of the following:day dayofweek dayofyear hour minute month quarter season second week weekday weekofyear year
cycles
array[string]
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.
Item
string
Each item in array.Values must be one of the following:
  • day
  • dayofweek
  • dayofyear
  • hour
  • month
epoch
[null, boolean]
Whether to include the epoch as new feature (seconds since 01/01/1970).
imputer
[null, string]
Whether and how to impute (replace/fill) missing values.Values must be one of the following:
  • Mean
  • Median
  • MostFrequent
  • Const
  • None
component_scaler
[null, string]
Whether and how to scale the final numerical values (across a single column).Values must be one of the following:
  • Standard
  • Robust
  • KNN
  • None
vector_scaler
[null, string]
How to scale the encoded (numerical columns).Values must be one of the following:
  • Euclidean
  • KNN
  • Norm
  • None
embedding
object
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).
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
scaler
[null, string]
How to scale the encoded (numerical columns).Values must be one of the following:
  • Euclidean
  • KNN
  • Norm
  • None
text
object
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.
Texts are excluded by default from the overall encoding of the dataset. See parameter include_text_features below to active it.
indicate_missing
boolean
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
encoder_params
object
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.
n_components
integer
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:
2n_components1024
scaler
[null, string]
How to scale the encoded (numerical columns).Values must be one of the following:
  • Euclidean
  • KNN
  • Norm
  • None
include_text_features
boolean
default:"false"
Whether to include or ignore text columns during the processing of input data. Enabling this will convert texts to their TfIdf 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.
params
object
Model parameters. See official UMAP documentation for details.
n_neighbors
integer
default:"15"
Number of neighbors. This determines the number of neighboring points used in local approximations of manifold structure. Larger values will result in more global structure being preserved at the loss of detailed local structure. In general this parameter should often be in the range 5 to 50, with a choice of 10 to 15 being a sensible default.Values must be in the following range:
1n_neighbors < inf
min_dist
number
default:"0.1"
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:
0min_dist < inf
n_components
integer
Number of n_components. Allows the user to determine the dimensionality of the reduced dimension space we will be embedding the data into.Values must be in the following range:
1n_components < inf
metric
string
default:"euclidean"
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
n_epochs
[integer, null]
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).
init
string
default:"spectral"
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.Values must be one of the following:
  • spectral
  • pca
  • tswspectral
  • random
low_memory
boolean
default:"false"
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.
target_weight
number
default:"0.5"
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.
seed
integer
Seed for random number generator ensuring reproducibility.Values must be in the following range:
0seed < inf
I