3
$\begingroup$

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 "goals" 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 "goals_conceded" 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 "goals_conceded" 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 "clean sheets" (only Keepers will have this stat) and "shots at target" (only line players will have this stat). How do I deal with them?

$\endgroup$
2
  • $\begingroup$ Looks like the actual problem is that classes are unbalanced. But theses columns aren't the ones you are trying to predict, are they? $\endgroup$ – Pedro Henrique Monforte Aug 16 '20 at 6:28
  • $\begingroup$ Nope, I want to predict a column that contains the player value in euros, using these columns as features for my model. $\endgroup$ – Caldass_ Aug 16 '20 at 7:29
3
$\begingroup$

To me the data in the current form seems wrong fro training a model for all players, it is like trying to tell whether an apple is better than a tennis ball. They have completely different characteristics.

what you could do instead is group players with similar features in different sets and train the models to predict their scores relevant to their feature set. So for example goalkeepers will be compared against other goalkeepers and assigned scores accordingly. After which you need to set a baseline value for each set and scale the scores for the different classes accordingly.

$\endgroup$
2
  • $\begingroup$ So you're saying I should separate in line players from goalkeepers so I would have a dataframe with only line players and another one with only goalkeepers? $\endgroup$ – Caldass_ Aug 16 '20 at 18:31
  • 1
    $\begingroup$ Precisely. In fact why just goalkeepers and players, you could have a category for defenders as well because forwards might have better on paper stats compared to defenders. Once you've trained your models on these individual classes, all that remains is standardization $\endgroup$ – tehem Aug 17 '20 at 3:12
3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Let me see if I got you: 1 - You're saying that by considering the players position (and also lots of other features) this problem is already solved, so putting the "goals_conceded" and the "goals" together would be fine since there are other features that the model can use to be trained correctly? 2- Instead of filling the keeper goals NaNs with 0, filling with -1? If that's what you mean, shouldn't I still fill with 0 since keepers can still score goals, it's rare but it happens. Plus, there are keepers that are the official penalty takers and freekick takers, etc. $\endgroup$ – Caldass_ Aug 16 '20 at 18:44
2
$\begingroup$

Its an interesting question. In this case I am doubting if training data is even correct. Because two different observations are themselves not comparable. For a ML model to say or understand how two observations are different they both should be comparable. Its a different thing that one value is unknown and one value does not apply to data.

Note: I don't know if below is valid because I am not very knowledgeable in soccer. There may a different way to look at this problem. Since Forwarder can also be assigned as a keeper. (No one will do it since he may not be good at it but he can still play as a keeper). So in your data the forwarder simply never conceded a goal so you may replace NaN with 0.

$\endgroup$
2
  • 1
    $\begingroup$ Interesting point, but I don't think it would work because if a foward has 0 conceded goals, and (because of other stats) he is worth only 600k, a keeper with those stats should be worth a lot. Although, the same thing would happen with valuable players, they would be worth a lot and still have 0 conceded goals. I honestly can't tell if this could be applied. $\endgroup$ – Caldass_ Aug 16 '20 at 18:35
  • 1
    $\begingroup$ What you said makes sense. forward goal_conceded should not be replaced with 0. I guess making different model for forward, defender and goal keepers will be better as @tehem suggested $\endgroup$ – Hitesh Somani Aug 17 '20 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.