where can i found the detailed API functions for scenario interaction

Options
zhlj
zhlj Registered Posts: 24 ✭✭✭✭

For example, I can find the function train_model(model_id, project_key=None, build_mode='RECURSIVE_BUILD', step_name=None, async=False, fail_fatal=True)

But how could I know what kind of object this function returns, and how can I use with that returned value?

From the sample code, I found function get_new_version_metrics() belongs to the returned instance from train_model() , but can't find any information from documentation.

Thanks,

Lj

Answers

  • Alex_Combessie
    Alex_Combessie Alpha Tester, Dataiker Alumni Posts: 539 ✭✭✭✭✭✭✭✭✭
    Options

    Hi,

    In the Dataiku Scenario API, train_model returns the same object type as run_step.

    If async=False (default) it returns a BuildFlowItemsStepResult object. You need to call the get_trained_model method to get a TrainedModelHandle object:

    class TrainedModelHandle(object):def __init__(self, report_item):self.report_item = report_itemassert(self.report_item["type"] == "BUILT_MODEL")def get_new_version(self):return self.report_item["versionId"]def get_model(self):return dataiku.Model(self.report_item["target"]["modelId"], project_key = self.report_item["target"]["projectKey"])def activate_new_version(self):model = self.get_model()model.activate_version(self.get_new_version())def get_new_version_metrics(self):model = self.get_model()return model.get_version_metrics(self.get_new_version())

    We will update our documentation to make it clearer.

    Hope it helps,

    Alex

  • zhlj
    zhlj Registered Posts: 24 ✭✭✭✭
    Options

    Thanks Alex for the quick reply. However, I've noticed that if one wants to access the function get_new_version_metrics(), he has to use following syntax:

    train_ret = scenario.train_model("0pwbYbmy")
    trained_model = train_ret.get_trained_model()
    performance = train_ret.get_new_version_metrics().get_performance_values()

    which means function belongs to the object returned by get_train_model() not train_model().

    Hope you can update the documentation quickly.

    Regards,

    LJ

  • Alex_Combessie
    Alex_Combessie Alpha Tester, Dataiker Alumni Posts: 539 ✭✭✭✭✭✭✭✭✭
    Options

    Hi,

    Thanks for spotting this. Indeed you first need to call get_trained_model on the result of train_model. In your case, the correct syntax is:

    train_model_result = scenario.train_model("<modelId>")trained_model = train_model_result.get_trained_model()trained_model_new_performance = trained_model.get_new_version_metrics().get_performance_values()

    I will edit my earlier response accordingly.

    Alex

  • Katie
    Katie Dataiker, Registered, Product Ideas Manager Posts: 105 Dataiker
    Options

    Hello to any future readers of this post - you can find detailed scenario documentation on our developer guide here: https://developer.dataiku.com/latest/concepts-and-examples/scenarios.html

Setup Info
    Tags
      Help me…