会网站开发维护的ps什么岗位,廊坊市建设局官方网站,怎样建设自己的ip地址网站,做国外百科知识网站#x1f308;#x1f308;#x1f308;机器学习 实战系列 总目录 本篇文章的代码运行界面均在Pycharm中进行 本篇文章配套的代码资源已经上传 SVM分类实战1之简单SVM分类 SVM分类实战2线性SVM SVM分类实战3非线性SVM
4、非线性SVM
4.1 创建非线性数据
from sklearn.data…机器学习 实战系列 总目录 本篇文章的代码运行界面均在Pycharm中进行 本篇文章配套的代码资源已经上传 SVM分类实战1之简单SVM分类 SVM分类实战2线性SVM SVM分类实战3非线性SVM
4、非线性SVM
4.1 创建非线性数据
from sklearn.datasets import make_moons
X, y make_moons(n_samples100, noise0.15, random_state42)def plot_dataset(X, y, axes):plt.plot(X[:, 0][y0], X[:, 1][y0], bs)plt.plot(X[:, 0][y1], X[:, 1][y1], g^)plt.axis(axes)plt.grid(True, whichboth)plt.xlabel(r$x_1$, fontsize20)plt.ylabel(r$x_2$, fontsize20, rotation0)plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
plt.show()4.2 分类预测
from sklearn.datasets import make_moons
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures
polynomial_svm_clfPipeline(((poly_features,PolynomialFeatures(degree3)),(scaler,StandardScaler()),(svm_clf,LinearSVC(C10,losshinge))))
polynomial_svm_clf.fit(X,y)使用PolynomialFeatures模块进行预处理使用这个可以增加数据维度polynomial_svm_clf.fit(X,y)对当前进行训练传进去X和y数据
def plot_predictions(clf,axes):x0s np.linspace(axes[0],axes[1],100)x1s np.linspace(axes[2],axes[3],100)x0,x1 np.meshgrid(x0s,x1s)X np.c_[x0.ravel(),x1.ravel()]y_pred clf.predict(X).reshape(x0.shape)plt.contourf(x0,x1,y_pred,cmapplt.cm.brg,alpha0.2)plot_predictions(polynomial_svm_clf,[-1.5,2.5,-1,1.5])
plot_dataset(X,y,[-1.5,2.5,-1,1.5])5、核函数
5.1 核函数
from sklearn.svm import SVCpoly_kernel_svm_clf Pipeline([(scaler, StandardScaler()),(svm_clf, SVC(kernelpoly, degree3, coef01, C5))])poly_kernel_svm_clf.fit(X, y)poly100_kernel_svm_clf Pipeline([(scaler, StandardScaler()),(svm_clf, SVC(kernelpoly, degree10, coef0100, C5))])poly100_kernel_svm_clf.fit(X, y)plt.figure(figsize(11, 4))plt.subplot(121)
plot_predictions(poly_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
plt.title(r$d3, r1, C5$, fontsize18)plt.subplot(122)
plot_predictions(poly100_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
plt.title(r$d10, r100, C5$, fontsize18)plt.show()5.2 高斯核函数
SVM分类实战1之简单SVM分类 SVM分类实战2线性SVM SVM分类实战3非线性SVM