while i was building the model to predict the performance of machine using the features like OEF,working time,performance/head etc...

I splitted the training data using

x_trainset, x_testset, y_trainset, y_testset = train_test_split(x, y, test_size=0.3)

then built the model

#Import Random Forest Model
from sklearn.ensemble import RandomForestClassifier

# Create the model with 100 trees

#Train the model using the training sets
train1=forest.fit(x_trainset, y_trainset)



array(['level2', 'level5', 'level2', 'level3', 'level3', 'level2',
       'level3', 'level2', 'level4', 'level2', 'level2', 'level3',
       'level4', 'level3', 'level3', 'level2', 'level2', 'level3',
       'level3', 'level3', 'level3', 'level3', 'level2', 'level5',
       'level3', 'level3', 'level2', 'level5', 'level4', 'level3',
       'level3', 'level3', 'level2', 'level2', 'level3', 'level3',
       'level3', 'level2', 'level4', 'level2', 'level2', 'level3',
       'level4', 'level3', 'level1', 'level3'], dtype=object)



120    level2
104    level5
117    level2
91     level3
4      level3
10     level2
133    level3
18     level2
119    level4
61     level2
71     level2
30     level3
27     level4
103    level3
14     level3
59     level2
50     level2
55     level3
53     level3
22     level3
78     level3
114    level3
70     level2
60     level5
6      level3
1      level3
83     level2
82     level5
26     level4
67     level3
62     level3
145    level3
74     level2
11     level2
107    level3
29     level3
138    level3
49     level2
150    level4
8      level2
20     level2
95     level3
51     level4
56     level3
72     level1
102    level3
Name: levels, dtype: object

then found the accuracy and i got like,

from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
print("Accuracy:",metrics.accuracy_score(y_testset, y_pred))


Accuracy: 1.0

In x_trainset,x_testset i have only the features(7) and in y_trainset,y_testset i have only column "levels" which is needed to be predicted

dataset size is about 153

I don't know whether this is correct.Please can anyone answer this as soon as possible

  • $\begingroup$ Even i tried using decision tree algorithm yet i got 100 % accuracy $\endgroup$
    – hema latha
    Feb 14, 2020 at 17:30

2 Answers 2


There could be many reasons why you achieved 100% accuracy.One of them could be:Duplicates in your data which are repetitive in both train and test data.I would suggest you to try the following steps: 1.Check if there are any duplicates in the original data 2. Try a different Train-Test split like 80-20 3.Try k-Fold cross validation 4.Checkout for Precision and Recall apart from accuracy. Hope this helps!

  • $\begingroup$ My Precision and Recall apart from accuracy is precision recall f1-score support level1 1.00 1.00 1.00 1 level2 1.00 1.00 1.00 25 level3 1.00 1.00 1.00 13 level4 1.00 1.00 1.00 4 level5 1.00 1.00 1.00 3 $\endgroup$
    – hema latha
    Feb 14, 2020 at 15:57
  • $\begingroup$ do you want me to put test size as 0.8 or 0.2 $\endgroup$
    – hema latha
    Feb 14, 2020 at 16:00
  • $\begingroup$ Any how thank u so much for ur suggestions $\endgroup$
    – hema latha
    Feb 14, 2020 at 16:02
  • $\begingroup$ test-0.2 which obviously means train -0.8 $\endgroup$
    – Sri Test
    Feb 14, 2020 at 16:09
  • $\begingroup$ i tried with test size as 0.2 yet the accuracy is 1.0 $\endgroup$
    – hema latha
    Feb 14, 2020 at 16:30

You are doing the split right, training in the train set and then testing in the test set.

Seems weird yes. With out seeing your data, have you droped the target from the with you are trainning?? This could be a reason why you have a 100% accuracy.

Other thing you could try is to plot the feature importance and check which features are contributing to the model.

Check this link to see feature importance

  • $\begingroup$ yes i have dropped the target from the training set $\endgroup$
    – hema latha
    Feb 14, 2020 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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