Got Changing the dtype of the features after fit() is not supported exception while predict.
shabir1 opened this issue · 1 comments
shabir1 commented
Got Changing the dtype of the features after fit() is not supported exception while predict.
I am getting an exception while prediction, Changing the dtype of the features after fit() is not supported.
E.g If my feature F1 has a value of 10 during the fit and while predicting my F1 value is 10.1 or vice versa then I am getting the exception.
raise ValueError("Changing the dtype of the features after fit() is "
ValueError: Changing the dtype of the features after fit() is not supported. Fit() method was called with ['Int64', 'Int64', 'Float64', 'Float64', 'Int64', 'Int64', 'Int64', 'Float64', 'Float64', 'Float64'] wher
eas the new features have ['Int64', 'Int64', 'Int64', 'Float64', 'Int64', 'Int64', 'Int64', 'Float64', 'Float64', 'Int64'] as type
How can I solve this issue?
ravinkohli commented
Actually, the dtype is calculated for the whole column. So, if the column was Float64
when fitting and Int64
while predicting, this error is raised. The best way to get rid of this error is by explicitly setting the dtypes for the columns that are now Int64
to Float64
using data = data.astype({'col1': 'float64', 'col2': 'float64'})
where the data is the test set and col1
and col2
are the columns which have different feature types