# Determining the Method Chosen When an Option is Set to Automatic

Many Mathematica functions with multiple methods have an option where the method is set to Automatic. Is it possible to have these functions output what method they choose. For example, if I'm using ClusteringComponents, can I determine which clustering method was used?

An example that uses ClusteringComponents is below:

ClusteringComponents[data={{0.5370051312752928, 0.5628007665509778,
0.924889712223683}, {0.40728988864591575, 0.8577670202812715,
0.5978730625026663}, {0.562516427215127, 0.49728131686549637,
0.47832331238190884}, {0.6774111669373863, 0.9144092245025786,
0.11305044875850445}, {0.033836358004133205, 0.6822209349614146,
0.000530175424924062}, {0.5126626915435528, 0.8832599430065953,
0.849552299897435}, {0.6491187920294659, 0.9219373898946732,
0.09901604790821605}, {0.4925931838614015, 0.48295149736934073,
0.7649173603531039}, {0.65672918763929, 0.4726727633204313,
0.584790541040825}, {0.07560367987323602, 0.7852947899002904,
0.9773441944169889}}, 3, 1,Method->Automatic]


I see in the documentation that it could be choosing any of the following methods: {"Agglomerate", "DBSCAN", "NeighborhoodContraction", "JarvisPatrick", "KMeans", "MeanShift", "KMedoids", "SpanningTree", "Spectral", "GaussianMixture"}, but I see no option to recover which method was chosen automatically.

It seems like: Trace[ ClusteringComponents[data,3,1], TraceInternal->True] might be partway there, but the output is overwhelming and I can't seem to find what I'm looking for.

DeleteDuplicates @
Flatten @
Trace[ClusteringComponents[data, 3, 1],
_["Method", _],
TraceInternal -> True]

{"Method" -> "KMeans"}


Alternatively, you can use HoldPattern["Method" -> _] instead of _["Method", _] in the second argument of Trace.

\$Version


"11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"

• Interesting, when running that code I get the following: {Method->Method}
– Nate
Feb 14, 2022 at 17:47
• @Nate, this works in version 11.3; but not in version 13.0.
– kglr
Feb 14, 2022 at 18:24
• Thanks, I'll roll-back to version 11.3, since it doesn't appear to work in 13.
– Nate
Feb 14, 2022 at 19:22