Issue
I am trying to train and predict with an affinity propagation model for the first time.
Here is my code:
import numpy as np
from sklearn.cluster import AffinityPropagation
data = np.array([[0.1,0.1,0.4], [0.0, 0.1, 0.5], [0.7,0.5,0.2]])
affprop = AffinityPropagation(affinity="euclidean", damping=0.7, random_state=0)
affprop.fit(data)
data_2 = np.array([[0.1,0.1], [0.0, 0.1], [0.7,0.5]])
affprop.predict(data_2)
However when I run this I get the following error:
ValueError: X has 2 features, but AffinityPropagation is expecting 3 features as input.
Am I misunderstanding how affinity propagation works with prediction? I want to be able to feed my trained model new data. Does the number of dimensions (i.e. length of each sub-list) need to be the same as the trained data?
Solution
Each element in data_2
should be of the same shape as each element in data_1
here (3,1)
Either data_2 = np.array([[0.1, 0.1, 0.1], [0.0, 0.1, 0.2], [0.7, 0.5, 0.25]])
or data_2 = np.array([[0.1,0.1, 0.1]])
would work.
You're trying to predict the cluster that your new data belongs to, so it must lies in the same n-dimensional space.
Answered By - NassimH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.