Q:

Is it possible to use the saved xgboost model (with one-hot encoding features) on unseen data (without one-hot encoding) for prediction?

I think the question is self-explanatory. But let's say you have a data with a few features with categorical data, and when building a model for example XGBoost you one-hot encode categorical features. Now you want to do prediction based on test data using the saved model. Obviously the test data needs to be one-hot encoded and need have similar features as training set. The question is whether it is possible to find a way not one-hot encode the test data and directly use it for prediction? Would this be somehow possible? 
To me it appears that whatever comes in to my saved model need to be as it was used during training i.e. one-hot encoded features! But this is not neat, especially when building widgets and dashboards!
Any comments/hints are appreciated. 

A:

Since its pretty old post, possibly this response is helpful for others.
Its true that some of the algo's accept data in Categorical format and internally converts into OneHotEncoding. In such cases, model accept the data in raw format and doesnt require any explicit conversion handling.
In case if it's not supported, we have to save both the models, i.e.

Model used for Encoding the data
Model used for predicting the data

In a simpler way we can save related models in a single file as well.
Refer code snippet below:
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import OneHotEncoder
import pickle as pk
import pandas as pd
import numpy as np

df = pd.read_csv(<"Some_file.csv">) #replace with actual csv file
X = df['Features']
y = df['Labels']
file = open("models.pkl", "wb")  

encoder = OneHotEncoder(sparse=False)
oneHotEncodedFeature = encoder.fit_transform(X[<'Categorical_feature'>].values.reshape(-1,1))
pk.dump(encoder, file) #dumping Encoder model

# Some processing for concatenating oneHotEncodedFeature with other features and assume it its X again.
linReg = LinearRegression()
linReg.fit(X,y)
pk.dump(linReg, file) #dumping linear Reg. model
file.close() #Create single pickle file, which has both the trained model.

#For prediction

file = open("models.pkl", "rb")
trained_encoder = pk.load(file)  #Pickle file first load the OneHotEncoder 
trained_model_for_prediction = pk.load(file) #Reading same pickle again will load the trained Linear Reg Model.

