How to insert two features in a model when a feature only applies to a certain group in the model I'm building a machine learning model in Python to predict soccer player values. Consider the following feature columns of the dataframe:
         [features]
---------------------------------
position | goals | goals_conceded 
-------- |-------|---------------       
Forward  |  23   |     NaN
Defender |   2   |     NaN
Defender |   4   |     NaN
Keeper   |   NaN |     20
Keeper   |   NaN |     43

Since keepers don't usually score goals, they'll almost always have null values in the &quot;goals&quot; column, but they still can have this statistic, so it would be fine to fill the NaNs with 0. On the other hand, since line players can't have &quot;goals_conceded&quot; stats, they'll also have null values in that column, but in this case, players will never have this statistic, since this is a keeper only stat. How do I build a machine learning model considering these two columns as features?
I thought about putting them together in one single column, but that can't happen since for a line player, the more goals he makes the better it is. For goalkeepers it's the opposite, the less goals he conceeds the better. I also can't fill the columns with zeros since it would affect the model prediction in the &quot;goals_conceded&quot; column for example, since 98% of the rows contain in line players info.
This happens with many of the columns in my dataframe, such as &quot;clean sheets&quot; (only Keepers will have this stat) and &quot;shots at target&quot; (only line players will have this stat). How do I deal with them?
Remember that any model will have the relationships between the features (X) and the label (y), so your ideas are correct. What is better will depend on your data, so try both, and try more ideas if you can. The best model will be the one that generalize better for new data, so take the final decision with data.
Please, note that your features are at least 3, goals, goals_conceded and position, so this last will help with the problem.
And I suggest not to fill NaN with 0, but -1 (or any other imposible/invalid integer number), because a newbie player will have 0 in the feature(s), and it's correct, and you want to identificate this.