def feature_selection( model_id: str, method: str, split: Optional[float] = 0.7, batch: Optional[str] = None, task_key: Optional[str] = None, sync: Optional[bool] = False, model_service: ModelService = Depends(ModelService), service: FeatureSelectionService = Depends(FeatureSelectionService), tasks: TaskService = Depends(TaskService)): try: model = model_service.get_model(model_id) mf = service.create_features_search(model, split, method, task_key=task_key) if sync: return service.feature_selection(model, mf, sync=True) return tasks.send(task_name='featureselection', task_args={ 'model': model.dict(), 'search_parameters': mf.dict() }, name='feature_selection-{}-{}-{}-{}'.format( model.symbol, model.pipeline, model.dataset, model.target), batch=batch) except MessageException as e: raise HTTPException(status_code=400, detail=e.message)
def grid_search_batch(batch: Optional[str] = None, task_key: Optional[str] = None, split: Optional[float] = 0.7, query: dict = Body(...), model_service: ModelService = Depends(ModelService), service: GridSearchService = Depends(GridSearchService), tasks: TaskService = Depends(TaskService)): try: models = model_service.query_models(query) tests = [(model, service.create_parameters_search(model, split, task_key=task_key)) for model in models] return [ tasks.send(task_name='gridsearch', task_args={ 'model': model.dict(), 'search_parameters': search_parameters.dict() }, name='grid_search-{}-{}-{}-{}'.format( model.symbol, model.pipeline, model.dataset, model.target), batch=batch, countdown=30) for model, search_parameters in tests ] except MessageException as e: raise HTTPException(status_code=400, detail=e.message)
def grid_search(model_id: str, split: Optional[float] = 0.7, batch: Optional[str] = None, task_key: Optional[str] = None, sync: Optional[bool] = False, model_service: ModelService = Depends(ModelService), service: GridSearchService = Depends(GridSearchService), tasks: TaskService = Depends(TaskService)): try: model = model_service.get_model(model_id) parameters = service.create_parameters_search(model, split, task_key=task_key) if sync: return service.grid_search(model, parameters, sync=True) return tasks.send(task_name='gridsearch', task_args={ 'model': model.dict(), 'search_parameters': parameters.dict() }, name='grid_search-{}-{}-{}-{}'.format( model.symbol, model.pipeline, model.dataset, model.target), batch=batch) except MessageException as e: raise HTTPException(status_code=400, detail=e.message)
def merge_dataset_many(requests: List[MergeRequest] = Body(...), tasks: TaskService = Depends(TaskService)): _tasks = [ tasks.send(task_name='merge_datasets', task_args=r.dict(), name='merge_datasets-{}->{}-{}'.format( str(r.query), r.name, r.symbol), batch=str(r.query)) for r in requests ] return _tasks
def build_dataset( req: BuildRequest = Body(...), service: DatasetBuildingService = Depends(DatasetBuildingService), tasks: TaskService = Depends(TaskService)): try: service.check_builder_args(req.builder, req.args) return tasks.send(task_name='build_dataset', task_args=req.dict(), name='build_dataset-{}-{}'.format( req.symbol, req.builder)) except MessageException as e: raise HTTPException(status_code=400, detail=e.message)
def merge_dataset(name: str, symbol: str, sync: Optional[bool] = False, query: dict = Body(...), service: DatasetService = Depends(DatasetService), repo: DatasetRepository = Depends(DatasetRepository), tasks: TaskService = Depends(TaskService)): if sync: datasets = repo.query(query) return service.merge_datasets(datasets, name, symbol) else: r = MergeRequest(query=query, name=name, symbol=symbol) return tasks.send(task_name='merge_datasets', task_args=r.dict(), name='merge_datasets-{}->{}-{}'.format( str(r.query), r.name, r.symbol), batch=str(r.query))
def test_model(model_id: str, sync: Optional[bool] = False, test: ModelTest = Body(...), tasks: TaskService = Depends(TaskService), service: ModelService = Depends(ModelService)): try: model = service.get_model(model_id) if sync: return service.test_model(model, test) return tasks.send(task_name='testmodel', task_args={ 'model': model.dict(), 'test': test.dict() }, name='model_test-{}-{}-{}-{}'.format( model.symbol, model.pipeline, model.dataset, model.target)) except MessageException as e: raise HTTPException(status_code=400, detail=e.message)
def build_many_dataset( requests: List[BuildRequest] = Body(...), batch: Optional[str] = None, service: DatasetBuildingService = Depends(DatasetBuildingService), tasks: TaskService = Depends(TaskService)): # Check all args are correct for req in requests: try: service.check_builder_args(req.builder, req.args) except MessageException as e: raise HTTPException(status_code=400, detail=e.message) # Launch tasks _tasks = [ tasks.send(task_name='build_dataset', task_args=r.dict(), name='build_dataset-{}-{}'.format(req.symbol, req.builder), batch=batch) for r in requests ] return _tasks
def feature_selection_batch( method: str, batch: Optional[str] = None, task_key: Optional[str] = None, split: Optional[float] = 0.7, query: dict = Body(...), model_service: ModelService = Depends(ModelService), service: FeatureSelectionService = Depends(FeatureSelectionService), tasks: TaskService = Depends(TaskService)): try: models = model_service.query_models(query) # This will only keep 1 copy for each (symbol, dataset, target) tuple d_models = { '{}-{}-{}'.format(m.symbol, m.dataset, m.target): m for m in models } models = [v for k, v in d_models.items()] def get_name_from_model(_model): return 'feature_selection-{}-{}-{}-{}'.format( _model.symbol, _model.pipeline, _model.dataset, _model.target) tests = [(model, service.create_features_search(model, split, method, task_key=task_key)) for model in models] return [ tasks.send(task_name='featureselection', task_args={ 'model': model.dict(), 'search_parameters': search_parameters.dict() }, name=get_name_from_model(model), batch=batch, countdown=30) for i, (model, search_parameters) in enumerate(tests) ] except MessageException as e: raise HTTPException(status_code=400, detail=e.message)