Exemplo n.º 1
0
 def fit(self, X, Y):
     self.knnList = []
     for column in range(len(Y[0])):
         yvar = np.zeros((len(Y), 1))
         for row in range(len(Y)):
             yvar[row][0] = Y[row][column]
         self.knnList.append(KNN(k=10, max_window_size=100, leaf_size=30))
         self.knnList[column].fit(X, yvar)
     return self
Exemplo n.º 2
0
 def partial_fit(self, X, y, classes=None):
     if len(self.knnList) == 0:
         self.knnList = []
         for i in range(len(y[0])):
             self.knnList.append(KNN(k=10, max_window_size=100, leaf_size=30))
     self.L = len(y[0])
     for column in range(len(y[0])):
         yvar = y[:, column]
         self.knnList[column].partial_fit(X, yvar)
     return self
from skmultiflow.evaluation.evaluate_prequential import EvaluatePrequential
from skmultiflow.options.file_option import FileOption

from my_classifier import BatchClassifier

dataset = "elec"

# 1. Create a stream
opt = FileOption("FILE", "OPT_NAME", "./data/" + dataset + ".csv", "CSV",
                 False)
stream = FileStream(opt, -1, 1)
# 2. Prepare for use
stream.prepare_for_use()
# 2. Instantiate the HoeffdingTree classifier
h = [
    KNN(k=10, max_window_size=100, leaf_size=30),
    HoeffdingTree(),
    BatchClassifier(window_size=100, max_models=10),
]
# 3. Setup the evaluator
eval = EvaluatePrequential(pretrain_size=1000,
                           output_file='result_' + dataset + '.csv',
                           max_instances=10000,
                           batch_size=1,
                           n_wait=500,
                           max_time=1000000000,
                           task_type='classification',
                           show_plot=True,
                           plot_options=['performance'])
# 4. Run
eval.eval(stream=stream, classifier=h)