I am trying to predict the future prices of petroleum but before that I wrote a simple function to see the dates vs price comparison using matplotlib visualization. However there is something wrong in the code and I am not able to find what should I pass. Here is the code:
dates=[]
prices=[]
def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-')[0]))
prices.append(float(row[2]))
return
def predicted_price(dates, prices, x):
dates=np.reshape(dates,len(dates),1)
svr_linear= 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_linear.fit(dates,prices)
svr_ploy.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.poly.predict(dates), color='blue', label='Poly Model')
plt.plot(dates, svr.linear.predict(dates), color='green', label='Linera Model')
plt.xlabel('Dates')
plt.ylabel('Prices')
plt.title('Regression')
plt.legend()
plt.show()
return svr_rbf.predict(x[4]), svr_linear(x[4]), svr_poly(x[4])
getdata('D:\\android\\trans1.csv')
predicted_prices=predicted_price([dates,prices,10])
print(predicted_prices)
Here is the error:
TypeError: Traceback (most recent call last)
<ipython-input-20-935270aaab8d> in <module>()
38 getdata('D:\\android\\trans1.csv')
39
---> 40 predicted_prices=predicted_price([dates,10.2,10])
41 print(predicted_prices)
TypeError: predicted_price() missing 2 required positional arguments: 'prices' and 'x'
Here is the data snapshot: enter image description here
predicted_prices = predicted_price(dates, 10.2, 10)