Python Forum
Supervised learning, tree based model - problems splitting data - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Supervised learning, tree based model - problems splitting data (/thread-39996.html)



Supervised learning, tree based model - problems splitting data - Pixel - May-16-2023

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.