Hi, all.
I’m trying to evaluate models I built with Code Repository.
When I attempting to build evaluation in Modeling Objectives, the error quoted below occurred:
Summary
The error indicates a mismatch between the number of features the model was trained on (56) and the number of features being provided during prediction (57). This discrepancy can occur if there are differences in the preprocessing steps or the input data structure between training and prediction phases.
### Suggestion
To fix this issue, ensure that the same preprocessing steps are applied consistently to both the training and prediction datasets. Verify that the input data structure remains unchanged between these phases.
### Possible Fix
Check the preprocessing steps and ensure that the same columns are used during both training and prediction. You might need to align the feature columns in your prediction data to match those used during training.
Here is a minimal code change suggestion to ensure the feature columns are consistent:
- predictions = self.model.predict(df_in[feature_columns])
- feature_columns = [col for col in df_in.columns if col in self.model.feature_names_in_]
- predictions = self.model.predict(df_in[feature_columns])
This change ensures that only the columns used during model training are passed to the prediction function.
For more detailed guidance, you may want to consult with Palantir support.
Though possible fix is implied, my code is almost the same.
def predict(self, df_in):
feature_columns = [col for col in df_in.columns if col not in ['customer_id', 'target']]
predictions = self.model.predict(df_in[feature_columns])
What should I fix to solve this error?