Print model in Python

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Print model in Python

Leonardo Vianna
Hi there,

I am having trouble getting the model for a cross-validate classifier. I am using Python wrapper.

I  have tried something like below:

cls = Classifier(classname="weka.classifiers.trees.M5P", options=["-M", "4.0"])
pout = PredictionOutput(classname="weka.classifiers.evaluation.output.prediction.PlainText")
evl = Evaluation(data)
evl.crossvalidate_model(cls, data, 10, Random(1), pout)
print(evl.header)
print(evl.summary("=== Summary ===", False))
print(pout.buffer_content())

But I just can not find the method to return the model.

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Print model in Python

Peter Reutemann
> I am having trouble getting the model for a cross-validate classifier. I am using Python wrapper.
>
> I  have tried something like below:
>
> cls = Classifier(classname="weka.classifiers.trees.M5P", options=["-M", "4.0"])
> pout = PredictionOutput(classname="weka.classifiers.evaluation.output.prediction.PlainText")
> evl = Evaluation(data)
> evl.crossvalidate_model(cls, data, 10, Random(1), pout)
> print(evl.header)
> print(evl.summary("=== Summary ===", False))
> print(pout.buffer_content())
>
> But I just can not find the method to return the model.

Cross-validation generates X number of models internally, evaluates
them and discards them. It is only used for collecting statistics.

If you want to generate an actual model, you have to build it with a
dataset explicitly (the Explorer does that implicitly on the full
datasets, which always confuses people).

Add the following lines after your evaluation code:

cls.build_classifier(data)
print(cls)

The python-weka-wrapper tool has its own mailing list:
https://groups.google.com/forum/#!forum/python-weka-wrapper

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html