DIfferent results when taking input through a csv file vs manual input

Viewed 26

So i am working on a very basic ml model to predict heart diseases and while testing the function i am getting this weird bug where the model shows wrong output when taking inputs for the parameter manually but when i read it from the csv it shows the correct output. Function:

def Diabetes(TestList):
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.feature_extraction import DictVectorizer
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
diadf=pd.read_csv('diabetes.csv')

labels=np.asarray(diadf.Outcome)
le=LabelEncoder().fit(labels)
labels=le.transform(labels)

df_sel=diadf.drop(['Outcome'],axis=1)
df_features=df_sel.to_dict(orient='records')
vec=DictVectorizer()
features=vec.fit_transform(df_features).toarray()


y_train,y_test,x_train,x_test=train_test_split(features,labels,test_size=0.1,random_state=0)


model=KNeighborsClassifier(n_neighbors=3).fit(y_train,x_train)
predictor=model.predict(TestList)
pred=[labels[p] for p in predictor]
acc=model.score(y_train,x_train)
print( acc*100, pred)

Taking input from the csv file:

import pandas as pd
diadf=pd.read_csv('diabetes.csv')
df_sel=diadf.drop(['Outcome'],axis=1)
tlist=df_sel.iloc[10].tolist()
Diabetes([tlist])

Output: 85.383502170767 [1]

While taking manual input:

Diabetes([[0,137,40,35,168,43.1,2.288,33]])

Output: 85.383502170767 [0]

for reference according to the dataset for this input the correct output should be 1

first 7 lines of the dataset:

Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age,Outcome
6,148,72,35,0,33.6,0.627,50,1
1,85,66,29,0,26.6,0.351,31,0
8,183,64,0,0,23.3,0.672,32,1
1,89,66,23,94,28.1,0.167,21,0
0,137,40,35,168,43.1,2.288,33,1

I really can't figure out where i am going wrong...

0 Answers
Related