2

I'm trying to load an array, x, into a regression (reg = linear_model.LinearRegression()) so that I run the prediction function multiple times.

However, whenever I try to load the array using the following:

for i in range(0,15):

    reg.predict(np.array(x[i]))

I get a value error Expected 2D array, got 1D array instead.

As this is a multivariate regression, with the array x looking like the following, reshaping the array is not possible.

array([[5.53600000e-01, 5.02666280e-02, 4.12000000e+01, 3.04170300e-03,
        2.96966300e-02, 9.51813015e-01, 1.43949843e-01, 5.84400000e+04,
        4.60000000e-02, 1.02944112e-01, 9.80000000e+00, 3.61169102e-01,
        3.53892821e-01, 3.73737374e-01, 3.25972495e-01, 2.29560501e-01],
       [6.87500000e-01, 8.92363030e-02, 4.76000000e+01, 3.55677200e-03,
        2.27086180e-02, 9.63474692e-01, 1.27620108e-01, 4.55930000e+04,
        5.30000000e-02, 1.18176453e-01, 1.46000000e+01, 4.36458333e-01,
        4.27125506e-01, 4.57230143e-01, 3.88632873e-01, 2.63273125e-01]...

Thanks!

EDIT:

Fix found -

for i in range(0,15):

    reg.predict(np.array([x[i]]))

Missing square brackets !

2
  • 1
    what is the shape of np.array(x[i]) ? can you post some data and code? Commented Jan 22, 2020 at 11:26
  • Apologies, have found a fix, please see main post. Thanks. Commented Jan 22, 2020 at 11:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.