源码
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from sklearn import svm
plt.figure(figsize=(5, 4), dpi=140)
plt.subplot(1, 1, 1)
n = 100
x = np.linspace(0,6,n)
x.resize((n,1))
y = 0.6*x*x*np.sin(x*3) + 6*x + 1 + np.random.rand(n,1)*6
# print(y.shape)
# print(x.shape)
plt.title('rbf_SVC')
ax = plt.gca() # gca 代表当前坐标轴,即 'get current axis'
ax.spines['right'].set_color('none') # 隐藏坐标轴
ax.spines['top'].set_color('none')
rbf_svr = svm.SVR(kernel='rbf', C=100) # C越大越容易过拟合
rbf_svr.fit(x, y)
y_pred = rbf_svr.predict(x)
plt.scatter(x,y)
plt.plot(x,y_pred)
plt.show()