Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How do I change the properties of a model object, when the object is generated by a toolbox?

2 Ansichten (letzte 30 Tage)
I create a model object using 'fitcnb' from the Statistics and Machine Learning toolbox. e.g. 'model = fitcnb(data,labels);', and 'model' has a number of properties. Is it possible to change the properties of 'model'? If so, how?
I want to do this because of incompatibilities between 'fitcnb' and the Matlab Compiler. I'm performing Naive Bayes classification in Matlab. To do this, I call 'fitcnb' and 'predict'. Here's a simplified example (with random data):
XX = rand(10^4,5); % make some random data
yy = rand(10^4,1)>0.5; % make random labels
% partition into training and testing
I_train = randsample(10^4, 0.5*10^4); % half the data for training
I_test = ~ismember(1:10^4, I_train); % the other half for testing
naive_bayes_model = fitcnb(XX(I_train,:),yy(I_train));
[predicted_class, score] = predict(naive_bayes_model,XX(I_test,:))
My problem is that we want to compile our code, which contains calls to 'fitcnb' and 'predict', into a standalone. The executable crashes at runtime if we include the call to 'fitcnb'; the problem's solved if we comment out the line to 'fitcnb'. Therefore it seems like there's a problem including calls to the Statistics and Machine Learning toolbox. So we need to get creative.
If we could save 'naive_bayes_model' to a mat-file and edit the properties, we could eliminate the call to 'fitcnb'. From inspection I think I know what all the properties are, e.g. mean, standard deviation, number of data points, etc. Then I could load 'naive_bayes_model', use it as a template, and change the properties for whatever data set it should operate on. However I'm not used to OOP in Matlab, so I have no idea if this is a crazy idea.

Antworten (1)

Don Mathis
Don Mathis am 25 Apr. 2017
I think the properties you want to set are 'protected' which means that only methods of the class or subclasses can set them. That design is often used when setting such properties individually would create an inconsistent state inside the object (because other properties may have values that depend on these, etc.). In some cases you could edit the code to make the desired properties 'public', but that could break things unless you read the code and made sure that there were no dependencies between these properties and others, anywhere. But that's not going to be easy, and most likely there are dependencies.

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by