说我有一个sklearn培训数据:
features, labels = assign_dataSets() #assignment operation
此处feature
是二维数组,而label
包含一个由值[0,1]
分类操作:
f1x = [features[i][0] for i in range(0, len(features)) if labels[i]==0]
f2x = [features[i][0] for i in range(0, len(features)) if labels[i]==1]
f1y = [features[i][1] for i in range(0, len(features)) if labels[i]==0]
f2y = [features[i][1] for i in range(0, len(features)) if labels[i]==1]
现在我绘制上述数据:
import matplotlib.pyplot as plt
plt.scatter(f1x,f1y,color='b')
plt.scatter(f2x,f2y,color='y')
plt.show()
现在我想用分类器运行拟合操作,例如SVC。
from sklearn.svm import SVC
clf = SVC()
clf.fit(features, labels)
现在我的问题是因为支持向量真的很慢,有没有办法实时监控分类器的决策边界(我的意思是正在进行拟合操作)?我知道我可以在拟合操作发生后绘制决策边界,但我希望分类器的绘图能够实时进行。也许是对线性空间声明的点数组进行线程化和运行预测。 fit函数是否允许这样的操作,还是我需要去其他库?
你知道,我是机器学习的新手。
答案 0 :(得分:2)
scikit-learn有这个功能,但它仅限于我理解的一些分类器(例如istream
,GradientBoostingClassifier
)。要启用此功能,您需要设置MPLClassifier
。例如:
verbose=True
我尝试使用clf = GradientBoostingClassifier(verbose=True)
并且没有按预期工作(可能是因为评论部分中提到的 sascha )。 Here是您在StackOverflow上的问题的不同变体。
关于第二个问题,如果切换到SVC
(另一个机器学习库),您可以使用Tensorflow
功能实时监控一些指标(例如错误衰减)
但是,据我所知,SVM实现仍在tensorboard
中进行实验。使用基于神经网络的模型时,v1.5
非常好。
如果你决定使用DNN进行分类Tensorflow
,那么这里是关于StackOverflow实现的讨论:No easy way to add Tensorboard output to pre-defined estimator functions DnnClassifier?
有用的参考资料:
Tensorflow SVM(现在只支持线性支持 - v1.5):https://www.tensorflow.org/api_docs/python/tf/contrib/learn/SVM
Tensorflow Kernals方法:https://www.tensorflow.org/versions/master/tutorials/kernel_methods
Tensorflow Tensorboard:https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard
Tensorflow DNNClassifier Estimator:https://www.tensorflow.org/api_docs/python/tf/estimator/DNNClassifier