Please enable JavaScript.
Coggle requires JavaScript to display documents.
AWS Model Updation, from sagemaker.amazon.amazon_estimator import get…
AWS Model Updation
Create a XGB Model
xgb_contrainer = get_image_uri()
session.boto_region_name
'xgboost'
model container
xbb = sagemaker.estimator.Estimator()
xgb_contrainer
role
train_instace_count = 1
train_isntance_type = 'ml.m4.xlarge'
output_path = 's3://{}/{}'.format(session.default_bucket(),s3_folder_prefix)
sagemaker_session = sagemaker.Session()
set hyperparameters
xgb.set_hyperparameters()
hyper parameters for xgboost
Train the model
xgb.fit({'train' : s3_train_input, 'validation' : s3_validation_input)
s3_train_input = sagemaker.s3_input()
s3_data = s3_train_location
content_type = 'text/csv'
This doesn't create any model until the container/estimator is deployed or endpoint is created for it
use training model artifacts to create a model
xgb_primary_container =
{'Image' : xgb_contrainer,
'ModelDataUrl' : xgb,model_data}
2 more items...
xgb_model_info = session.sagemaker_client.create_model()
3 more items...
Create Endpoint
xgb_endpoint_info = session.sagemaker_client.create_endpoint_config()
3 more items...
Create linear model
linear_container = get_image()
session.boto_region_name
'linear-learner'
linear_estimator = saqemaker.estimator.Estimator()
container = linear_container
role = sagemaker.get_execution_role()
train_instance_count = 1
train_instance_type = 'ml.m.xlarge'
output_path = 's3://{}/{}'.format(session.default_bucket(),s3_folder)
sagemaker_session = sagemaker.session()
linear_estimator.set_hyperparameters()
feature_dim = 13
predictor_type = 'regressor'
mini_batch_size = 200
linear_estimator.fit()
{
'train' : sagemaker.s3_input
(
s3_data = input_data,
content_type = 'text/csv'
)
'validation' : sagemaker.s3_input (
s3_data = valiodation_data
content_type = 'text/csv'
)
}
linear_primary_contrainer =
{
""Image" : linear_container
"ModelDataUrl" : linear_estimator.model_data
}
linear_model_info = session.sagemaker_client.create_model()
ModelName = unique_model_name
ExecutionRoleArn = sagemaker.get_execution_role()
Primarycontainer = linear_primary_container
linear_endpoint_config_info = session.sagemaker_client.create_endpoint_config()
EndpointConfigName = unique_name
ProductionVariants =
1 more item...
linear_endpoint_info = session,sagemaker_client.create_endpoint()
3 more items...
Combined endpoint
combined_endpoint_config_info = session.sagemaker_client.create_endpoint_config()
combined_endpoint_info =session.sagemaker_client.create_endpoint()
EndpointName = unique_endpoin_nam
EndpointConfigName = unique_endpoint_config_name
session,sagemaker_clinet.wait_for_endpoint(unique_endpoint_name)
response = session.sagemaker_runtime_client.invoke_endpoint()
EndpointName = unique_endpoint_name
ContentType = 'text/csv'
Body = ' , '.join(map(str,test.values[10]))
respoce['Body'].read().decode('utf-8')
session.sagemaker_client.describe_endpoint(EndpointName = unique_endpoint_name)
session.sagemaker_client.update_endpoint(EndpointName = unique_endpoint_name, EndpointConfigName = unique_config_name)
EndpointConfigName = unique_config_info_name
ProdcutionVariants = [ ]
{
"InstanceType" : "ml.m4.xlarge",
"InitiallVariantWeight": 1
"InitialInstancecount" : 1
"ModelName" : unique_linear_model_name
"VariantName" : "linear_model"
}
{
"InstanceType" : "ml.m4.xlarge",
"InitialVariantWeight" : 1
"InitialInstanceCount" : 1,
"ModelName": unique_xgb_model_name
"VariantName" : "xgb_model"
}
Generating unique names
name + strftime("%Y-%m-%d-%H-%M-%S", gmtime())
from sagemaker.amazon.amazon_estimator import get_image_uri
from sagemaker.amazon.amazon_estimator import get_image_uri
you should use the model unique name given but not the model variable created