How can I extract the algorithm's source code of Naive Bayes Classificator?
1 view (last 30 days)
Show older comments
I have used MATLAB's Naive Bayes Classificator as shown below for a given training data set called 'PlotArray' being an array:
--------------------------------------------------------------
% First model each variable in each class using a Gaussian distribution.
% nb = NaiveBayes.fit(training-data, classes)
nbGau = NaiveBayes.fit(cell2mat(PlotArray(2:end,1:14)),PlotArray(2:end,16));
% cpre = predict(nb, test-data)
nbGauClass= nbGau.predict(cell2mat(PlotArray(2:end,1:14)));
% bad: element '1' meaning classification error for Training data set
bad = ~strcmp(nbGauClass,PlotArray(2:end,16));
% number of measurement rows
N = size(PlotArray,1)-1;
% Resubstitution error:
nbGauResubErr = sum(bad) / N;
nbGauClassFun = @(xtrain,ytrain,xtest)...
(predict(NaiveBayes.fit(xtrain,ytrain), xtest));
% use cvpartition to generate 10 disjoint stratified subsets.
cp = cvpartition(PlotArray(2:end,16),'k',10);
% cross-validation error
nbGauCVErr = crossval('mcr',cell2mat(PlotArray(2:end,1:14)),PlotArray(2:end,16),...
'predfun', nbGauClassFun,'partition',cp);
% Save results
Estimation_true = strcmp(PlotArray(2:end,16),nbGauClass);
ClassificationResult = [PlotArray, ['ClassificationResult';nbGauClass]];
ClassificationResult(1,18)={'CorrectEstimation'};
for k4 = 1 : length(Estimation_true)
if Estimation_true(k4) == 1
ClassificationResult(1+k4,18) = {'y'};
else
ClassificationResult(1+k4,18) = {'NO!'};
end
end
--------------------------------------------------------------
The classification seems to work fine and I want to extract the mathematical algorithm for this classificator. How can I now get the source code of the trained classificator? What I mean is that I need simple mathematical operations that I can fit to another programming language such as python, C++, C#, Java or PLC-Code. How can I achieve this?
Answers (0)
See Also
Categories
Find more on Naive Bayes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!