def main(): """ Just runs some example code. """ # setup the flow flow = Flow(name="list files") listfiles = ListFiles() listfiles.config["dir"] = str(helper.get_data_dir()) listfiles.config["list_files"] = True listfiles.config["list_dirs"] = False listfiles.config["recursive"] = False listfiles.config["regexp"] = ".*.arff" flow.actors.append(listfiles) tee = Tee() flow.actors.append(tee) convert = Convert() convert.config["setup"] = conversion.PassThrough() tee.actors.append(convert) console = Console() console.config["prefix"] = "Match: " tee.actors.append(console) load = LoadDataset() load.config["use_custom_loader"] = True flow.actors.append(load) cross = CrossValidate() cross.config["setup"] = Classifier(classname="weka.classifiers.trees.J48", options=["-C", "0.3"]) flow.actors.append(cross) summary = EvaluationSummary() summary.config["matrix"] = True flow.actors.append(summary) # print flow flow.setup() print("\n" + flow.tree + "\n") # save the flow fname = tempfile.gettempdir() + os.sep + "simpleflow.json" Flow.save(flow, fname) # load flow fl2 = Flow.load(fname) # output flow fl2.setup() print("\n" + fl2.tree + "\n")
def main(): """ Just runs some example code. """ # setup the flow flow = Flow(name="stopping the flow") outer = ForLoop() outer.config["max"] = 10 flow.actors.append(outer) ssv = SetStorageValue() ssv.config["storage_name"] = "current" flow.actors.append(ssv) tee = Tee() tee.config["condition"] = "@{current} == 7" flow.actors.append(tee) stop = Stop() tee.actors.append(stop) console = Console() flow.actors.append(console) # run the flow msg = flow.setup() if msg is None: print("\n" + flow.tree + "\n") msg = flow.execute() if msg is not None: print("Error executing flow:\n" + msg) else: print("Error setting up flow:\n" + msg) flow.wrapup() flow.cleanup()
def main(): """ Just runs some example code. """ # setup the flow helper.print_title("Attribute selection") iris = helper.get_data_dir() + os.sep + "iris.arff" flow = Flow(name="attribute selection") filesupplier = FileSupplier() filesupplier.config["files"] = [iris] flow.actors.append(filesupplier) loaddataset = LoadDataset() loaddataset.config["incremental"] = False flow.actors.append(loaddataset) attsel = AttributeSelection() attsel.config["search"] = ASSearch(classname="weka.attributeSelection.BestFirst") attsel.config["eval"] = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval") flow.actors.append(attsel) results = Tee() results.name = "output results" flow.actors.append(results) picker = ContainerValuePicker() picker.config["value"] = "Results" picker.config["switch"] = True results.actors.append(picker) console = Console() console.config["prefix"] = "Attribute selection results:" results.actors.append(console) reduced = Tee() reduced.name = "reduced dataset" flow.actors.append(reduced) picker = ContainerValuePicker() picker.config["value"] = "Reduced" picker.config["switch"] = True reduced.actors.append(picker) console = Console() console.config["prefix"] = "Reduced dataset:\n\n" reduced.actors.append(console) # run the flow msg = flow.setup() if msg is None: print("\n" + flow.tree + "\n") msg = flow.execute() if msg is not None: print("Error executing flow:\n" + msg) else: print("Error setting up flow:\n" + msg) flow.wrapup() flow.cleanup()
def main(): """ Just runs some example code. """ # setup the flow count = 50 helper.print_title("build clusterer incrementally") iris = helper.get_data_dir() + os.sep + "iris.arff" flow = Flow(name="build clusterer incrementally") filesupplier = FileSupplier() filesupplier.config["files"] = [iris] flow.actors.append(filesupplier) initcounter = InitStorageValue() initcounter.config["storage_name"] = "counter" initcounter.config["value"] = 0 flow.actors.append(initcounter) loaddataset = LoadDataset() loaddataset.config["incremental"] = True flow.actors.append(loaddataset) remove = Filter(name="remove class attribute") remove.config["setup"] = filters.Filter( classname="weka.filters.unsupervised.attribute.Remove", options=["-R", "last"]) flow.actors.append(remove) inccounter = UpdateStorageValue() inccounter.config["storage_name"] = "counter" inccounter.config["expression"] = "{X} + 1" flow.actors.append(inccounter) train = Train() train.config["setup"] = Clusterer(classname="weka.clusterers.Cobweb") flow.actors.append(train) pick = ContainerValuePicker() pick.config["value"] = "Model" pick.config["switch"] = True flow.actors.append(pick) tee = Tee(name="output model every " + str(count) + " instances") tee.config["condition"] = "@{counter} % " + str(count) + " == 0" flow.actors.append(tee) trigger = Trigger(name="output # of instances") tee.actors.append(trigger) getcounter = GetStorageValue() getcounter.config["storage_name"] = "counter" trigger.actors.append(getcounter) console = Console() console.config["prefix"] = "# of instances: " trigger.actors.append(console) console = Console(name="output model") tee.actors.append(console) # run the flow msg = flow.setup() if msg is None: print("\n" + flow.tree + "\n") msg = flow.execute() if msg is not None: print("Error executing flow:\n" + msg) else: print("Error setting up flow:\n" + msg) flow.wrapup() flow.cleanup()
def main(): """ Just runs some example code. """ # setup the flow count = 50 helper.print_title("build classifier incrementally") iris = helper.get_data_dir() + os.sep + "iris.arff" flow = Flow(name="build classifier incrementally") filesupplier = FileSupplier() filesupplier.config["files"] = [iris] flow.actors.append(filesupplier) initcounter = InitStorageValue() initcounter.config["storage_name"] = "counter" initcounter.config["value"] = 0 flow.actors.append(initcounter) loaddataset = LoadDataset() loaddataset.config["incremental"] = True flow.actors.append(loaddataset) select = ClassSelector() select.config["index"] = "last" flow.actors.append(select) inccounter = UpdateStorageValue() inccounter.config["storage_name"] = "counter" inccounter.config["expression"] = "{X} + 1" flow.actors.append(inccounter) train = Train() train.config["setup"] = Classifier(classname="weka.classifiers.bayes.NaiveBayesUpdateable") flow.actors.append(train) pick = ContainerValuePicker() pick.config["value"] = "Model" pick.config["switch"] = True flow.actors.append(pick) tee = Tee(name="output model every " + str(count) + " instances") tee.config["condition"] = "@{counter} % " + str(count) + " == 0" flow.actors.append(tee) trigger = Trigger(name="output # of instances") tee.actors.append(trigger) getcounter = GetStorageValue() getcounter.config["storage_name"] = "counter" trigger.actors.append(getcounter) console = Console() console.config["prefix"] = "# of instances: " trigger.actors.append(console) console = Console(name="output model") tee.actors.append(console) # run the flow msg = flow.setup() if msg is None: print("\n" + flow.tree + "\n") msg = flow.execute() if msg is not None: print("Error executing flow:\n" + msg) else: print("Error setting up flow:\n" + msg) flow.wrapup() flow.cleanup()
def main(): """ Just runs some example code. """ # setup the flow helper.print_title("Attribute selection") iris = helper.get_data_dir() + os.sep + "iris.arff" flow = Flow(name="attribute selection") filesupplier = FileSupplier() filesupplier.config["files"] = [iris] flow.actors.append(filesupplier) loaddataset = LoadDataset() loaddataset.config["incremental"] = False flow.actors.append(loaddataset) attsel = AttributeSelection() attsel.config["search"] = ASSearch( classname="weka.attributeSelection.BestFirst") attsel.config["eval"] = ASEvaluation( classname="weka.attributeSelection.CfsSubsetEval") flow.actors.append(attsel) results = Tee() results.name = "output results" flow.actors.append(results) picker = ContainerValuePicker() picker.config["value"] = "Results" picker.config["switch"] = True results.actors.append(picker) console = Console() console.config["prefix"] = "Attribute selection results:" results.actors.append(console) reduced = Tee() reduced.name = "reduced dataset" flow.actors.append(reduced) picker = ContainerValuePicker() picker.config["value"] = "Reduced" picker.config["switch"] = True reduced.actors.append(picker) console = Console() console.config["prefix"] = "Reduced dataset:\n\n" reduced.actors.append(console) # run the flow msg = flow.setup() if msg is None: print("\n" + flow.tree + "\n") msg = flow.execute() if msg is not None: print("Error executing flow:\n" + msg) else: print("Error setting up flow:\n" + msg) flow.wrapup() flow.cleanup()