-1

I want to generate an elbow plot for a pre-processed dataset which has been read from an excel file. In the next step, I want to generate an Elbow Plot by using the plot method from the package matplotlib. After executing the code I got the following error:

ValueError: x and y must have same first dimension, but have shapes (10,) and (1,)

The code looks like the following:

plt.plot(range(1, 11), wcss, linewidth = 4, color = 'black', marker = 'D', markersize = 10)
plt.title('The Elbow Method', family = 'Arial', fontsize = 14, color = 'black')
plt.xlabel('Number of Clusters', family = 'Arial', fontsize = 12, color = 'black')
plt.ylabel('WCSS', family = 'Arial', fontsize = 12, color = 'black')
plt.xticks(fontsize = 12, color = 'black')
plt.yticks(fontsize = 12, color = 'black')
plt.grid(which = 'both', color = 'black', axis = 'x', alpha = 0.5)

Where could the problem be?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
kayprog
  • 3
  • 2

2 Answers2

0

The variable wcss seems to be a scalar and not a vector.

We can't really answer this without knowing how you created the variable wcss. But you should probably take a look at that variable.

Michael
  • 153
  • 1
  • 6
0

Please note that in x-axis you are plotting 10 points(that is range(1,11))but seems in your wccs variable there is just one value, You have to match the numbers for both x and y, you cant have 1 'y' for ten different 'x'. Relook and adjust either the range or values in wccs as per your need.

think-maths
  • 917
  • 2
  • 10
  • 28