pascalabcnet/InstallerSamples/MachineLearning/08_Datasets/Iris/08_ConfusionMatrix1.pas

29 lines
911 B
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Confusion matrix для Iris с использованием DataPipeline.
// Рекомендуемый стиль - он проще и явно показывает намерения
uses MLABC, PlotML;
begin
var ds := Datasets.Iris;
var (train, test) := ds.StratifiedTrainTestSplit(0.2, 42);
var pipe := DataPipeline.BuildClassification(
ds.Target,
ds.Features,
new StandardScaler,
new LogisticRegression
);
pipe.Fit(train.Data);
var pred := pipe.Predict(test.Data);
var ytest := pipe.GetEncodedLabels(test.Data);
var cm := new ConfusionMatrix(ytest, pred);
var acc := Metrics.Accuracy(ytest, pred);
Plot.ConfusionMatrix(cm, pipe.GetClassLabels{, normalize := MatrixNormalization.Rows});
Plot.Title := $'Iris: DataPipeline, accuracy = {acc:F3}';
Plot.XLabel := 'Предсказанный класс';
Plot.YLabel := 'Истинный класс';
end.