Hi all, I am trying to calculate mutual information for feature selection. But I have faced this error. I also attached a snapshot of the code.
This is because 57021 is not divisible by 3. Try
(16907, 3) instead:
>>> import numpy as np >>> a = np.array( * 50721) >>> a.reshape((16908, 3)) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: cannot reshape array of size 50721 into shape (16908,3) >>> a.reshape((16907, 3)) array([[0, 0, 0], [0, 0, 0], [0, 0, 0], ..., [0, 0, 0], [0, 0, 0], [0, 0, 0]])
I have got your solution, but I don’t know how to apply it to the code as the number 50721 came from output of the calculation of mutual_info_classif(x_train, y_train).
I am unfamiliar with everything your script is doing, but you must reshape data in a way compatible with the actual size of your data. Your script may or may not be returning the information correctly for you, I don’t know, but if you need to arrange the data in columns of 3, you must make sure it is divisible by three and then calculate how many rows you need.
>>> 50721 % 3 0 >>> 50721 / 3 16907.0
Why use a snapshot of the code? Do you write your code using photoshop? Please don’t do it.
Copy and paste the code as text and place it between code fences as explained here:
You clearly don’t.
Always code fences. Never snapshots. Simple.