I’ve been experimenting on several datasets and found something very strange while implementing ML.
I’ll Explain after the code…
import numpy as np
from sklearn import datasets
iris = datasets.load_iris()
# 4 features in np array - 150 rows
case = 1 # change cases to see variation
if case == 1: # first feature deleted
iris.data = np.delete(iris.data,0, 1)
if case == 2: # first 2 features deleted
iris.data = np.delete(iris.data,0, 1)
iris.data = np.delete(iris.data,0, 1)
if case == 3: # first 3 features deleted (1 feature left)
iris.data = np.delete(iris.data,0, 1)
iris.data = np.delete(iris.data,0, 1)
iris.data = np.delete(iris.data,0, 1)
if case == 4: # only second feature deleted from np array
iris.data = np.delete(iris.data,1, 1)
if case == 5: # only third feature deleted from np array
iris.data = np.delete(iris.data,2, 1)
if case == 6: # only last feature deleted from np array
iris.data = np.delete(iris.data,3, 1)
# print iris.data
# exit()
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
pred = gnb.fit(iris.data, iris.target).predict(iris.data)
# pred = gnb.fit(iris.data, iris.target).predict(test_data)
from sklearn.metrics import accuracy_score
print accuracy_score(iris.target, pred)
I’m using the basic fisher iris dataset from sklearn, it has 150 rows and 4 columns (features).
Using training data as test data.
So i tried to remove a few features and see if accuracy changed.
And I thought it would.
But till case 1, 2, and 3, I removed 1, 2 and 3 features respectively and there was no change in the accuracy. It stayed 96%.
Then on running cases 4,5 and 6, The accuracy changed. Why?
On comparing case 2 and 4,
Both have second feature removed from the dataset, so clearly, removing second feature is responsible for change in accuracy (as seen in case 4)
So why does it not change in case 2?
Just because it had first feature removed too? to balance out the second? (If that were true, case 1 would have given different accuracy)
Why does accuracy not change in first 3 cases, but it does in the last 3 cases?
Is ML dependent on the order in which features are feeded to the algorithm?
What am I missing here?
Would be great if someone could clear this doubt.
Thanks!