biolab / orange3

🍊 :bar_chart: :bulb: Orange: Interactive data analysis
https://orangedatamining.com
Other
4.88k stars 1.02k forks source link

Neural network: Different result in GUI and python #3049

Closed horvathj closed 5 years ago

horvathj commented 6 years ago
Orange version

3.13

Expected behavior

Get same result in GUI and python when using neural network modell prediction (for binary classification).

Actual behavior

Different result in GUI. Maybe it is wrong?

Steps to reproduce the behavior

(Small files, modell with train in 2-3 seconds) _flow

  1. Rename to (.csv) and Load the attached train.txt file, and connect into a Neural Network modell. train.txt

  2. Parameters for Neural Network:

    • Hidden neurons: 1
    • Activation: ReLu
    • Optimizer: L-BFGS-B
    • alpha: 0,0001
    • Max iterations: 300

3) Connect the modell in to prediction modul.

4) Rename to .csv and Load the test.csv and connect into prediciton modul. test.txt

5) Check the predictions, and retrain the neural network modell while the first 2 row is bus, and the second 2 is police. AND the third row is 0.43 : 0.57

_results

6) Save the neural network modell into a pickle file "neural.pkcls" with Save model.

7) Activate a python environment with installed Orange and pickle packages.

8) Run this code in python:

import Orange
import pickle
nn = pickle.load( open( "neural.pkcls", "rb" ) )
nn.predict([[0.327,0.926],[0.077,0.498],[0.518,0.512],[0.499,0.335]])

9) The first array shows the categorisation (on my computer it is wrongly: [0., 0., 0., 1.] and the predict_proba numbers are not the same as in prediciton result table.

_cmd

Additional info (worksheets, data, screenshots, ...)

If I list out the coefs and intercepts and do the MLP math in excel, I get the python results. But the GUI shows something else, what I can not understand.

horvathj commented 6 years ago

If I train the model in python I get the same result as in the prediction window.

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

mlp = Orange.classification.NNClassificationLearner(hidden_layer_sizes=(1, ), solver='lbfgs', max_iter=300, random_state=3)
nn = mlp.fit(train.X,train.Y)

nn.predict(test)

(array([0., 0., 1., 1.]), array([[1.00000000e+00, 5.49156522e-13], [9.99999973e-01, 2.73501750e-08], [4.33381136e-01, 5.66618864e-01], [2.67609779e-04, 9.99732390e-01]]))

ajdapretnar commented 5 years ago

Probably the same as #3521?

janezd commented 5 years ago

Most probably. I read both issues yesterday, but obviously not carefully enough. Now it's just that you do the honour of clicking "Close". :)

This is yet another argument for #3705.

ajdapretnar commented 5 years ago

Even though @horvathj reported this first, closing as duplicate of #3521. Sorry for not figuring this out sooner.