(Upgrading comment to answer.)
This error message is generally pretty straightforward: you have missing values (generally one of np.nan
, pd.NA
, None
), and whatever method you're trying to use cannot handle that.
Now train_test_split
doesn't usually care about missing values: it's just splitting up the rows, so why should it care what values are in there? But, in this case you're asking to stratify
on y
(making the train/test split have the same proportion of each class in y
), and so it does care about the values in y
. So the error is because you have missing values in y
.
Missing the target variable is problematic. The best thing to do is probably to drop those rows, unless there's some additional context (e.g. if your data is time-series, maybe you can impute based on the adjacent rows).
train_test_split
doesn't care about missing values, except that OP is stratifying ony
. $\endgroup$