Orange Forum • View topic - Getting predictions from classifier with python file

Getting predictions from classifier with python file

A place to ask questions about methods in Orange and how they are used and other general support.

Getting predictions from classifier with python file

Postby mjrother » Mon Jun 10, 2013 2:47

I have trained several learners and want to use the learner to get the prediction another set of data.

Here is an example using neural network

learner = orngClass.neural.NeuralNetworkLearner()
learner.name = "Neural Network"
learner.n_mid = 10
learner.reg_fact = 0.1
learner.normalize = False

data = Orange.data.Table("train.csv")
test_data = Orange.data.Table("test.csv")

print "Testing Neural Network"
for t in test_data:
print learner(t)


I get this error:
Traceback (most recent call last):
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\NeuralNetworkLearner.py", line 65, in <module>
predict_NeuralNetwork(data, test_data)
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\NeuralNetworkLearner.py", line 56, in predict_NeuralNetwork
print learner(t)
File "y:\python\Python27\lib\site-packages\Orange\classification\neural.py", line 195, in __call__
X = data.to_numpy()[0]
AttributeError: 'Orange.data.Instance' object has no attribute 'to_numpy'


With other learners/classifiers I get different errors. For example with the Bayes classifier I get:
Traceback (most recent call last):
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\BayesLearner.py", line 35, in <module>
predict_Bayes(data, test_data)
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\BayesLearner.py", line 27, in predict_Bayes
print learner(t)
File "y:\python\Python27\lib\site-packages\Orange\utils\__init__.py", line 201, in wrap_call
return func(*args, **kwargs)
File "y:\python\Python27\lib\site-packages\Orange\classification\bayes.py", line 93, in __call__
return NaiveClassifier(bayes(data, weight))
AttributeError: Learner.__call__: examples and, optionally, weight attribute expected


Am I using the classifers incorrectly?

Re: Getting predictions from classifier with python file

Postby Ales » Mon Jun 10, 2013 11:37

mjrother wrote:Am I using the classifers incorrectly?
No. You are not even training the the classifier.
Try this:
Code: Select all
classifier = learner(data)
for t in test_data:
    print classifier(t)

Re: Getting predictions from classifier with python file

Postby mjrother » Tue Jun 11, 2013 0:04

My bad, I omitted the cross training step in the learning. Repeating some code for context.


learner = orngClass.bayes.NaiveLearner()
learners = [learner]

results = orngEval.testing.cross_validation(learners, data, folds=10)

for t in test_data:
print learner(t)

Traceback (most recent call last):
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\BayesLearner.py", line 35, in <module>
predict_Bayes(data, test_data)
File "Z:\Courses\Kaggle\BiologicalResponse\src\bioresponse\BayesLearner.py", line 27, in predict_Bayes
print learner(t)
File "y:\python\Python27\lib\site-packages\Orange\utils\__init__.py", line 201, in wrap_call
return func(*args, **kwargs)
File "y:\python\Python27\lib\site-packages\Orange\classification\bayes.py", line 93, in __call__
return NaiveClassifier(bayes(data, weight))
AttributeError: Learner.__call__: examples and, optionally, weight attribute expected

Re: Getting predictions from classifier with python file

Postby Ales » Tue Jun 11, 2013 9:49

mjrother wrote:My bad, I omitted the cross training step in the learning. Repeating some code for context.

The same comment still applies. See the tutorial on learners and classifiers.


Return to Questions & Support