r"""Save the time-stamped model predictor to disk. Parameters ---------- model : alphapy.Model The model object that contains the best estimator. timestamp : str Date in yyyy-mm-dd format. Returns ------- None : None
(model, timestamp)
| 510 | # |
| 511 | |
| 512 | def save_predictor(model, timestamp): |
| 513 | r"""Save the time-stamped model predictor to disk. |
| 514 | |
| 515 | Parameters |
| 516 | ---------- |
| 517 | model : alphapy.Model |
| 518 | The model object that contains the best estimator. |
| 519 | timestamp : str |
| 520 | Date in yyyy-mm-dd format. |
| 521 | |
| 522 | Returns |
| 523 | ------- |
| 524 | None : None |
| 525 | |
| 526 | """ |
| 527 | |
| 528 | logger.info("Saving Model Predictor") |
| 529 | |
| 530 | # Extract model parameters. |
| 531 | directory = model.specs['directory'] |
| 532 | |
| 533 | # Get the best predictor |
| 534 | predictor = model.estimators['BEST'] |
| 535 | |
| 536 | # Save model object |
| 537 | |
| 538 | if 'KERAS' in model.best_algo: |
| 539 | filename = 'model_' + timestamp + '.h5' |
| 540 | full_path = SSEP.join([directory, 'model', filename]) |
| 541 | logger.info("Writing model predictor to %s", full_path) |
| 542 | predictor.model.save(full_path) |
| 543 | else: |
| 544 | filename = 'model_' + timestamp + '.pkl' |
| 545 | full_path = SSEP.join([directory, 'model', filename]) |
| 546 | logger.info("Writing model predictor to %s", full_path) |
| 547 | joblib.dump(predictor, full_path) |
| 548 | |
| 549 | |
| 550 | # |