Skip to content

Commit e8db6ba

Browse files
author
Ubuntu
committed
Added README and sample code for feature group.
1 parent 739da01 commit e8db6ba

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

samples/feature_group/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Feature Group Sample
2+
3+
This sample demonstrates how to create a feature group using the Amazon AWS Controllers for Kubernetes (ACK) service controller for Amazon SageMaker.
4+
5+
## Prerequisites
6+
7+
This sample assumes that you have completed the [common prerequisites](https://github.com/aws-controllers-k8s/sagemaker-controller/blob/main/samples/README.md).
8+
9+
### Create an S3 bucket:
10+
11+
Since we are using the offline store in this example, you need to set up an s3 bucket. [Here are directions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html) to set up your s3 bucket through the S3 Console, AWS SDK, or AWS CLI.
12+
13+
### Updating the Feature Group Specification:
14+
15+
In the `my-feature-group.yaml` file, modify the placeholder values with those associated with your account and feature group.
16+
17+
## Creating your Feature Group
18+
19+
### Create a Feature Group:
20+
21+
To submit your prepared feature group specification, apply the specification to your Kubernetes cluster as such:
22+
23+
```
24+
$ kubectl apply -f my-feature-group.yaml
25+
featuregroup.sagemaker.services.k8s.aws/my-feature-group created
26+
```
27+
28+
### List Feature Groups:
29+
30+
To list all feature groups created using the ACK controller use the following command:
31+
32+
```
33+
$ kubectl get featuregroup
34+
```
35+
36+
### Describe a Feature Group:
37+
38+
To get more details about the feature group once it's submitted, like checking the status, errors or parameters of the feature group use the following command:
39+
40+
```
41+
$ kubectl describe featuregroup my-feature-group
42+
```
43+
44+
## Ingesting Data into your Feature Group
45+
46+
Note that ingestion is **not** supported in the controller.
47+
The following assumes creation of a feature group with its name stored in `feature_group_name`
48+
49+
```
50+
### Sample CSV data file for Ingestion Example:
51+
#TransactionID,EventTime
52+
#1,1623434915
53+
#2,1623435267
54+
#3,1623435284
55+
56+
###Example boto3 ingestion of feature group:
57+
58+
import boto3
59+
import csv
60+
61+
sagemaker_featurestore_runtime_client = boto3.Session().client(
62+
service_name="sagemaker-featurestore-runtime")
63+
64+
### OPTION 1: To Download all records at once and upload records sequentially
65+
with open('./Downloads/Sample_data.csv') as file_handle:
66+
records =[
67+
[
68+
{'FeatureName':featureName,
69+
'ValueAsString':valueAsString}
70+
for featureName, valueAsString in row.items()]
71+
for row in csv.DictReader(file_handle, skipinitialspace=True)]
72+
73+
for record in records:
74+
sagemaker_featurestore_runtime_client.put_record(
75+
FeatureGroupName=feature_group_name,
76+
Record=record)
77+
78+
### OPTION 2: To Download records sequentially and upload records sequentially
79+
with open('./Downloads/Sample_data.csv') as file_handle:
80+
for row in csv.DictReader(file_handle, skipinitialspace=True):
81+
record =[
82+
{'FeatureName':featureName,
83+
'ValueAsString':valueAsString}
84+
for featureName, valueAsString in row.items()]
85+
sagemaker_featurestore_runtime_client.put_record(
86+
FeatureGroupName=feature_group_name,
87+
Record=record)
88+
89+
# To Check that the records are retrievable
90+
for recordIdentifierValue in range(1,len(records) + 1):
91+
sagemaker_featurestore_runtime_client.get_record(
92+
FeatureGroupName=feature_group_name,
93+
RecordIdentifierValueAsString=str(recordIdentifierValue))
94+
```
95+
96+
## Deleting your Feature Group
97+
98+
To delete the feature group, use the following command:
99+
100+
```
101+
$ kubectl delete featuregroup my-feature-group
102+
featuregroup.sagemaker.services.k8s.aws "my-feature-group" deleted
103+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: FeatureGroup
3+
metadata:
4+
name: <YOUR FEATURE GROUP NAME>
5+
spec:
6+
eventTimeFeatureName: EventTime
7+
featureDefinitions:
8+
- featureName: TransactionID
9+
featureType: Integral
10+
- featureName: EventTime
11+
featureType: Fractional
12+
featureGroupName: <YOUR FEATURE GROUP NAME>
13+
recordIdentifierFeatureName: TransactionID
14+
offlineStoreConfig:
15+
s3StorageConfig:
16+
s3URI: s3://<YOUR BUCKET>/feature-group-data
17+
onlineStoreConfig:
18+
enableOnlineStore: True
19+
roleARN: <YOUR SAGEMAKER ROLE ARN>

0 commit comments

Comments
 (0)