pythonnumpymatrixpython-3.6gwr

Facing LinAlgError: Matrix is singular


Community,

The language barrier is hitting me hard. Somehow I managed to learn with a model, but I can't predict, as it now says my Matrix is singular - which I don't understand - is it another word for unique?

Anyhow, here the important bits:

X.shape

(457, 123)

coord.shape

(457, 2)

pred = model.predict(coord, X)

File "...\venv3\lib\site-packages\spglm\iwls.py", line 37, in _compute_betas_gwr xtx_inv_xt = linalg.solve(xtx, xT)

File "...\venv3\lib\site-packages\scipy\linalg\basic.py", line 216, in solve _solve_check(n, info)

File "...\venv3\lib\site-packages\scipy\linalg\basic.py", line 31, in _solve_check raise LinAlgError('Matrix is singular.')

numpy.linalg.LinAlgError: Matrix is singular.

.

In X and coord are numbers (positive and few negative ones, coord are coordinates longitude and latitude).

The Model im trying to use is from this Library:

from mgwr.gwr import GWR

Docs found here

Prediction is here

Any help would greatly be appreciated!

Best Regards


Solution

  • A singular matrix is one that cannot be inverted. You can usually solve this by adding some small delta to all entries of the matrix you're trying to invert.