Registry / aws / sagemaker-scikit-learn-extension

sagemaker-scikit-learn-extension

JSON →
library2.5.0pypypiunverified

An open-source library that extends scikit-learn functionalities, specifically designed for use with Amazon SageMaker. It provides robust encoders, time series feature extractors, and other transformers to streamline machine learning workflows on SageMaker. The current version is 2.5.0, with regular updates typically released every few months, focusing on new features and bug fixes.

pip install sagemaker-scikit-learn-extension
INSTALL
IMPORT
SIG · SAGEMAKER-SCIKIT-L
S
sagemaker-scikit-learn-extension
awspythonv2.5.0
Install
2.5s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.5s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RobustOrdinalEncoder
from sagemaker_sklearn_extension.preprocessing import RobustOrdinalEncoder
from sagemaker_sklearn_extension import RobustOrdinalEncoder

This quickstart demonstrates how to use the `RobustOrdinalEncoder` to encode categorical data. It handles unknown categories by mapping them to a specified value, preventing errors that might occur with standard ordinal encoders when encountering new data. The example shows fitting and transforming a Pandas DataFrame column.

import pandas as pd from sagemaker_sklearn_extension.encoders import RobustOrdinalEncoder data = pd.DataFrame({ 'category': ['A', 'B', 'A', 'C', 'B', 'A', None, 'D'], 'value': [10, 20, 15, 25, 30, 12, 18, 22] }) # Initialize the encoder # `max_categories` handles categories exceeding this limit as unseen. # `handle_unknown='use_encoded_value'` ensures a specific value for unseen/nan. encoder = RobustOrdinalEncoder(max_categories=3, handle_unknown='use_encoded_value', unknown_value=-1) # Fit and transform the 'category' column encoded_data = encoder.fit_transform(data[['category']]) print("Original Data:\n", data) print("\nEncoded 'category' column:\n", encoded_data.reshape(-1)) print("\nLearned categories:", encoder.categories_[0])
Debug
Known issues
breakingVersion 2.0.0 introduced breaking changes by updating core dependencies. It requires `scikit-learn>=0.23,<1.2` and `mlio>=0.5,<0.6`. Earlier versions of these libraries are no longer supported.
fix
Ensure your environment has `scikit-learn` and `mlio` installed within the specified version ranges. Upgrade them if necessary: `pip install 'scikit-learn>=0.23,<1.2' 'mlio>=0.5,<0.6'`.
affects: >=2.0.0
gotchaWhen serializing estimators that use custom functions (like `DateTimeDefinitions` in `TSFreshExtractor`), avoid using lambda functions. Version 2.1.0 addressed `pickle` issues by recommending named functions for better serialization stability.
fix
Always use named functions instead of anonymous lambda functions when defining custom logic within estimators that need to be serialized (e.g., using `pickle` for model deployment).
affects: All
gotchaThe `TSFreshExtractor`'s parallelism feature is explicitly disabled when running in a `sagemaker_serve` execution environment. This is by design to prevent resource contention during inference, but it means feature extraction might be slower in such contexts.
fix
Be aware of this limitation when deploying models using `TSFreshExtractor` to SageMaker inference endpoints. Optimize input data or pre-compute features if latency becomes an issue in `sagemaker_serve` environments.
affects: >=2.5.0
breakingVersion 2.5.0 includes bug fixes related to `tsfresh` dependency. The library now expects `tsfresh>=0.17.0,<0.18.0`. Incompatible versions of `tsfresh` may lead to broken functionality or runtime errors, especially with `TSFreshExtractor`.
fix
Pin your `tsfresh` dependency to the required range: `pip install 'tsfresh>=0.17.0,<0.18.0'`.
affects: >=2.5.0
Upgrade
Version history
2.5.0latest on PyPI · released Feb 18, 2022
Audit
Dependencies
scikit-learnrequiredCore dependency for scikit-learn compatible estimators.
mliorequiredInternal data handling and processing library.
tsfreshrequiredUsed by TSFreshExtractor for time series feature engineering.
pandasrequiredData manipulation for various transformers.
Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
1
Resources