SeldonClassifier

class SeldonClassifier(api_key=None, *, host=None, dataset_name='dataset', model='seldon-small', strategy=None, memory_optimization=False, preprocess=True, n_groups=None, column_names=None, selected_features=None, timeout_s=900, metadata=None, user=None, api_version=None, default_headers=None, upload_mode=False, ttl_days=None)

Sklearn-compatible classifier using the Neuralk API.

This classifier connects to either the Neuralk cloud API or an on-premise Seldon server. It follows the standard scikit-learn classifier interface and only accepts classification targets (binary or multiclass).

Parameters:
  • api_key (str, optional) – API key for authentication (e.g., “nk_live_xxxx”). Required for cloud mode. If not provided, reads from the NEURALK_API_KEY environment variable. Optional for on-premise mode.

  • host (str, optional) – Base URL of the server. If not provided, uses the Neuralk cloud endpoint. When provided, enables on-premise mode which doesn’t require an API key.

  • dataset_name (str, default="dataset") – Name identifier for the dataset used in API requests.

  • model (str, default="seldon-small") – Model identifier to use for inference. Available models: - “seldon-flash”: Fastest model, optimized for low latency - “seldon-small”: Balanced model (default) - “seldon-large”: Most accurate model, recommended for complex tasks

  • strategy (str, optional) – Prompting strategy for group-wise processing.

  • memory_optimization (bool, default=False) – Enable server-side memory optimization.

  • preprocess (bool, default=True) – Enable server-side data preprocessing.

  • n_groups (int, optional) – Number of groups for the prompting strategy.

  • column_names (List[str], optional) – Column names corresponding to features in X.

  • selected_features (List[str], optional) – Features to use for grouping strategies.

  • timeout_s (int, default=900) – Request timeout in seconds.

  • metadata (dict, optional) – Optional metadata to include with requests.

  • user (str, optional) – Optional user identifier for request tracking.

  • api_version (str, optional) – Optional API version string to send as ‘Nicl-Version’ header.

  • default_headers (dict, optional) – Optional default headers to include with every request.

  • upload_mode (bool, default=False) – When True, each prediction first uploads the dataset (train + test + settings) to Neuralk storage, then runs inference by reference (“drop & predict”): the long-lived inference request carries no payload, which is more robust for large datasets and unstable connections. The uploaded dataset stays reusable until its retention tier expires (see ttl_days); its id is available as last_dataset_id_ after a prediction. Cloud only.

  • ttl_days (int, optional) – Retention tier in days for datasets uploaded in upload_mode: one of 1, 7, 30 or 90. Defaults to the server default (90 days). Only used when upload_mode=True.

Examples

>>> from neuralk import SeldonClassifier
>>> clf = SeldonClassifier(api_key="nk_live_xxxx")
>>> clf.fit(X_train, y_train)
>>> predictions = clf.predict(X_test)
>>> probabilities = clf.predict_proba(X_test)

Drop & predict with a 7-day retention:

>>> clf = SeldonClassifier(api_key="nk_live_xxxx", upload_mode=True, ttl_days=7)
>>> clf.fit(X_train, y_train)
>>> predictions = clf.predict(X_test)
>>> clf.last_dataset_id_
'auto/3f2a....tar.zst'