【发布时间】:2019-05-13 19:02:59
【问题描述】:
我是编程新手,我正在尝试让图形在 Python 中工作。但我遇到了某种错误,图表不会显示。我在 Ubuntu 操作系统上。希望一些 Python 大师可以解释什么是错误的以及如何解决它。
代码:
import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
dates = []
prices = []
def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
dates.append(int(row[0].split('-')[0]))
prices.append(float(row[1]))
return
def predict_prices(dates, prices, x):
dates = np.reshape(dates,(len(dates), 1))
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree = 2)
svr_rbf = SVR(kernel='rbf',C=1e3, gamma = 0.1)
svr_rbf.fit(dates, prices)
svr_poly.fit(dates, prices)
svr_rbf.fit(dates, prices)
plt.scatter(dates, prices, color='black', label='Data')
plt.plot(dates, svr_rbf.predict(dates), color='red', label='RBF model')
plt.plot(dates, svr_lin.predict(dates), color='green', label='Linear
model')
plt.plot(dates, svr_poly.predict(dates), color='blue', label='Polynomial
model')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Support Vector Regression')
plt.legend()
plt.show()
return svr_rbf.predict(x)[0], svr_lin.predict(x)[0], svr_poly.predict(x)
[0]
get_data('aapl.csv')
predicted_price = predict_prices(dates, prices, 29)
print(predicted_price)
导致此错误:
/home/xxx/.local/lib/python3.6/site-packages/sklearn/svm/base.py:196:
FutureWarning:在 0.22 版本中,gamma 的默认值将从“auto”更改为“scale”,以更好地考虑未缩放的功能。将 gamma 显式设置为“auto”或“scale”以避免出现此警告。
【问题讨论】:
-
您上面显示的“错误”实际上是来自 sklearn 的警告。它不会以任何方式影响您的代码的工作。未显示的图完全是一个不同的错误。显示带有数据样本的完整代码,以便我们可以尝试重现它。还显示有关您的系统、操作系统、库版本的详细信息可能会有所帮助/
标签: python numpy matplotlib scikit-learn