Mathematica Asked on March 8, 2021
I generated lines and circles:
lines = Table[
Graphics[
Line[{{RandomInteger[{0, 10}],
RandomInteger[{0, 10}]}, {RandomInteger[{0, 10}],
RandomInteger[{0, 10}]}}], ImageSize -> 10], {x, 1, 20}];
circles =
Table[Graphics[
Circle[{RandomInteger[{0, 10}], RandomInteger[{0, 10}]},
RandomInteger[{0, 20}]], ImageSize -> 10], {x, 1, 20}];
and put them into a classifier
c = Classify[{lines -> "lines", circles -> "circles"}]
the training was successful with no errors, but when trying to test the classifier with:
test = Graphics[Line[{{0, 1}, {0, 2}}], ImageSize -> 10]
c[test]
I get the error:
ClassifierFunction::mlbddataev: The data being evaluated is not
formatted correctly.
And I do not understand what the problem is. Can somebody tell me, how to correctly format the data?
This is the way I would do it.
Association
, not list, when you label by the whole batches and not single objects.Graphics
so circles and lines are different sizes and in different places. You can also add noise (like random points), but I did not do it for simplicity.PerformanceGoal->"Quality"
is recommended for more accurate results.Graphics
but in more complex cases you can always consider converting Graphics
to Image
with Rasterize
and using Neural Networks.Training set:
lines = ParallelTable[Graphics[{Thick,Line[RandomReal[10,{2,2}]]},
ImageSize -> 50,PlotRange->{{0,10},{0,10}}], {x, 1, 100}];
circles = ParallelTable[Graphics[{Thick,Circle[RandomReal[{3,7},2], RandomReal[{1,3}]]},
ImageSize -> 50,PlotRange->{{0,10},{0,10}}], {x, 1, 100}];
Here is a sample (frames are only to stress varying locations of lines and circles within the Graphics
):
Framed /@ RandomSample[lines~Join~circles, 10]
Train:
c=Classify[<|"lines"->lines,"circles"->circles|>,PerformanceGoal->"Quality"]
Information[c]
Test set:
linesTEST=ParallelTable[Graphics[{Thick,Line[RandomReal[10,{2,2}]]},
ImageSize -> 100,PlotRange->{{0,10},{0,10}}], {x, 1, 20}];
circlesTEST = ParallelTable[Graphics[{Thick,Circle[RandomReal[{3,7},2], RandomReal[{1,3}]]},
ImageSize -> 50,PlotRange->{{0,10},{0,10}}], {x, 1, 20}];
Measure performance:
cm=ClassifierMeasurements[c,<|"lines"->linesTEST,"circles"->circlesTEST|>]
cm["ConfusionMatrixPlot"]
Correct answer by Vitaliy Kaurov on March 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP