SVM→8.SVM實戰→3.調節SVM參數
阿新 • • 發佈:2018-10-08
復雜 flatten 標簽 decision display autumn 技術分享 分享圖片 每次 《SVM→8.SVM實戰→3.調節SVM參數》
Show 拓展參考見SVM→8.SVM實戰→1.訓練一個基本的SVM
描述 | 代碼 | ||
---|---|---|---|
|
| ||
|
| ||
|
| ||
|
|
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‘) |
SVM→8.SVM實戰→3.調節SVM參數