Is there any possibility to vary the accuracy of same data set in matlab and jupyter notebook by using python code ?

For same data set, at first I applied it in matlab and get 96% accuracy for decision tree method, then I apply that same data set in jupyter notebook by using python code where I get 53% accuracy for C4.5 (decision tree) by using k-fold cross validation.

I didn't understand where's the problem for getting different accuracy for same dataset and same method.

My procedure in python code is given below:

import pandas as pd
import numpy as np
from sklearn import tree
from sklearn.model_selection import KFold 


enter image description here

# define X and y
feature_cols = ['Past','Family_History','Current','current or previous 
               workplace','diagnosed with a mental health condition by a 
               medical professional?','do you feel that it interferes with 
               your work when being treated effectively?','Gender']
X = train[feature_cols]

# y is a vector, hence we use dot to access 'label'
y = train['Diagonised condition']

kfold = KFold(n_splits=10,random_state=None)
model = tree.DecisionTreeClassifier(criterion='gini')

results = cross_val_score(model, X, y, cv=kfold,scoring = 'accuracy')
result = results.mean()*100

std = results.std()*100
print (result)

enter image description here

  • $\begingroup$ Please post the MATLAB code so it can be compared to the Python code. $\endgroup$ Jan 23 '19 at 16:12
  • $\begingroup$ In matlab I use classification app (decision tree) and load my data set then calculate accuracy. $\endgroup$
    – IS2057
    Jan 23 '19 at 18:05
  • $\begingroup$ Are you sure that all other parameters for your decision tree are the same? $\endgroup$ Jan 24 '19 at 6:23
  • $\begingroup$ @MajidMortazavi, Yes I am sure . I use the same dataset and same parameters. $\endgroup$
    – IS2057
    Jan 24 '19 at 6:49

It is hard to make a direct comparison between a white box implementation (scikit-learn) and a black box implementation (MATLAB).

One guess they are using different algorithms. scikit-learn uses an optimized version of the CART algorithm. Maybe MATLAB uses ID3, C4.5, or something else. Another guess two implementations are using different hyperparameters (e.g., different splitting criteria, max depth, minimum node size, ...).

Since decision trees are white-box models, you can examine their internal structure. Plot both trained trees. See how they each are making the splits and how many splits are being made.


Although different splitting algorithms and hyperparameters indeed result in different model performance, I feel like the difference here is still too much. I feel like you can try to one hot encode some of your multiclass categorical data and see if there will be any difference.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.