-
Notifications
You must be signed in to change notification settings - Fork 14
Support kwargs in predict() and predict_proba() #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a38f8cd
5eaf768
4be5989
13f1af8
44c1588
21ef07c
7cb3cb2
5857fe2
d29582a
2afba82
ed5d97f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -558,7 +558,6 @@ def predict_real_time( | |
test_data_image_column: Optional[str] = None, | ||
accept: str = "application/x-parquet", | ||
inference_kwargs: Optional[Dict[str, Any]] = None, | ||
**kwargs, | ||
) -> Union[pd.DataFrame, pd.Series]: | ||
""" | ||
Predict with the deployed SageMaker endpoint. A deployed SageMaker endpoint is required. | ||
|
@@ -595,7 +594,6 @@ def predict_proba_real_time( | |
test_data_image_column: Optional[str] = None, | ||
accept: str = "application/x-parquet", | ||
inference_kwargs: Optional[Dict[str, Any]] = None, | ||
**kwargs, | ||
) -> Union[pd.DataFrame, pd.Series]: | ||
""" | ||
Predict probability with the deployed SageMaker endpoint. A deployed SageMaker endpoint is required. | ||
|
@@ -704,6 +702,7 @@ def predict( | |
instance_count: int = 1, | ||
custom_image_uri: Optional[str] = None, | ||
wait: bool = True, | ||
inference_kwargs: Optional[Dict[str, Any]] = None, | ||
download: bool = True, | ||
persist: bool = True, | ||
save_path: Optional[str] = None, | ||
|
@@ -783,6 +782,7 @@ def predict( | |
instance_count=instance_count, | ||
custom_image_uri=custom_image_uri, | ||
wait=wait, | ||
inference_kwargs=inference_kwargs, | ||
download=download, | ||
persist=persist, | ||
save_path=save_path, | ||
|
@@ -805,6 +805,7 @@ def predict_proba( | |
instance_count: int = 1, | ||
custom_image_uri: Optional[str] = None, | ||
wait: bool = True, | ||
inference_kwargs: Optional[Dict[str, Any]] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add docstring |
||
download: bool = True, | ||
persist: bool = True, | ||
save_path: Optional[str] = None, | ||
|
@@ -889,6 +890,7 @@ def predict_proba( | |
instance_count=instance_count, | ||
custom_image_uri=custom_image_uri, | ||
wait=wait, | ||
inference_kwargs=inference_kwargs, | ||
download=download, | ||
persist=persist, | ||
save_path=save_path, | ||
|
@@ -1133,6 +1135,7 @@ def _predict( | |
instance_count=1, | ||
custom_image_uri=None, | ||
wait=True, | ||
inference_kwargs=None, | ||
download=True, | ||
persist=True, | ||
save_path=None, | ||
|
@@ -1256,6 +1259,7 @@ def _predict( | |
transformer_kwargs=transformer_kwargs, | ||
model_kwargs=model_kwargs, | ||
repack_model=repack_model, | ||
inference_kwargs=inference_kwargs, | ||
**transform_kwargs, | ||
) | ||
self._batch_transform_jobs[job_name] = batch_transform_job | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ class TimeSeriesSagemakerBackend(SagemakerBackend): | |
def _preprocess_data( | ||
self, | ||
data: Union[pd.DataFrame, str], | ||
id_column: str, | ||
timestamp_column: str, | ||
target: str, | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
target: Optional[str] = None, | ||
static_features: Optional[Union[pd.DataFrame, str]] = None, | ||
) -> pd.DataFrame: | ||
if isinstance(data, str): | ||
|
@@ -27,12 +27,15 @@ def _preprocess_data( | |
cols = data.columns.to_list() | ||
# Make sure id and timestamp columns are the first two columns, and target column is in the end | ||
# This is to ensure in the container we know how to find id and timestamp columns, and whether there are static features being merged | ||
timestamp_index = cols.index(timestamp_column) | ||
cols.insert(0, cols.pop(timestamp_index)) | ||
id_index = cols.index(id_column) | ||
cols.insert(0, cols.pop(id_index)) | ||
target_index = cols.index(target) | ||
cols.append(cols.pop(target_index)) | ||
if timestamp_column is not None: | ||
timestamp_index = cols.index(timestamp_column) | ||
cols.insert(0, cols.pop(timestamp_index)) | ||
if id_column is not None: | ||
id_index = cols.index(id_column) | ||
cols.insert(0, cols.pop(id_index)) | ||
if target is not None: | ||
target_index = cols.index(target) | ||
cols.append(cols.pop(target_index)) | ||
data = data[cols] | ||
|
||
if static_features is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making I think that keeping the |
||
|
@@ -48,8 +51,8 @@ def fit( | |
*, | ||
predictor_init_args: Dict[str, Any], | ||
predictor_fit_args: Dict[str, Any], | ||
id_column: str, | ||
timestamp_column: str, | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
static_features: Optional[Union[str, pd.DataFrame]] = None, | ||
framework_version: str = "latest", | ||
job_name: Optional[str] = None, | ||
|
@@ -199,9 +202,9 @@ def predict_proba_real_time(self, **kwargs) -> pd.DataFrame: | |
def predict( | ||
self, | ||
test_data: Union[str, pd.DataFrame], | ||
id_column: str, | ||
timestamp_column: str, | ||
target: str, | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
target: Optional[str] = None, | ||
static_features: Optional[Union[str, pd.DataFrame]] = None, | ||
**kwargs, | ||
) -> Optional[pd.DataFrame]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,7 +541,7 @@ def predict_proba_real_time( | |
""" | ||
self._validate_inference_kwargs(inference_kwargs=kwargs) | ||
return self.backend.predict_proba_real_time( | ||
test_data=test_data, test_data_image_column=test_data_image_column, accept=accept | ||
test_data=test_data, test_data_image_column=test_data_image_column, accept=accept, inference_kwargs=kwargs | ||
) | ||
|
||
def predict( | ||
|
@@ -556,6 +556,7 @@ def predict( | |
custom_image_uri: Optional[str] = None, | ||
wait: bool = True, | ||
backend_kwargs: Optional[Dict] = None, | ||
**kwargs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add docstring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add example code should be added to tutorials that showcase specifying kwargs. Otherwise it will be hard for users to realize how to do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I will add some tutorials with this PR. |
||
) -> Optional[pd.Series]: | ||
""" | ||
Batch inference. | ||
|
@@ -632,6 +633,7 @@ def predict( | |
instance_count=instance_count, | ||
custom_image_uri=custom_image_uri, | ||
wait=wait, | ||
inference_kwargs=kwargs, | ||
**backend_kwargs, | ||
) | ||
|
||
|
@@ -648,6 +650,7 @@ def predict_proba( | |
custom_image_uri: Optional[str] = None, | ||
wait: bool = True, | ||
backend_kwargs: Optional[Dict] = None, | ||
**kwargs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add docstring |
||
) -> Optional[Union[Tuple[pd.Series, Union[pd.DataFrame, pd.Series]], Union[pd.DataFrame, pd.Series]]]: | ||
""" | ||
Batch inference | ||
|
@@ -730,6 +733,7 @@ def predict_proba( | |
instance_count=instance_count, | ||
custom_image_uri=custom_image_uri, | ||
wait=wait, | ||
inference_kwargs=kwargs, | ||
**backend_kwargs, | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,8 @@ def fit( | |
*, | ||
predictor_init_args: Dict[str, Any], | ||
predictor_fit_args: Dict[str, Any], | ||
id_column: str = "item_id", | ||
timestamp_column: str = "timestamp", | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is our motivation for changing the defaults here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to make the |
||
static_features: Optional[Union[str, pd.DataFrame]] = None, | ||
framework_version: str = "latest", | ||
job_name: Optional[str] = None, | ||
|
@@ -120,7 +120,7 @@ def fit( | |
if backend_kwargs is None: | ||
backend_kwargs = {} | ||
|
||
self.target_column = predictor_init_args.get("target", "target") | ||
self.target_column = predictor_init_args.get("target") | ||
self.id_column = id_column | ||
self.timestamp_column = timestamp_column | ||
|
||
|
@@ -146,6 +146,9 @@ def fit( | |
def predict_real_time( | ||
self, | ||
test_data: Union[str, pd.DataFrame], | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
target: Optional[str] = None, | ||
static_features: Optional[Union[str, pd.DataFrame]] = None, | ||
accept: str = "application/x-parquet", | ||
**kwargs, | ||
|
@@ -175,13 +178,18 @@ def predict_real_time( | |
Pandas.DataFrame | ||
Predict results in DataFrame | ||
""" | ||
self.id_column = id_column or self.id_column | ||
self.timestamp_column = timestamp_column or self.timestamp_column | ||
self.target_column = target or self.target_column | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the
It has been handled https://github.com/autogluon/autogluon/blob/bda6174f4a1fb8398aef4f375d9eacfd29bb46d9/timeseries/src/autogluon/timeseries/predictor.py#L179 |
||
|
||
return self.backend.predict_real_time( | ||
test_data=test_data, | ||
id_column=self.id_column, | ||
timestamp_column=self.timestamp_column, | ||
target=self.target_column, | ||
static_features=static_features, | ||
accept=accept, | ||
inference_kwargs=kwargs, | ||
) | ||
|
||
def predict_proba_real_time(self, **kwargs) -> pd.DataFrame: | ||
|
@@ -190,6 +198,9 @@ def predict_proba_real_time(self, **kwargs) -> pd.DataFrame: | |
def predict( | ||
self, | ||
test_data: Union[str, pd.DataFrame], | ||
id_column: Optional[str] = None, | ||
timestamp_column: Optional[str] = None, | ||
target: Optional[str] = None, | ||
static_features: Optional[Union[str, pd.DataFrame]] = None, | ||
predictor_path: Optional[str] = None, | ||
framework_version: str = "latest", | ||
|
@@ -199,6 +210,7 @@ def predict( | |
custom_image_uri: Optional[str] = None, | ||
wait: bool = True, | ||
backend_kwargs: Optional[Dict] = None, | ||
**kwargs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring |
||
) -> Optional[pd.DataFrame]: | ||
""" | ||
Predict using SageMaker batch transform. | ||
|
@@ -263,6 +275,10 @@ def predict( | |
Please refer to | ||
https://sagemaker.readthedocs.io/en/stable/api/inference/transformer.html#sagemaker.transformer.Transformer.transform for all options. | ||
""" | ||
self.id_column = id_column or self.id_column | ||
self.timestamp_column = timestamp_column or self.timestamp_column | ||
self.target_column = target or self.target_column | ||
|
||
if backend_kwargs is None: | ||
backend_kwargs = {} | ||
backend_kwargs = self.backend.parse_backend_predict_kwargs(backend_kwargs) | ||
|
@@ -279,6 +295,7 @@ def predict( | |
instance_count=instance_count, | ||
custom_image_uri=custom_image_uri, | ||
wait=wait, | ||
inference_kwargs=kwargs, | ||
**backend_kwargs, | ||
) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.