Question

Excuse my ignorance, I'm very new to Python. I'm trying to perform factor analysis in Python using MDP (though I can use another library if there's a better solution).

I have an m by n matrix (called matrix) and I tried to do:

import mdp
mdp.nodes.FANode()(matrix)

but I get back an error. I'm guessing maybe my matrix isn't formed properly? My goal is find out how many components are in the data and find out which rows load onto which components.

Here is the traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mdp/signal_node.py", line 630, in __call__
    return self.execute(x, *args, **kwargs)
  File "mdp/signal_node.py", line 611, in execute
    self._pre_execution_checks(x)
  File "mdp/signal_node.py", line 480, in _pre_execution_checks
    self.train(x)
  File "mdp/signal_node.py", line 571, in train
    self._check_input(x)
  File "mdp/signal_node.py", line 429, in _check_input
    if not x.ndim == 2:
AttributeError: 'list' object has no attribute 'ndim'

Does anyone have any idea what's going on, and feel like explaining it to a Python newbie?

Was it helpful?

Solution

I have absolutely no experience with mdp, but it looks like it expects your matrices to be passed as a Numpy array instead of a list. Numpy is a package for high performance scientific computing. You can go to the Numpy home page and install it. After doing so, try altering your code to this:

import mdp, numpy
mdp.nodes.FANode()(numpy.array(matrix))

OTHER TIPS

As Stephen said, the data must be a numpy array. More precisely it must be a 2D array, with the first index representing the different sampes and the second index representing the data dimensions (using the wrong order here can lead to the "singular matrix" error).

You should also take a look at the MDP documentation, which should answer all your questions. If that doesn't help there is the MDP user mailing list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top