-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial connection to predicting with sagemaker
- Loading branch information
Showing
5 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
|
||
import numpy as np | ||
from eland import DataFrame | ||
from typing import List, Optional | ||
|
||
from sagemaker import RealTimePredictor | ||
|
||
|
||
def make_sagemaker_prediction(endpoint_name: str, | ||
data: DataFrame, | ||
column_order: Optional[List[str]] = None | ||
) -> np.array: | ||
""" | ||
Make a prediction on an eland dataframe using a deployed SageMaker model endpoint. | ||
Parameters | ||
---------- | ||
endpoint_name: string representing name of SageMaker endpoint | ||
data: eland DataFrame representing data to feed to SageMaker model. The dataframe must match the input datatypes | ||
of the model and also have the correct number of columns. | ||
column_order: list of string values representing the proper order that the columns should be read into the | ||
SageMaker model. Must be a permutation of the column names of the eland DataFrame. | ||
Returns | ||
---------- | ||
np.array representing the output of the model on input data | ||
""" | ||
predictor = RealTimePredictor(endpoint=endpoint_name, content_type='text/csv') | ||
|
||
test_data = data | ||
if column_order is not None: | ||
test_data = test_data[column_order] | ||
|
||
preds = predictor.predict(test_data.to_csv(header=False, index=False)) | ||
preds = np.array(json.loads(preds.decode('utf-8'))['probabilities']) | ||
return preds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ elasticsearch>=8,<9 | |
pandas>=1.2,<2 | ||
matplotlib<4 | ||
numpy<2 | ||
opensearch-py>=2 | ||
sagemaker>=1.72,<2 | ||
tqdm<5 | ||
|
||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ elasticsearch>=8,<9 | |
pandas>=1.2,<2 | ||
matplotlib<4 | ||
numpy<2 | ||
opensearch-py>=2 | ||
opensearch-py>=2 | ||
sagemaker>=1.72,<2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters