2
$\begingroup$

Let we have an array of integers e.g. Range@365.
Each index has a specific value by which clusterization of integers should be done.
But these values cannot be calculated. It's WeatherData or something like this.
They are presented as a data List. So DistanceFunction is:

df = Abs[data[[#1]]-data[[#2]]]&

I also tried next form:

idf[i_?IntegerQ, j_?IntegerQ]:= Abs[data[[i]]-data[[j]]];

But anyway

FindClusters[Range@365, df]

or

FindClusters[Range@365, (idf[#1,#2])&]

not work, with unclear errors.

$\endgroup$

2 Answers 2

1
$\begingroup$

Mathematica's FindCluster knows various type of DistanceFunction. So if you want to use 1,2,...,365 as indices of data, try the following syntax:

 FindClusters[data -> Range[365]]

and let Mathematica select the best distance function. If you are not satisfied with the result, then, you can try tuning the distance function.

For example,

data = Most[
   Last /@ Normal[
     AirTemperatureData[
      "KBOS", {{2000, 1, 1}, {2000, 12, 31}, "Day"}]]];

Length[data]
(* 365 *)

data // Short

input data

FindClusters[data -> Range[365]]

result

$\endgroup$
1
$\begingroup$

Your syntax for the distance function isn't quite right. Define:

df[x_, y_] = Abs[x - y];

Then:

FindClusters[Range@365, 3, DistanceFunction -> df]

Finds 3 clusters using the defined df.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.