def pi_init(self, str_xml: str): """ Handles configuration based on the GUI. Called when the Alteryx engine is ready to provide the tool configuration from the GUI. :param str_xml: The raw XML from the GUI. """ # Getting the dataName data property from the Gui.html self.data_source = Et.fromstring(str_xml).find( 'DataImportSource').text if 'DataImportSource' in str_xml else None self.data_location = Et.fromstring(str_xml).find( 'DataLocation').text if 'DataLocation' in str_xml else None self.do_auto_viz = Et.fromstring(str_xml).find( 'DoAutoViz').text == "True" if 'DoAutoViz' in str_xml else False self.display_browser = Et.fromstring(str_xml).find( 'DisplayBrowser' ).text == "True" if 'DisplayBrowser' in str_xml else False self.use_https = Et.fromstring(str_xml).find( 'UseHttps').text == "True" if 'UseHttps' in str_xml else False verify = False if self.use_https else True # Get connection information base = Et.fromstring(str_xml) self.address = base.find( 'Address' ).text if 'Address' in str_xml else 'http://prerelease.h2o.ai' username = base.find( 'Username').text if 'Username' in str_xml else 'h2oai' password = self.alteryx_engine.decrypt_password( base.find('Password').text, 0) if 'Password' in str_xml else 'h2oai' self.dai = h2oai_client.Client(address=self.address, username=username, password=password, verify=verify) # Valid target name checks. if self.data_source is None: self.display_error_msg( self.alteryx_engine.xmsg( 'Data Source must be specified. Please select a data source.' )) elif self.data_location is None and self.data_source != "upload": self.display_error_msg( self.alteryx_engine.xmsg( 'Data Location must be specified. Please enter a data location' )) error_msg = self.msg_str(self.str_file_path) if error_msg != '': self.alteryx_engine.output_message(self.n_tool_id, Sdk.EngineMessageType.error, self.xmsg(error_msg)) else: self.is_valid = True self.output_dataset = self.output_anchor_mgr.get_output_anchor( 'Dataset')
def process(dai_host, dai_user, dai_pass, train_ds, exp_config, project_name, test_ds): """ :param dai_host: Driverless AI host URL e.g. http://localhost:12345 :param dai_user: Driverless AI user name :param dai_pass: Driverless AI password :param train_ds: path to training dataset csv file :param exp_config: path to experiment config json file :param project_name: Project name to organize datasets and experiments :param test_ds: path to testing dataset csv file (optional) :return: None """ # print all the passed parameters # import inspect # _, _, _, values = inspect.getargvalues(inspect.currentframe()) # print(values) # Create a connection to Driverless AI con = h2o.Client(address=dai_host, username=dai_user, password=dai_pass) # Get project key project_key = get_project_key(con, project_name) # Upload datasets and link to project test_ds_key = None train_ds_key = upload_dataset_to_project(con, project_key, train_ds, "Training") if test_ds is not None: test_ds_key = upload_dataset_to_project(con, project_key, test_ds, "Testing") # Read experiment config file and overwrite needed configs, save the config on file system with open(exp_config, 'r') as read_file: experiment_configs = json.load(read_file) experiment_configs['dataset_key'] = train_ds_key if test_ds_key is not None: experiment_configs['testset_key'] = test_ds_key with open('experiment-config.json', 'w') as write_file: json.dump(experiment_configs, write_file, indent=4) # Execute the experiment, link to project experiment: h2o.Model = con.start_experiment_sync(**experiment_configs) con.link_experiment_to_project(project_key, experiment.key) # build mojo pipeline mojo: h2o.MojoPipeline = con.build_mojo_pipeline_sync(experiment.key) # download mojo and python scoring pipelines and experiment summary con.download(experiment.scoring_pipeline_path, "") con.download(experiment.summary_path, "") con.download(mojo.file_path, "") # Finally save experiment.json with open('experiment.json', 'w') as write_file: json.dump(experiment.dump(), write_file, indent=4)
def pi_init(self, str_xml: str): """ Handles configuration based on the GUI. Called when the Alteryx engine is ready to provide the tool configuration from the GUI. :param str_xml: The raw XML from the GUI. """ # Getting the dataName data property from the Gui.html self.model_id = Et.fromstring(str_xml).find( 'ModelID').text if 'ModelID' in str_xml else None self.is_timeseries = Et.fromstring(str_xml).find( 'IsTimeSeries' ).text == "True" if "IsTimeSeries" in str_xml else False self.target_col = Et.fromstring(str_xml).find( "TargetColumn").text if "TargetColumn" in str_xml else "" self.dataset_key = Et.fromstring(str_xml).find( 'DatasetKey').text if "DatasetKey" in str_xml else "" self.display_browser = Et.fromstring(str_xml).find( 'DisplayBrowser' ).text == "True" if "DisplayBrowser" in str_xml else False self.use_https = Et.fromstring(str_xml).find( 'UseHttps').text == "True" if 'UseHttps' in str_xml else False verify = False if self.use_https else True # Get connection information base = Et.fromstring(str_xml) self.addr = base.find( 'Address' ).text if 'Address' in str_xml else 'http://prerelease.h2o.ai' username = base.find( 'Username').text if 'Username' in str_xml else 'h2oai' password = self.alteryx_engine.decrypt_password( base.find('Password').text, 0) if 'Password' in str_xml else 'h2oai' self.dai = h2oai_client.Client(address=self.addr, username=username, password=password, verify=verify) # Valid target name checks. error_msg = self.msg_str(self.str_file_path) if error_msg != '': self.alteryx_engine.output_message(self.n_tool_id, Sdk.EngineMessageType.error, self.xmsg(error_msg)) else: self.is_valid = True self.output_anchor = self.output_anchor_mgr.get_output_anchor('MLI')
def pi_init(self, str_xml: str): """ Handles configuration based on the GUI. Called when the Alteryx engine is ready to provide the tool configuration from the GUI. :param str_xml: The raw XML from the GUI. """ # Getting the dataName data property from the Gui.html self.target_name = Et.fromstring(str_xml).find( 'TargetColumn').text if 'TargetColumn' in str_xml else None #self.output_field = Et.fromstring(str_xml).find('OutputField').text if 'OutputField' in str_xml else None self.accuracy = int(Et.fromstring(str_xml).find( 'Accuracy').text) if 'Accuracy' in str_xml else None self.time = int(Et.fromstring(str_xml).find( 'Time').text) if 'Time' in str_xml else None self.interpretability = int( Et.fromstring(str_xml).find('Interpretability').text ) if 'Interpretability' in str_xml else None self.is_classification = Et.fromstring(str_xml).find( 'IsClassification' ).text == 'True' if 'IsClassification' in str_xml else None # Default function for DAI is to have Time Series off self.is_timeseries = Et.fromstring(str_xml).find( 'IsTimeSeries' ).text == 'True' if 'IsTimeSeries' in str_xml else False self.config_string = Et.fromstring( str_xml).find('AdditionalUserConfigs' ).text if 'AdditionalUserConfigs' in str_xml else "" reg_scorer = Et.fromstring(str_xml).find( 'RegressionScoringMetric' ).text if 'RegressionScoringMetric' in str_xml else "" class_scorer = Et.fromstring(str_xml).find( 'ClassificationScoringMetric' ).text if 'ClassificationScoringMetric' in str_xml else "" self.use_https = Et.fromstring(str_xml).find( 'UseHttps').text == "True" if 'UseHttps' in str_xml else False verify = False if self.use_https else True if self.is_classification: self.scorer = class_scorer else: self.scorer = reg_scorer self.display_browser = Et.fromstring(str_xml).find( 'DisplayBrowser' ).text == 'True' if 'DisplayBrowser' in str_xml else False # Get connection information base = Et.fromstring(str_xml) self.addr = base.find( 'Address' ).text if 'Address' in str_xml else 'http://prerelease.h2o.ai' username = base.find( 'Username').text if 'Username' in str_xml else 'h2oai' password = self.alteryx_engine.decrypt_password( base.find('Password').text, 0) if 'Password' in str_xml else 'h2oai' self.dai = h2oai_client.Client(address=self.addr, username=username, password=password, verify=verify) # Valid target name checks. if self.target_name is None: self.display_error_msg( self.alteryx_engine.xmsg( 'Target Column cannot be empty. Please enter a Target Column.' )) elif len(self.target_name) > 255: self.display_error_msg( self.alteryx_engine.xmsg( 'Target Column cannot be greater than 255 characters.')) error_msg = self.msg_str(self.str_file_path) if error_msg != '': self.alteryx_engine.output_message(self.n_tool_id, Sdk.EngineMessageType.error, self.xmsg(error_msg)) else: self.is_valid = True self.output_anchor = self.output_anchor_mgr.get_output_anchor( 'Predictions') self.output_model = self.output_anchor_mgr.get_output_anchor('Model')