1
$\begingroup$

I have a time series dataset which represented as following:

x=[ 
       [12.19047619,  18.28571429,   6.0952381 ] ,

       [ 80.98765432,  14.17283951,  11.13580247 ] ,

       [ 50.82644628,  16.26446281,   9.14876033 ] , .... ]


and to predicted -->
 Y  = [13.9,  18,   14.987]

How I can use LASSO and SVR linear regression models in python to predict Y (which represented as a vector as shown in the above example)

$\endgroup$
  • $\begingroup$ What is time series in this? It seems data with 3 features only. $\endgroup$ – rnso Oct 30 '18 at 1:46
  • $\begingroup$ These features are changing over time, so vector # 1 in x is taken at time t(i) and vector # 2 is taken at time t(i+1) and so on $\endgroup$ – Neno M. Oct 30 '18 at 3:55
  • $\begingroup$ Why are you calling it multiple outputs? There is only one output per row or sample or observation of X. $\endgroup$ – rnso Oct 30 '18 at 8:56
1
$\begingroup$

Both Lasso and SVM are available in sklearn library. Lasso: sklearn.linear_model.Lasso. SVM: sklearn.svm.SVT

An example from Lasso page:

>>> from sklearn import linear_model
>>> clf = linear_model.Lasso(alpha=0.1)
>>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000, normalize=False, positive=False, precompute=False, random_state=None, selection='cyclic', tol=0.0001, warm_start=False)
>>> print(clf.coef_)
[0.85 0. ]
>>> print(clf.intercept_)
0.15...

In your case clf.fit looks like this:

clf.fit(X, Y)

X should be the size (nn,n)
Y should be the size nn
Where nn is the number of observations (points) and n is the number of variables. So rows in X are observations and columns are different variables.

If you have more variables than observations then you should read this post about the problems you can have with it and how to solve them.

$\endgroup$
  • $\begingroup$ Thanks @keiv.fly ... I followed the exact same steps but it gives --> ValueError: Found input variables with inconsistent numbers of samples: [4, 3] .... This is when I have 4 sample and each sample with 3 dimensions and the output is expected to be a vector with 3 dimensions $\endgroup$ – Neno M. Oct 29 '18 at 18:00
  • $\begingroup$ What is the output of x.shape and y.shape? $\endgroup$ – keiv.fly Oct 29 '18 at 18:22
  • $\begingroup$ x.shape --> (4,3) .... y.shape --> (3,) .... I am not sure but it seems I should take the transpose of x before fitting? $\endgroup$ – Neno M. Oct 29 '18 at 18:25
  • $\begingroup$ please check the edited response $\endgroup$ – Neno M. Oct 29 '18 at 18:27
  • $\begingroup$ y should be 4. You have 3 x variables. For every observation (row) you should have all x variables and one y. So in your case you have 4 observations (rows of x) and you should have 4 observations for y. $\endgroup$ – keiv.fly Oct 29 '18 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.