The problematic part is:
self.H = np.multiply(self.H, np.divide(np.matmul(preprocessing.normalize(self.W).T, np.multiply(self.X, np.power(self.A, self.beta - 2)))), np.matmul(self.W.T, np.power(self.A, self.beta - 1)) + self.sparsity)
A, W, H are Panda dataframes. Beta and sparsity are integers.
Their initialization are:
self.W = pd.DataFrame(np.random.randint(100,size=(self.X.shape[0], self.K)))
self.H = pd.DataFrame(np.random.randint(0,100,size=(self.K, self.X.shape[1])))
self.W = preprocessing.normalize(self.W)
self.A = self.W.dot(self.H)
Type Error: can't multiply sequence by non-int of type 'float'
means exactly what it says. You cannot multiply a non-number(non-int) data type with a numbered data type.
For example, you cannot multiply strings with a number.
The above code you have submitted actually works. But, since you are getting this error, I assume the above code is just a proxy for your actual code. So, I'll tell how I solved the same error that I had gotten when I was doing something similar.
Let's say there is a csv file that contains the subject marks for a class like the table below
| | Maths | English |
| Adam | 98 | 78 |
| John | 34 | 89 |
As you can see, there is a row index as well as a column index. If you run
marks = pd.read_csv("marks.csv")
marks
will have 3 columns with the firs column containing the names of the students. Pandas
read assumed the first column was part of the data. Now, if you multiply this with a Numpy
array, you will get an error. Since, numbers can't be multiplied with strings.
To solve this, we need to explicitly tell pandas that the first column in the file is the row index.
marks = pd.read_csv("marks.csv", index_col=0)
The parameter, index_col
tells which column in the file to take as the row index.
You can read about this in detail in their documentation, here.