def test_convert_to_output_format_ok(self, input, expected_output):
     actual_output = to_output(input)
     assert expected_output == actual_output
     try:
         json.dumps(actual_output)
     except Exception:
         raise AssertionError("Could not dump result into json")
Example #2
0
    def predict(self, instance):
        """
        instance:
            Since we're doing scheduled prediction, this will be a data spec
            describing the data we should do prediction on.
        
        Note that it's also possible to take api_key and project in as
        optional arguments here.
        """
        dts = DataFetcher(instance)
        df = dts.time_series.fetch_dataframe(["temp", "pressure", "rpm"]).dropna()

        X = df[["temp", "pressure", "rpm"]].values
        df["production_rate"] = self.regressor.predict(X)

        # For scheduled prediction we need to return output on the format:
        # {
        #   "timeSeries":
        #      { "production_rate": [(t0, p0), (t1, p1), (t2, p2), ...] }
        # }
        # We can use a model hosting utilities method to convert our dataframe
        # to this format.
        return to_output(df[["timestamp", "production_rate"]])
Example #3
0
 def predict(self, instance):
     data_fetcher = DataFetcher(instance,
                                client_name="simple-transform-client")
     df = data_fetcher.time_series.fetch_dataframe(["x1", "x2"])
     df["y"] = (df["x1"] + df["x2"]) / math.pi
     return to_output(df[["y"]])
Example #4
0
 def predict(self, instance):
     data_fetcher = DataFetcher(instance)
     df = data_fetcher.time_series.fetch_dataframe(["x1", "x2"])
     df["y"] = (df["x1"] + df["x2"]) / math.pi
     return to_output(df[["y", "timestamp"]])
 def test_convert_to_output_duplicate_alias(self):
     with pytest.raises(DuplicateAliasInScheduledOutput, match="multiple"):
         to_output([
             pd.DataFrame({"x": [1]}, index=[1]),
             pd.DataFrame({"x": [1]}, index=[1])
         ])
Example #6
0
    def predict(self, instance):
        data_fetcher = DataFetcher(instance)
        df = data_fetcher.time_series.fetch_dataframe(["x1", "x2"])
        df["y"] = df["x2"] / df["x1"]

        return to_output(df.size)
Example #7
0
    def predict(self, instance):
        data_fetcher = DataFetcher(instance, client_name="cprfix-client")
        df = data_fetcher.time_series.fetch_dataframe(["x1", "x2"])
        df["y"] = df["x2"] / df["x1"]

        return to_output(df[["y"]])