예제 #1
0
def create_multiple(request):
    """No request validation"""
    payload = json.loads(request.body.decode('utf-8'))
    try:
        split = Split.objects.get(pk=payload['split_id'])
    except Split.DoesNotExist:
        return Response({'error': 'not in database'},
                        status=status.HTTP_404_NOT_FOUND)

    # detect either or not a predictive_model to update has been specified otherwise train a new one.
    if 'incremental_train' in payload['config'] and payload['config'][
            'incremental_train']['base_model'] is not None:
        jobs = update(split, payload)
    elif payload['type'] in [e.value for e in PredictiveModels]:
        jobs = generate(split, payload)
    elif payload['type'] == JobTypes.LABELLING.value:
        jobs = generate_labelling(split, payload)
    else:
        return Response(
            {'error': 'type not supported'.format(payload['type'])},
            status=status.HTTP_422_UNPROCESSABLE_ENTITY)
    for job in jobs:
        django_rq.enqueue(tasks.prediction_task, job.id)
    serializer = JobSerializer(jobs, many=True)
    return Response(serializer.data, status=201)
예제 #2
0
    def test_generate_up_to(self):
        job = create_test_job()

        initial_job = job.to_dict()
        del initial_job['created_date']
        del initial_job['modified_date']
        del initial_job['hyperparameter_optimizer']
        del initial_job['encoding']['features']
        del initial_job['encoding']['task_generation_type']
        del initial_job['labelling']['attribute_name']

        generated_job = generate(split=job.split,
                                 payload={
                                     'type': 'classification',
                                     'split_id': 1,
                                     'config': {
                                         'clusterings': ['noCluster'],
                                         'encodings': ['simpleIndex'],
                                         'encoding': {
                                             'padding': False,
                                             'prefix_length': 2,
                                             'generation_type': 'up_to',
                                             'add_remaining_time': False,
                                             'add_elapsed_time': False,
                                             'add_executed_events': False,
                                             'add_resources_used': False,
                                             'add_new_traces': False,
                                             'features': [],
                                         },
                                         'create_models': False,
                                         'methods': ['randomForest'],
                                         'kmeans': {},
                                         'incremental_train': {
                                             'base_model': None,
                                         },
                                         'hyperparameter_optimizer': {
                                             'algorithm_type': 'tpe',
                                             'max_evaluations': 10,
                                             'performance_metric': 'rmse',
                                             'type': 'none',
                                         },
                                         'labelling': {
                                             'type': 'next_activity',
                                             'attribute_name': '',
                                             'threshold_type':
                                             'threshold_mean',
                                             'threshold': 0,
                                         },
                                         'classification.decisionTree': {},
                                         'classification.knn': {},
                                         'classification.randomForest': {},
                                         'classification.adaptiveTree': {},
                                         'classification.hoeffdingTree': {},
                                         'classification.multinomialNB': {},
                                         'classification.perceptron': {},
                                         'classification.SGDClassifier': {},
                                         'classification.xgboost': {},
                                         'classification.nn': {},
                                         'regression.lasso': {},
                                         'regression.linear': {},
                                         'regression.randomForest': {},
                                         'regression.xgboost': {},
                                         'regression.nn': {},
                                         'time_series_prediction.rnn': {}
                                     }
                                 })[0].to_dict()
        del generated_job['created_date']
        del generated_job['modified_date']
        del generated_job['hyperparameter_optimizer']
        del generated_job['encoding']['features']
        del generated_job['encoding']['task_generation_type']
        del generated_job['labelling']['attribute_name']

        self.assertDictEqual(initial_job, generated_job)