Suppose I have two cluster points
SeedRandom[2]
pts = RandomReal[1, {50, 2}];
cluster = FindClusters[pts, 2, RandomSeeding -> 1];
ListPlot[cluster]
I want to find a line to separate this two cluster point sets,and this line has the minimum total distance with all points. I think Mathematica maybe have some in-built methods can implement it.This is my current try
trainning = Flatten[MapIndexed[Thread[#1 -> First[#2]] &, cluster]];
c = Classify[trainning, Method -> "SupportVectorMachine"];
ClassifierInformation[c, "Function"]
Missing[PropertyNotAvailable,Function]
But I cannot get an available result.So I have to implement it manually.
sol = ArgMin[{Total[Abs[a # - #2 + b]/Sqrt[a^2 + 1] & @@@ pts],
a # + b < #2 & @@@ Last[cluster],
a # + b > #2 & @@@ First[cluster]}, {a, b}];
Show[ContourPlot[
Evaluate[# x + #2 == y & @@ sol], {x, 0, 1}, {y, 0, 1}],
ListPlot[cluster]]
I will get the result and some error information simultaneously.I cannot sure the result is what I want exactly.I mean I don't know the total distance is smallest or not.Is there better solution can do this?
Classify
$\endgroup$