in frauddetector/frauddetector.py [0:0]
def fit(self, data_schema, data_location, role, variables, labels, data_source="EXTERNAL_EVENTS", wait=False):
"""Train Amazon FraudDetector model version. Wraps the boto3 SDK API to allow bulk operations.
Args:
:wait: boolean to indicate whether to wait or not
Returns:
:response_all: {variable_name: API-response-status, variable_name: API-response-status} dict
"""
self.project_variables = variables
self.project_labels = labels
self.variables = self.fd.get_variables()
self.labels = self.fd.get_labels()
self.events = self.fd.get_event_types()
self.entities = self.fd.get_entity_types()
self.models = self.fd.get_models()
if self.variables and self.labels:
self._setup_project()
event_details = {
'dataLocation' : data_location,
'dataAccessRoleArn': role
}
lh.info("fit: train {} model".format(self.model_name))
response = self.fd.create_model_version(
modelId=self.model_name,
modelType=self.model_type,
trainingDataSource=data_source,
trainingDataSchema=data_schema,
externalEventsDetail=event_details
)
lh.info("Wait for model training to complete...")
stime = time.time()
while wait:
current_time = datetime.now()
clear_output(wait=True)
response = self.fd.get_model_version(
modelId=self.model_name,
modelType=self.model_type,
modelVersionNumber=self.model_version)
if response['status'] == 'TRAINING_IN_PROGRESS':
lh.info(f"{current_time}: current progress: {(time.time() - stime)/60:{3}.{3}} minutes")
time.sleep(60) # -- sleep for 60 seconds
if response['status'] != 'TRAINING_IN_PROGRESS':
lh.info(f"{current_time}: Model status : {response['status']}")
break
etime = time.time()
# -- summarize --
lh.info("\nModel training complete")
lh.info("\nElapsed time : %s" % (etime - stime) + " seconds \n")
return response