Unorderable Types: str() > float error KNN model
<p>I have read quite a bit on this particular error and haven't been able to find an answer that addresses my issue. I have a data set that I have split into train and test sets and am looking to run a KNeighborsClassifier. My code is below... My problem is that when I look at the dtypes of my X_train i don't see any string formatted columns at all. My y_train is a single categorical variable. This is my first stackoverflow post so my apologies if I've overlooked any formalities and thanks for the help! :) </p>

<p>Error:</p>

<pre><code>TypeError: unorderable types: str() &gt; float()
</code></pre>

<p>Dtypes: </p>

<pre><code>X_train.dtypes.value_counts()
Out[54]: 
int64      2035
float64     178
dtype: int64
</code></pre>

<p>Code:</p>

<pre><code># Import Packages 
import os
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
from sklearn.dummy import DummyRegressor
from sklearn.cross_validation import train_test_split, KFold
from matplotlib.ticker import FormatStrFormatter
from sklearn import cross_validation
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
import pdb

# Set Directory Path 
path = "file_path"
os.chdir(path)

#Select Import File
data = 'RawData2.csv' 
delim = ','

#Import Data File
df = pd.read_csv(data, sep = delim)
print (df.head())

df.columns.get_loc('Categories')

#Model 

#Select/Update Features
X = df[df.columns[14:2215]]

#Get Column Index for Target Variable
df.columns.get_loc('Categories')

#Select Target and fill na's with "Small" label
y = y[y.columns[21]]
print(y.values)
y.fillna('Small')

#Training/Test Set
X_sample = X.loc[X.Var1 &lt;1279]
X_valid = X.loc[X.Var1 &gt; 1278]
y_sample = y.head(len(X_sample))
y_test = y.head(len(y)-len(X_sample))

X_train, X_test, y_train, y_test = train_test_split(X_sample, y_sample, test_size = 0.2)
cv = KFold(n = X_train.shape[0], n_folds = 5, random_state = 17)

print(X_train.shape, y_train.shape)
X_train.dtypes.value_counts()

from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score

knn = KNeighborsClassifier(n_neighbors = 5)
knn.fit(X_train, y_train) **&lt;-- This is where the error is flagged** 
accuracy_score(knn.predict(X_test))
</code></pre>