0

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

TiRoX
  • 31
  • 7

1 Answers1

1

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.

Mark Snyder
  • 1,635
  • 3
  • 12
  • ah, so the issues are the 0 values? – TiRoX Jan 09 '20 at 20:58
  • @TiRoX: No. For instance, the identity matrix, which has ones on the main diagonal and zeroes everywhere else is invertible. – Bill Bell Jan 09 '20 at 21:02
  • @TiRoX The issue is that your matrix does not consist of linearly independent columns (or rows). Its determinant is zero. – Mark Snyder Jan 09 '20 at 21:07
  • okay, so its an issue with the data itself and not the structure. thanks – TiRoX Jan 09 '20 at 23:25
  • Hi Mr. Snyder, i also have similar problem.. do you mean small delta is a small value ? i already try to add small value in my data but it still produces same error.. – SongJL Jan 20 '21 at 03:30
  • @SongJL Yeah, a small value. However, my original answer is not very complete. For example, I didn't point out that only square matrices are invertible. Since OP's matrix is obviously not square, but it worked at some point, the singular matrix error must be from some kind of derived matrix within the model. Nevertheless, the answer is almost certainly the same - it's a data problem. Try adding a small value (e.g. .001) to the main diagonal of your data matrix, and if that doesn't work, try adding it to all of your data. Then try filtering your data different ways - does it work if square? – Mark Snyder Jan 21 '21 at 04:37
  • Hey, a little addition by me. @MarkSnyder is totally correct. My issue was that, it would try to use hindering-values, which obviously doesn't work within that procedure. Thus a small delta can be a way out, however it rendered the model useless for me also calculations were much further off. I decided to use another approach completely. https://math.stackexchange.com/questions/886930/inverse-matrix-and-its-zero-entries <- had a little more context to it. – TiRoX Jan 22 '21 at 11:49