.card { font-family: arial; font-size: 20px; text-align: left; color: black; background-color: white }
.cloze { font-weight: bold; color: red }
.myCode { font-family: droid sans mono; background-color: #f2f2f2; padding-left: 5px; padding-right: 5px }
《SVM→8.SVM实战→3.调节SVM参数》
描述 | 代码 | ||
---|---|---|---|
|
|
||
|
|
||
|
plot_svc_decision_function参考见扩展 |
||
|
|
Show 拓展
参考见SVM→8.SVM实战→1.训练一个基本的SVM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
def plot_svc_decision_function(model, ax=None, plot_support=True): """Plot the decision function for a 2D SVC""" if ax is None: ax = plt.subplot(111) xlim = ax.get_xlim() ylim = ax.get_ylim() # create grid to evaluate model x = np.linspace(xlim[0], xlim[1], 30) y = np.linspace(ylim[0], ylim[1], 30) X,Y = np.meshgrid(x, y) xy = np.vstack([X.flatten(), Y.flatten()]).T P = model.decision_function(xy).reshape(X.shape) # plot decision boundary and margins #levels是 alpha是透明度 linestyles ax.contour(X, Y, P, colors=‘k‘, levels=[-1, 0, 1], alpha=0.5, linestyles=[‘--‘, ‘-‘, ‘--‘]) # plot support vectors if plot_support: ax.scatter(model.support_vectors_[:, 0], model.support_vectors_[:, 1], s=500,c=‘‘,edgecolors=‘black‘) |
原文地址:https://www.cnblogs.com/LeisureZhao/p/9752733.html
时间: 2024-10-28 21:37:14