Exemplo n.º 1
0
    def __init__(self, model_path):
        self._gateway = create_gateway()

        self._pipeline = ExportedPipeline()
        self._pipeline.load(model_path)

        self._features_spec = """
        {
            "event": [{
                "group": "medication",
                "operation": "count",
                "window": 365
            }, {
                "group": "diagnostic",
                "operation": "count",
                "window": 365
            }, {
                "group": "medication",
                "operation": "avrgdu",
                "window": 365
            }, {
                "group": "encounter",
                "operation": "avrgdu",
                "window": 365
            }],
            "attribute": [{
                "attribute": "DOB",
                "operation": "default"
            },{
                "attribute": "gender"
            }]
        }
        """

        self._feature_mapping = ssf.load_feature_mapping(model_path + "mapping.txt")
        self._feature_names = [k for k, __ in sorted(self._feature_mapping.items(), key=lambda x: x[1])]
        self._metrics = load_json(model_path + "metric")

        self._top_features = None
        for step in self._pipeline._steps:
            if hasattr(step._model, "scores_"):
                scores = step._model.scores_
                top_features_index = np.argsort(scores)[::-1][:200]
                self._top_features = [self._feature_names[i] for i in top_features_index]
                break
Exemplo n.º 2
0
 def metrics(self):
     # assuming last step is Test and output is metrics.
     # maybe tricky. to be fixed TODO
     test_step = self._steps[-1]
     metrics_json = load_json(test_step.test_output_path)
     return ModelMetrics(**metrics_json)