一、安装
在pycharm或者spyder上安装scikit-multiflow可能会遇到各种问题,只能耐心一点,多在网上找找教程。具体的安装过程可以参考以下b站上的视频教程,当然以下教程也不是包治百病。
如何在Anaconda上安装及卸载第三方包_哔哩哔哩_bilibili
二、代码
下面是一份完整的python代码,注释里面的方法不成功,错误提示为EvaluatePrequential导入不成功。
from skmultiflow.data import SEAGenerator
from skmultiflow.trees import HoeffdingTree
from skmultiflow import EvaluatePrequential
import matplotlib.pyplot as plt
import numpy as np
stream = SEAGenerator() '''创建数据流
stream.prepare_for_use()
nb_iters=100
tree = HoeffdingTree() '''创建HoeffdingTree
correctness_dist = []
for i in range(nb_iters):
X,Y = stream.next_sample()
prediction = tree.predict(X)
if Y==prediction:
correctness_dist.append(1)
else:
correctness_dist.append(0)
tree.partial_fit(X,Y)
time = [i for i in range(nb_iters)]
sumValue=0
accuracy= np.zeros(len(correctness_dist))
for i in range(len(correctness_dist)):
sumValue = sumValue + correctness_dist[i]
accuracy[i] = (sumValue*1.0)/(i+1)
print(accuracy)
plt.plot(time,accuracy)
'''
evaluator = EvaluatePrequential(show_plot=True, max_sample=nb_iters)
evaluator.evaluate(stream=stream,model=tree)
'''
三 参考文献
本博客参考了以下网络资源:
进一步的学习,可以上官网查阅资料:scikit-multiflow