New to ML trying to use SVM and SVR for 1st time some syntax/transposition errors

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


New to ML trying to use SVM and SVR for 1st time some syntax/transposition errors



I am trying to run A SVR on some data I got from yahoo finance. I want to use closing prices of Ethereum to predict next 10-15 days path using a supervised learning method. I have already done autoregressive model (ARIMA) but now I want to try ML techniques like pattern recognition so I start with SVR



I am simply running into a problem that I dont know how to convert my data column into a row so that the SVR works...I thought it would be simple but I am new to coding overall...appreciate your help; see below:



''' building a simple model for using machine learning to do pattern recog on stock prices'''


import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.pylab as ply
import numpy as np
from pandas import DataFrame as df
from sklearn.svm import SVR

df = pd.read_csv("C:LearningETH.csv", index_col='Date', parse_dates=True)
prices = df['Adj Close']
dates = df.index
dates = dates.values.reshape(1,len(dates))

# run support vector regressions to get next predicted value
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3)
svr_rbf = SVR(kernel='rbf', C=1e3)
svr_lin.fit(dates, prices)
svr_lin.poly(dates, prices)
svr_lin.rbf(dates, prices)



When I run this I get following error:



Traceback (most recent call last): File "C:/Users/.../Machine
Learning/MachLearningStockPrediction.py", line 19, in
svr_lin.fit(dates, prices) File "C:Users...AppDataLocalContinuumanaconda3libsite-packagessklearnsvmbase.py",
line 149, in fit
X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr') File
"C:Users...AppDataLocalContinuumanaconda3libsite-packagessklearnutilsvalidation.py",
line 583, in check_X_y
check_consistent_length(X, y) File "C:Users...AppDataLocalContinuumanaconda3libsite-packagessklearnutilsvalidation.py",
line 204, in check_consistent_length
" samples: %r" % [int(l) for l in lengths]) ValueError: Found input variables with inconsistent numbers of samples: [1, 1085]



Length of both prices and dates is same 1085 characters



Please help




1 Answer
1



When you do this:


dates = dates.values.reshape(1,len(dates))



dates will be converted to a row vector which have 1 rows and 1085 columns. In scikit-learn, the required data for X (data features) is [n_samples, n_features]. So here, scikit thinks that your data have only 1 sample with 1085 features.


dates


[n_samples, n_features]



But then your prices is of shape [1085, ] which according to scikit should have shape [n_samples, ]. So here number of samples are taken as 1085. And hence the error.


prices



You should do this to correct the error:


dates = dates.values.reshape(len(dates), 1)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results