Reputation: 13
I am working on a school project where we are using SVR to predict the next value of a series of values (e.g. stock values). We found some example code on scikit (Python) which we aren't able to understand the syntax for.
Could someone help us decipher this?
X = np.sort(5 * np.random.rand(40, 1), axis=0)
Y = np.sin(X).ravel()
from sklearn.svm import SVR
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
y_rbf = svr_rbf.fit(X, Y).predict(X)
I understand the first 4 lines of this code... my issue is more with the y_rbf line... how exactly does this work? Are we doing a curve fit based on the training set and then predicting based on the same input vector?
I am not sure what the syntax means. Any help is appreciated.
Thank you.
Upvotes: 1
Views: 1589
Reputation: 1905
The last line can be broken up into:
svr_rbf.fit(X, Y) # 1
y_rbf = svr_rbf.predict(X) # 2
You build a model of how the output y depends on X. According to the documentation you:
Fit the SVM model according to the given training data.
Here you use the model you built previously to predict the values (y) for each point. As the documention puts it:
Perform regression on samples in X.
This is fine for an experiment, but just to make you aware: in general you'll want to test your model on data other than what was used to fit the model to avoid overfitting. You can read about cross-validation if you are not familiar with it.
Upvotes: 1