0

I am using the following code to create a silhouette coefficient plot with KElbowVisualizer:

# Import the KElbowVisualizer method 

# Instantiate a scikit-learn K-Means model
model = KMeans(random_state=0)

# Instantiate the KElbowVisualizer with the number of clusters and the metric 
titleKElbow = "title"

visualizer = KElbowVisualizer(model, k=(2,7), metric='silhouette', timings=False,title = titleKElbow)

# Fit the data and visualize
visualizer.fit(df[['a','b','c']])    
visualizer.poof()  

In the resulting plot the x axis label is 'k'. How can I change the axis labels on the resulting plot? I have tried the documentation, but as far as I know it only shows how to add axis labels in a plt style plot.

Thelonious Monk
  • 426
  • 5
  • 19

1 Answers1

3

You can retrieve the ax property of the visualizer and use the set_xlabel method on it directly:

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from yellowbrick.cluster import KElbowVisualizer


model = KMeans(random_state=0)
visualizer = KElbowVisualizer(
    model, 
    k=(2,7), 
    metric="silhouette", 
    timings=False,
    title="custom title"
)

visualizer.fit(df[["a", "b", "c"]])
visualizer.ax.set_xlabel("custom x label")
plt.show()

Thanks for checking out Yellowbrick!

rebeccabilbro
  • 477
  • 4
  • 3