在SVM中利用对线性核函数和高斯核函数进行调参来对二分类鸢尾花数据分类结果进行比较。从最终的结果来看,调参是很重要的。
其代码如下:import numpy as np
from sklearn import svm
import matplotlib as mpl
import matplotlib.colors
import matplotlib.pyplot as plt
def show_accuracy(a, b):
acc = a.ravel() == b.ravel()
# print '正确率:%.2f%%' % (100*float(acc.sum()) / a.size)
if __name__ == "__main__":
data = np.loadtxt('bipartition.txt', dtype=np.float, delimiter='\t')
x, y = np.split(data, (2, ), axis=1)
y = y.ravel()
clf_param = (('linear', 0.1), ('linear', 0.5), ('linear', 1), ('linear', 2),
('rbf', 1, 0.1),