python svr回归_python – 支持向量回归(SVR)在Ubuntu 18.04 LTS中...

如果您在Jupyter Ipython笔记本上运行,则只需在代码顶部添加%matplotlib内联.您可以阅读有关它的更多信息here和here.

否则,我复制了你的代码并删除了matplotlib.use(“Agg”),它适用于Ubuntu 18.04,matplotlib 2.2.2版.你能指定你使用的是哪个版本吗?

这里还有代码,

import matplotlib

import numpy as np

from sklearn.svm import SVR

import matplotlib.pyplot as plt

#Generate Sample data

x = np.sort(5 * np.random.rand(40, 1), axis = 0)

y = np.sin(x).ravel()

#Add noise to targets

y[::5] += 3 * (0.5 - np.random.rand(8))

#create classifier regression model

svr_rbf = SVR(kernel="rbf", C=1000, gamma=0.1)

svr_lin = SVR(kernel="linear", C=1000, gamma=0.1)

svr_poly = SVR(kernel="poly", C=1000, gamma=0.1)

#Fit regression model

y_rbf = svr_rbf.fit(x,y).predict(x)

y_lin = svr_lin.fit(x,y).predict(x)

y_poly = svr_poly.fit(x,y).predict(x)

#Plotting of results

lw = 2

plt.scatter(x, y, color="darkorange", label="data")

plt.plot(x, y_rbf, color="navy", lw=lw, label="RBF Model")

plt.plot(x, y_lin, color="c", lw=lw, label="Linear Model")

plt.plot(x, y_poly, color="cornflowerblue", lw=lw, label="Polynomial Model")

plt.xlabel("data")

plt.ylabel("target")

plt.title("Support Vector Regression")

plt.legend()

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值