snowflake.ml.modeling.neighbors.NeighborhoodComponentsAnalysis

class snowflake.ml.modeling.neighbors.NeighborhoodComponentsAnalysis(*, n_components=None, init='auto', warm_start=False, max_iter=50, tol=1e-05, callback=None, verbose=0, random_state=None, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, passthrough_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)

Bases: BaseTransformer

Neighborhood Components Analysis For more details on this class, see sklearn.neighbors.NeighborhoodComponentsAnalysis

input_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols, sample_weight_col, and passthrough_cols parameters are considered input columns. Input columns can also be set after initialization with the set_input_cols method.

label_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain labels. Label columns must be specified with this parameter during initialization or with the set_label_cols method before fitting.

output_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols must match the expected number of output columns from the specific predictor or transformer class used. If you omit this parameter, output column names are derived by adding an OUTPUT_ prefix to the label column names for supervised estimators, or OUTPUT_<IDX>for unsupervised estimators. These inferred output column names work for predictors, but output_cols must be set explicitly for transformers. In general, explicitly specifying output column names is clearer, especially if you don’t specify the input column names. To transform in place, pass the same names for input_cols and output_cols. be set explicitly for transformers. Output columns can also be set after initialization with the set_output_cols method.

sample_weight_col: Optional[str]

A string representing the column name containing the sample weights. This argument is only required when working with weighted datasets. Sample weight column can also be set after initialization with the set_sample_weight_col method.

passthrough_cols: Optional[Union[str, List[str]]]

A string or a list of strings indicating column names to be excluded from any operations (such as train, transform, or inference). These specified column(s) will remain untouched throughout the process. This option is helpful in scenarios requiring automatic input_cols inference, but need to avoid using specific columns, like index columns, during training or inference. Passthrough columns can also be set after initialization with the set_passthrough_cols method.

drop_input_cols: Optional[bool], default=False

If set, the response of predict(), transform() methods will not contain input columns.

n_components: int, default=None

Preferred dimensionality of the projected space. If None it will be set to n_features.

init: {‘auto’, ‘pca’, ‘lda’, ‘identity’, ‘random’} or ndarray of shape (n_features_a, n_features_b), default=’auto’

Initialization of the linear transformation. Possible options are ‘auto’, ‘pca’, ‘lda’, ‘identity’, ‘random’, and a numpy array of shape (n_features_a, n_features_b).

  • ‘auto’

    Depending on n_components, the most reasonable initialization will be chosen. If n_components <= n_classes we use ‘lda’, as it uses labels information. If not, but n_components < min(n_features, n_samples), we use ‘pca’, as it projects data in meaningful directions (those of higher variance). Otherwise, we just use ‘identity’.

  • ‘pca’

    n_components principal components of the inputs passed to fit() will be used to initialize the transformation. (See PCA)

  • ‘lda’

    min(n_components, n_classes) most discriminative components of the inputs passed to fit() will be used to initialize the transformation. (If n_components > n_classes, the rest of the components will be zero.) (See LinearDiscriminantAnalysis)

  • ‘identity’

    If n_components is strictly smaller than the dimensionality of the inputs passed to fit(), the identity matrix will be truncated to the first n_components rows.

  • ‘random’

    The initial transformation will be a random array of shape (n_components, n_features). Each value is sampled from the standard normal distribution.

  • numpy array

    n_features_b must match the dimensionality of the inputs passed to fit() and n_features_a must be less than or equal to that. If n_components is not None, n_features_a must match it.

warm_start: bool, default=False

If True and fit() has been called before, the solution of the previous call to fit() is used as the initial linear transformation (n_components and init will be ignored).

max_iter: int, default=50

Maximum number of iterations in the optimization.

tol: float, default=1e-5

Convergence tolerance for the optimization.

callback: callable, default=None

If not None, this function is called after every iteration of the optimizer, taking as arguments the current solution (flattened transformation matrix) and the number of iterations. This might be useful in case one wants to examine or store the transformation found after each iteration.

verbose: int, default=0

If 0, no progress messages will be printed. If 1, progress messages will be printed to stdout. If > 1, progress messages will be printed and the disp parameter of scipy.optimize.minimize() will be set to verbose - 2.

random_state: int or numpy.RandomState, default=None

A pseudo random number generator object or a seed for it if int. If init=’random’, random_state is used to initialize the random transformation. If init=’pca’, random_state is passed as an argument to PCA when initializing the transformation. Pass an int for reproducible results across multiple function calls. See Glossary.

Methods

fit(dataset)

Fit the model according to the given training data For more details on this function, see sklearn.neighbors.NeighborhoodComponentsAnalysis.fit

get_input_cols()

Input columns getter.

get_label_cols()

Label column getter.

get_output_cols()

Output columns getter.

get_params([deep])

Get parameters for this transformer.

get_passthrough_cols()

Passthrough columns getter.

get_sample_weight_col()

Sample weight column getter.

get_sklearn_args([default_sklearn_obj, ...])

Get sklearn keyword arguments.

set_drop_input_cols([drop_input_cols])

set_input_cols(input_cols)

Input columns setter.

set_label_cols(label_cols)

Label column setter.

set_output_cols(output_cols)

Output columns setter.

set_params(**params)

Set the parameters of this transformer.

set_passthrough_cols(passthrough_cols)

Passthrough columns setter.

set_sample_weight_col(sample_weight_col)

Sample weight column setter.

to_sklearn()

Get sklearn.neighbors.NeighborhoodComponentsAnalysis object.

transform(dataset)

Apply the learned transformation to the given data For more details on this function, see sklearn.neighbors.NeighborhoodComponentsAnalysis.transform

Attributes

model_signatures

Returns model signature of current class.