Python Forum

Full Version: Supervised learning, tree based model - problems splitting data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently using a tree based model for self training purposes and there is one area of code I get stuck. I used One-hot code to extract additional columns from my original data. Viewing the dataframe the new columns are visible, but trying to split the data into new features (X) and response (y), I continually get the KeyError that the new columns are not in the index.

My code:

X = df.loc[:, ["Mileage", "AgeP", "Category_SAV", "Category_SUV", "Category_Sedan", "Category_Small", "Category_Super"]]
y = df.loc[:, "Claim"]
The error however is only on the Category_ index columns even though I see these in the dataframe.