SciPy - ValueError: all the input array dimensions for the concatenation axis must match exactly

Viewed 672

So I'm working on a problem where I need to simply use SciPy to perform linear regression to get the weights and statistics on the weights, but I'm getting the error "ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 11 and the array at index 1 has size 100"

The code is simply:

from scipy import stats

x = x_copy
y = y_copy

stats.linregress(x, y)

Where x is a dataframe and y is a numpy array.

When doing x.shape and y.shape I get that x is (100, 11) and y is (100,). Running the exact same matrices in np.linalg.lstsq and sklearn.linear_model.LinearRegression both work fine and output the weights, but as far as I'm aware I need SciPy to get the statistics on the weights themselves.

I've also checked x.dtypes and all variables are float64, and y.dtype also returns float64. I've also tried replacing to x in the regression call with x.to_numpy() incase there was something with the headers/index but received the same issue.

Any suggestions?

Edit:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_28012/197024375.py in <module>
      4 y = y_copy
      5 
----> 6 stats.linregress(x.values, y)
      7 
      8 x.values.shape

~\anaconda3\lib\site-packages\scipy\stats\_stats_mstats_common.py in linregress(x, y, alternative)
    153     #   ssxm = mean( (x-mean(x))^2 )
    154     #   ssxym = mean( (x-mean(x)) * (y-mean(y)) )
--> 155     ssxm, ssxym, _, ssym = np.cov(x, y, bias=1).flat
    156 
    157     # R-value

<__array_function__ internals> in cov(*args, **kwargs)

~\anaconda3\lib\site-packages\numpy\lib\function_base.py in cov(m, y, rowvar, bias, ddof, fweights, aweights, dtype)
   2426         if not rowvar and y.shape[0] != 1:
   2427             y = y.T
-> 2428         X = np.concatenate((X, y), axis=0)
   2429 
   2430     if ddof is None:

<__array_function__ internals> in concatenate(*args, **kwargs)

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 11 and the array at index 1 has size 100```
0 Answers
Related