modAL icon indicating copy to clipboard operation
modAL copied to clipboard

Broadcasting error in avg_score

Open shubhamgp47 opened this issue 1 year ago • 1 comments

I get the following error with avg_score multilabel strategy -

File "C:\Users\localuserSKSG\anaconda3\envs\alenv\lib\site-packages\modAL\models\base.py", line 175, in query query_result, query_metrics = self.query_strategy( File "C:\Users\localuserSKSG\anaconda3\envs\alenv\lib\site-packages\modAL\multilabel.py", line 258, in avg_score classwise_scores = classwise_confidence*(classwise_predictions-1/2) ValueError: operands could not be broadcast together with shapes (26872,2,3) (26872,3)

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "avg-score.py", line 264, in query_index, query_instance = learner.query(X_pool_np, n_instances=n_instances) File "C:\Users\localuserSKSG\anaconda3\envs\alenv\lib\site-packages\modAL\models\base.py", line 180, in query query_result = self.query_strategy( File "C:\Users\localuserSKSG\anaconda3\envs\alenv\lib\site-packages\modAL\multilabel.py", line 258, in avg_score classwise_scores = classwise_confidence*(classwise_predictions-1/2) ValueError: operands could not be broadcast together with shapes (26872,2,3) (26872,3)

We do not see this error with avg_confidence. Clearly this is because of these lines of code in avg_score which are not present in avg_confidence-

classwise_predictions = classifier.predict(X_pool) classwise_scores = classwise_confidence*(classwise_predictions-1/2)

Does anyone has a solution/workaround for this?

shubhamgp47 avatar Dec 03 '24 12:12 shubhamgp47

The error message indicates that the classwise_confidence and classwise_predictions - 1/2 arrays have incompatible shapes and cannot be broadcast together.

Understanding the Issue: • classwise_confidence has shape (26872, 2, 3). • classwise_predictions - 1/2 has shape (26872, 3). • Since they do not match, NumPy cannot perform element-wise multiplication.

Possible Fix: 1. Check classifier.predict(X_pool) Output: • The shape mismatch suggests that classifier.predict(X_pool) returns (26872, 3), while classwise_confidence has an extra dimension (26872, 2, 3). • Ensure that classifier.predict(X_pool) returns the expected number of class probabilities. If it is returning a (26872, 3), confirm why classwise_confidence has (26872, 2, 3).

naveedyassin avatar Mar 22 '25 12:03 naveedyassin