skada.utils.source_target_merge

skada.utils.source_target_merge(*arrays, sample_domain: ndarray | None = None) Sequence[ndarray][source]

Merge source and target domain data based on sample domain labels.

Parameters:
*arrayssequence of array-like

(, n_features). The number of arrays must be even since we consider pairs of source-target arrays each time. Each pair should have at least one non-empty array. In each pair the first array is considered as the source and the second as the target. If one of the array is None or empty, it's value will be inferred from the other array and the sample_domain (depending on the type of the arrays, they'll have a value of -1 or nan).

sample_domainarray-like of shape (n_samples,)

Array specifying the domain labels for each sample. If None or empty the domain labels will be inferred from the the *arrays, being a default source and target domain (depending on the type of the arrays, they'll have a value of 1 or -2).

Returns:
mergeslist, length=len(arrays)/2

List containing merged data based on the sample domain labels.

sample_domainarray-like of shape (n_samples,)

Array specifying the domain labels for each sample.

Examples

>>> X_source = np.array([[1, 2], [3, 4], [5, 6]])
>>> X_target = np.array([[7, 8], [9, 10]])
>>> X, sample_domain = source_target_merge(X_source, X_target)
>>> X
array([[ 1,  2],
       [ 3,  4],
       [ 5,  6],
       [ 7,  8],
       [ 9, 10]])
>>> sample_domain
array([ 1.,  1.,  1., -2., -2.])
>>> X_source = np.array([[1, 2], [3, 4], [5, 6]])
>>> X_target = np.array([[7, 8], [9, 10]])
>>> y_source = np.array([0, 1, 1])
>>> y_target = None
>>> X, y, _ = source_target_merge(X_source, X_target, y_source, y_target)
>>> X
array([[ 1,  2],
       [ 3,  4],
       [ 5,  6],
       [ 7,  8],
       [ 9, 10]])
>>> y
array([ 0,  1,  1, -1, -1])