in code/cv.py [0:0]
def fit_model(instance_type,
output_path,
s3_train_base_dir,
s3_test_base_dir,
f,
c,
gamma,
kernel
):
"""Fits a model using the specified algorithm.
Args:
instance_type: instance to use for Sagemaker Training job
output_path: S3 URI as the location for the trained model artifact
s3_train_base_dir: S3 URI for train datasets
s3_test_base_dir: S3 URI for test datasets
f: index represents a fold number in the K fold cross validation
c: regularization parameter for SVM
gamma: kernel coefficiency value
kernel: kernel type for SVM algorithm
Returns:
Sagemaker Estimator created with given input parameters.
"""
sklearn_framework_version='0.23-1'
script_path = 'scikit_learn_iris.py'
sagemaker_session = sagemaker.Session()
role = sagemaker.get_execution_role()
sklearn_estimator = SKLearn(
entry_point=script_path,
instance_type=instance_type,
framework_version=sklearn_framework_version,
role=role,
sagemaker_session=sagemaker_session,
output_path=output_path,
hyperparameters={'c': c, 'gamma' : gamma, 'kernel': kernel},
metric_definitions= [ { "Name": "test:score", "Regex": "model test score:(.*?);" }]
)
sklearn_estimator.fit(inputs = { 'train': f'{s3_train_base_dir}/{f}',
'test': f'{s3_test_base_dir}/{f}'
}, wait=False)
return sklearn_estimator