def demo(): """ _test_pipeline This demo demonstrates the Pipeline structure seemingly working as a learner, while being passed as parameter to an EvaluatePrequential object. """ # # Setup the stream # stream = FileStream("../data/datasets/covtype.csv", -1, 1) # stream.prepare_for_use() # # If used for Hoeffding Trees then need to pass indices for Nominal attributes # Test with RandomTreeGenerator # stream = RandomTreeGenerator(n_classes=2, n_numerical_attributes=5) # stream.prepare_for_use() # Test with WaveformGenerator stream = WaveformGenerator() stream.prepare_for_use() # Setup the classifier #classifier = PerceptronMask() #classifier = NaiveBayes() #classifier = PassiveAggressiveClassifier() classifier = HoeffdingTreeClassifier() # Setup the pipeline pipe = Pipeline([('Hoeffding Tree', classifier)]) # Setup the evaluator evaluator = EvaluatePrequential(show_plot=True, pretrain_size=1000, max_samples=100000) # Evaluate evaluator.evaluate(stream=stream, model=pipe)
def demo(output_file=None, instances=40000): """ _test_comparison_holdout This demo will test a holdout evaluation task when more than one learner is evaluated, which makes it a comparison task. Parameters ---------- output_file: string, optional If passed this parameter indicates the output file name. If left blank, no output file will be generated. instances: int (Default: 40000) The evaluation's maximum number of instances. """ # Setup the File Stream # stream = FileStream("../data/datasets/covtype.csv", -1, 1) stream = WaveformGenerator() stream.prepare_for_use() # Setup the classifier clf_one = HoeffdingTree() # clf_two = KNNAdwin(n_neighbors=8, max_window_size=2000) # classifier = PassiveAggressiveClassifier() # classifier = SGDRegressor() # classifier = PerceptronMask() # Setup the pipeline classifier = [clf_one] # Setup the evaluator evaluator = EvaluateHoldout(test_size=500, dynamic_test_set=True, max_samples=instances, batch_size=1, n_wait=5000, max_time=1000, output_file=output_file, show_plot=True, metrics=['kappa']) # Evaluate evaluator.evaluate(stream=stream, model=classifier)
def demo(output_file=None, instances=40000): """ _test_holdout This demo runs a holdout evaluation task with one learner. The default stream is a WaveformGenerator. The default learner is a SGDClassifier, which is inserted into a Pipeline structure. All the default values can be changing by uncommenting/commenting the code below. Parameters ---------- output_file: string The name of the csv output file instances: int The evaluation's max number of instances """ # Setup the File Stream # stream = FileStream("../data/datasets/covtype.csv", -1, 1) stream = WaveformGenerator() stream.prepare_for_use() # Setup the classifier classifier = SGDClassifier() # classifier = PassiveAggressiveClassifier() # classifier = SGDRegressor() # classifier = PerceptronMask() # Setup the pipeline pipe = Pipeline([('Classifier', classifier)]) # Setup the evaluator evaluator = EvaluateHoldout(test_size=2000, dynamic_test_set=True, max_samples=instances, batch_size=1, n_wait=15000, max_time=1000, output_file=output_file, show_plot=True, metrics=['kappa', 'kappa_t', 'performance']) # Evaluate evaluator.evaluate(stream=stream, model=pipe)
def demo(output_file=None, instances=40000): """ _test_prequential_bagging This demo shows the evaluation process of a LeverageBaggingClassifier, initialized with different base estimators. Parameters ---------- output_file: string The name of the csv output file instances: int The evaluation's max number of instances """ # Setup the File Stream # stream = FileStream("../data/datasets/sea_big.csv", -1, 1) #stream = SEAGenerator(classification_function=2, noise_percentage=0.0) #stream.prepare_for_use() stream = WaveformGenerator() stream.prepare_for_use() # Setup the classifier #classifier = OzaBaggingADWINClassifier(base_estimator=KNNClassifier(n_neighbors=8, max_window_size=2000, # leaf_size=30)) #classifier = LeverageBaggingClassifier(base_estimator=KNNClassifier(n_neighbors=8, max_window_size=2000, # leaf_size=30), # n_estimators=1) pipe = LeverageBaggingClassifier(base_estimator=HoeffdingTreeClassifier(), n_estimators=2) # Setup the pipeline #pipe = Pipeline([('Classifier', classifier)]) # Setup the evaluator evaluator = EvaluatePrequential(pretrain_size=2000, max_samples=instances, output_file=output_file, show_plot=False) # Evaluate evaluator.evaluate(stream=stream, model=pipe)
def main(): global agentNetwork # start agent network agentNetwork = AgentNetwork() # add agents data_stream_agent_1 = agentNetwork.add_agent(agentType=DataStreamAgent) ml_agent_hoeffdingTree = agentNetwork.add_agent(agentType=ML_Model) ml_agent_neuralNets = agentNetwork.add_agent(agentType=ML_Model) monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent) # init parameters data_stream_agent_1.init_parameters(stream=WaveformGenerator(), pretrain_size=1000, batch_size=100) ml_agent_hoeffdingTree.init_parameters(ml_model=HoeffdingTreeClassifier()) ml_agent_neuralNets.init_parameters(ml_model=NaiveBayes()) # connect agents agentNetwork.bind_agents(data_stream_agent_1, ml_agent_hoeffdingTree) agentNetwork.bind_agents(data_stream_agent_1, ml_agent_neuralNets) agentNetwork.bind_agents(ml_agent_hoeffdingTree, monitor_agent_1) agentNetwork.bind_agents(ml_agent_neuralNets, monitor_agent_1) agentNetwork.set_running_state() # allow for shutting down the network after execution return agentNetwork
from skmultiflow.trees.hoeffding_tree import HoeffdingTree from hoeffopttree import HoeffdingOptTree from skmultiflow.evaluation.evaluate_prequential import EvaluatePrequential from skmultiflow.data.file_stream import FileStream from skmultiflow.data import LEDGenerator, RandomTreeGenerator, RandomRBFGenerator, WaveformGenerator import matplotlib as plt plt.interactive(True) #dataset = "elec" dataset = "covtype" #stream = FileStream("./data/"+dataset+".csv", n_targets=1, target_idx=-1) #stream = LEDGenerator() #stream = RandomTreeGenerator() #stream = RandomRBFGenerator() stream = WaveformGenerator(has_noise=False) stream.prepare_for_use() h = [ HoeffdingOptTree(), # HoeffdingTree() ] evaluator = EvaluatePrequential(pretrain_size=1000, max_samples=20000, show_plot=True, metrics=['accuracy'], output_file='result_' + dataset + '.csv', batch_size=1) # 4. Run evaluator.evaluate(stream=stream, model=h, model_names=["HOT"]) '''import pandas as pd
from skmultiflow.data import WaveformGenerator from skmultiflow.trees import HoeffdingTree from skmultiflow.evaluation import EvaluatePrequential import scutds # 1. Create a stream stream = WaveformGenerator() stream.prepare_for_use() # 2. Instantiate the HoeffdingTree classifier sd = scutds.ScutDS() # 3. Setup the evaluator evaluator = EvaluatePrequential(show_plot=False, pretrain_size=1000, batch_size = 1000, max_samples=10000) # 4. Run evaluation evaluator.evaluate(stream=stream, model=sd)
from skmultiflow.data import WaveformGenerator from skmultiflow.trees.hoeffding_tree import HoeffdingTreeClassifier from skmultiflow.evaluation.evaluate_prequential import EvaluatePrequential # Create a stream stream = WaveformGenerator() stream.prepare_for_use() # Not required for v0.5.0+ # Instantiate the HoeffdingTreeClassifier ht = HoeffdingTreeClassifier() # Setup the evaluator evaluator = EvaluatePrequential(show_plot=False, pretrain_size=200, max_samples=20000) # Run evaluation evaluator.evaluate(stream=stream, model=ht)
num_accurate = [1 if y == True else 0 for y in res] accuracy = np.sum(num_accurate) / len(num_accurate) * 100 return accuracy if __name__ == '__main__': #start agent network agentNetwork = AgentNetwork() #add agents data_stream_agent_1 = agentNetwork.add_agent(agentType=DataStreamAgent) ml_agent_hoeffdingTree = agentNetwork.add_agent(agentType=ML_Model) ml_agent_neuralNets = agentNetwork.add_agent(agentType=ML_Model) monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent) #init parameters data_stream_agent_1.init_parameters(stream=WaveformGenerator(), pretrain_size=1000, batch_size=100) ml_agent_hoeffdingTree.init_parameters(ml_model=HoeffdingTree()) ml_agent_neuralNets.init_parameters(ml_model=NaiveBayes()) #connect agents agentNetwork.bind_agents(data_stream_agent_1, ml_agent_hoeffdingTree) agentNetwork.bind_agents(data_stream_agent_1, ml_agent_neuralNets) agentNetwork.bind_agents(ml_agent_hoeffdingTree, monitor_agent_1) agentNetwork.bind_agents(ml_agent_neuralNets, monitor_agent_1) agentNetwork.set_running_state()