Jump to content

Analysing FM20 with Python


Recommended Posts

Always wanted to do something similar and doing the "analysis" job of the manager IRL, for example monitoring the squad during the season with stats and attributes...but laziness always takes over

Planning of beginning a new long term save soon, I'll definitively try to be serious about it lol

Also this could be a very useful tool for scouting hundreds of players stats

Will share here if I get something done

Link to post
Share on other sites

@CowShedBarmyArmy wondering how do you visualize your plots?

EDIT: Will just go with Jupyter Lab/Notebook, less of a hassle and it would be sort of a report

I have defined all the plots and data I wanna see using my excel tool (which I can share):image.thumb.png.6aa8e0f5eea387e78a94549d4213409d.png
It contains a dictionnary for the attributes (long name, short name), the stats (long & short name, categorization also) a sheet to define my tactic and a sheet with a macro that converts multiple cells into a string containing their values into a python list format, for example ['aaa','bbb','ccc']

I've already wrote a code to import data and clean it, for example converting appropriate stats to integer of float type, or converting appearances (x) y into x+y.

An example of simple plot with matplotlib:
image.thumb.png.7c09d328e3d46e2d2b9ea6523a46a1ce.png

 

In the long term, I also project to analyse how attributes influence my KPIs, so projecting to do some regression analysis after setting up my dashboard, would be a cool project

Edited by gam945
Link to post
Share on other sites

 

19 hours ago, gam945 said:

@CowShedBarmyArmy wondering how do you visualize your plots?

EDIT: Will just go with Jupyter Lab/Notebook, less of a hassle and it would be sort of a report

I have defined all the plots and data I wanna see using my excel tool (which I can share):image.thumb.png.6aa8e0f5eea387e78a94549d4213409d.png
It contains a dictionnary for the attributes (long name, short name), the stats (long & short name, categorization also) a sheet to define my tactic and a sheet with a macro that converts multiple cells into a string containing their values into a python list format, for example ['aaa','bbb','ccc']

I've already wrote a code to import data and clean it, for example converting appropriate stats to integer of float type, or converting appearances (x) y into x+y.

An example of simple plot with matplotlib:
image.thumb.png.7c09d328e3d46e2d2b9ea6523a46a1ce.png

 

In the long term, I also project to analyse how attributes influence my KPIs, so projecting to do some regression analysis after setting up my dashboard, would be a cool project

Hi gam945,

I use Plotly at the moment, couldnt quite work out how to add the player name to a scatter plot on matplotlib.

https://plotly.com/python/plotly-express/

Jupyter is very easy to use so I would definately recommend it. It allows you to test small chunks of code at a time.

I'm impressed with the clarity of your plan. I planned to create this kind of detailed plan up front but I just ending up diving straight in and I've been winging it ever since.

I cant wait to see your progress.

 

Link to post
Share on other sites

This is fantastic! The Python aspect is perhaps beyond me but your statistical analysis is very much up my street. I've just started a save with Brentford FC who are massive on stats in real life and it is definitely an area that I'm going to be placing a lot of emphasis on, in the transfer market especially. Football seems to be becoming more analytical by the day and, honestly, it surprises me that more people don't look at the in-game stats which are actually quite numerous now - and will only become more so. There are some that I find very important such as save % for keepers, shots on target for strikers and key passes.

 

What are your favourite stats and how do these change by position or by role? For example what stats do you place most emphasis on for say central defenders? 

 

Edited by WhoAreYa?
Link to post
Share on other sites

Thanks for the nice feedback. Maybe one day I will be competent enough to make the program really easy to use!

I haven't finalised my stats analysis yet as I have been developing the python code but for central defenders I am currently using : Interceptions/90 vs Headers won/90

I plan to use the stats in here https://totalfootballanalysis.com/category/data-analysis which will mean I have to create some custom ones.

Work has been busy today so havent done much last two days but I will soon.

 

Edited by CowShedBarmyArmy
Link to post
Share on other sites

21 hours ago, WhoAreYa? said:

This may be of interest to you, @CowShedBarmyArmy?

https://theresonlyoneball.com/2019/12/31/0104-scouting-and-transfers/ from  @fmFutbolManager

As I mentioned with my Brentford save, this is the kind of thing that I want to be setting up. Fascinating stuff! 

Thanks for the link, I've read his posts before and they are excellent. I will try and integrate some ideas into my stuff.

I've made some progress today with converting data etc so it should be full steam ahead now.

Think I have a decent way to assess goalkeepers:

Saves/90 vs Goals Conceded/90

Theory being a keeper making lots of saves in a team that doesnt concede much must be doing ok.

I'd love total shots faced but I can't find that in FM20. I had to calculate Saves/90 myself as it doesn't exist.

gk.thumb.PNG.d0ade4fc89994f09db498ffeb391fd9b.PNG

If you have specific metrics you'd like then let me know and i'll create them and upload the file.

Edited by CowShedBarmyArmy
Link to post
Share on other sites

1 hour ago, CowShedBarmyArmy said:

Thanks for the link, I've read his posts before and they are excellent. I will try and integrate some ideas into my stuff.

I've made some progress today with converting data etc so it should be full steam ahead now.

Think I have a decent way to assess goalkeepers:

Saves/90 vs Goals Conceded/90

Theory being a keeper making lots of saves in a team that doesnt concede much must be doing ok.

I'd love total shots faced but I can't find that in FM20. I had to calculate Saves/90 myself as it doesn't exist.

gk.thumb.PNG.d0ade4fc89994f09db498ffeb391fd9b.PNG

If you have specific metrics you'd like then let me know and i'll create them and upload the file.

I seem to remember that there's a stat shown on a player's data profile that isn't shown on the search filter. Their personal data report card near where you look at their coach report. Sure it's something like shots faced or saves made. I can't check right now as I'm waiting for a new computer and can't quite remember it! 

Link to post
Share on other sites

Two new files uploaded to GitHub.

versions.thumb.PNG.9fcbfe9ba54ded631e3cb430ae5d961b.PNG

Added message box to choose between Current Squad data or Potential Signings. This saves having too much data on screen at one time.

messagebox.thumb.PNG.1320b905275926f3772905e2858766e3.PNG

Now the coding is in reasonable shape (for a rookie), I'll focus on creating new player profile scatter plots. At the moment I only have:

Goalkeepers - Saves/90 v Goals Conceded/90

Best Tacklers - Tackles/90 v Tackle Won %

Best Headers - Headers Won/90 v Header Win %

Ball Winners - Tackles/90 v Interceptions/90

Wing Play - Dribbles Per Game v Assists/90

Playmakers - Key Passes/90 v Chances Created/90

Goalscorers - Goals/90 v Shot On Target %

Link to post
Share on other sites

On 14/05/2020 at 20:50, WhoAreYa? said:

I seem to remember that there's a stat shown on a player's data profile that isn't shown on the search filter. Their personal data report card near where you look at their coach report. Sure it's something like shots faced or saves made. I can't check right now as I'm waiting for a new computer and can't quite remember it! 

Think i've sussed it out.

shots saved + goals conceded = shots faced.

saves.PNG.d52133867e257c025289a9b0a3cd3ba9.PNG

Cheers for the heads up :thup:

 

Edited by CowShedBarmyArmy
Link to post
Share on other sites

On 15/05/2020 at 17:47, CowShedBarmyArmy said:

Two new files uploaded to GitHub.

versions.thumb.PNG.9fcbfe9ba54ded631e3cb430ae5d961b.PNG

Added message box to choose between Current Squad data or Potential Signings. This saves having too much data on screen at one time.

messagebox.thumb.PNG.1320b905275926f3772905e2858766e3.PNG

Now the coding is in reasonable shape (for a rookie), I'll focus on creating new player profile scatter plots. At the moment I only have:

Goalkeepers - Saves/90 v Goals Conceded/90

Best Tacklers - Tackles/90 v Tackle Won %

Best Headers - Headers Won/90 v Header Win %

Ball Winners - Tackles/90 v Interceptions/90

Wing Play - Dribbles Per Game v Assists/90

Playmakers - Key Passes/90 v Chances Created/90

Goalscorers - Goals/90 v Shot On Target %

I like the 3d plotly express charts the best as you can include more information. 
Like for wing play, dribbles per game, cross completion, pass percentage.

Feels like I get better information with 3d than just 2d. 

Looked at trying a 3d surface plot but not sure how to fit it to the data

Link to post
Share on other sites

On 27/05/2020 at 23:52, FMFutbol said:

I like the 3d plotly express charts the best as you can include more information. 
Like for wing play, dribbles per game, cross completion, pass percentage.

Feels like I get better information with 3d than just 2d. 

Looked at trying a 3d surface plot but not sure how to fit it to the data

I haven't tried these yet, great idea thanks.

Link to post
Share on other sites

  • 4 months later...

Hi guys

 

I've been trying to teach myself Python over the last few weeks and fm seemed to be a good place to start, and this thread has been a big inspiration for me and I refer back to it every couple days.

 

My goal is to ultimately unearth good value players from scouting only in game statistics not attributes. 

 

An issue that i have run into is converting the Value string into a usable float.  The way the value data is extracted from the game makes it incredibly difficult (for my simple mind) to apply a set of rules to convert it into usable data.

 

Hopefully below will highlight the issue i'm running into.

 

The way I had been looking to take the issue is to replace K or M with a set number of 0's and remove the non-numeric characters. This is obviously isn't going to work due to the structure of the exported data. For example if i replaced M with 000000 i would receive: 

  • 2m = 2000000
  • 7.5m = 75000000
  • 9.75m = 975000000

 

Can anyone tell me how they have solved this? Or if there is a different field available? I'm really not keen on this being a manual process. 

 

image.png.9ee487c62bada4ca7eb9ce518e4bb7e9.png

image.png.e1f874406140340f5bd1581a6be7131b.png

 

image.png

Link to post
Share on other sites

1 hour ago, calv84 said:

Hi guys

 

I've been trying to teach myself Python over the last few weeks and fm seemed to be a good place to start, and this thread has been a big inspiration for me and I refer back to it every couple days.

 

My goal is to ultimately unearth good value players from scouting only in game statistics not attributes. 

 

An issue that i have run into is converting the Value string into a usable float.  The way the value data is extracted from the game makes it incredibly difficult (for my simple mind) to apply a set of rules to convert it into usable data.

 

Hopefully below will highlight the issue i'm running into.

 

The way I had been looking to take the issue is to replace K or M with a set number of 0's and remove the non-numeric characters. This is obviously isn't going to work due to the structure of the exported data. For example if i replaced M with 000000 i would receive: 

  • 2m = 2000000
  • 7.5m = 75000000
  • 9.75m = 975000000

 

Can anyone tell me how they have solved this? Or if there is a different field available? I'm really not keen on this being a manual process. 

 

image.png.9ee487c62bada4ca7eb9ce518e4bb7e9.png

image.png.e1f874406140340f5bd1581a6be7131b.png

 

image.png

 

This is just from the top of my head.

But couldn't you do something like this:

If you encounter 'm' and you know you are dealing with monetary values:

  1. Remove 'm' from the string or trim the string and set the string length to n-1
  2. Try to cast the string to float
  3. Multiply the float by 1000000

This can similarly also be applied to 'k' monetary values (multiplying instead with 100000).

I know there are some steps and each step could present problems, but it is worth a try.

Edited by andershs
Link to post
Share on other sites

1 hour ago, andershs said:

 

This is just from the top of my head.

But couldn't you do something like this:

If you encounter 'm' and you know you are dealing with monetary values:

  1. Remove 'm' from the string or trim the string and set the string length to n-1
  2. Try to cast the string to float
  3. Multiply the float by 1000000

This can similarly also be applied to 'k' monetary values (multiplying instead with 100000).

I know there are some steps and each step could present problems, but it is worth a try.

Of course...

 

I'll give that a go. Thank you. 

Link to post
Share on other sites

Damn. I really wish I found this thread months ago I actually have the stuff on my laptop to install Python but never got round to it. I kinda wish I had now. Instead, I manually did all the formulas in excel for my club dna AND every position available. 🙄

I always got too confused when it came to some of the stuff like tackles per 90 and tackle win %, so I just didn't bother with that, despite wanting to. 

Edited by EnigMattic1
Link to post
Share on other sites

  • 4 weeks later...
On 11/10/2020 at 08:42, calv84 said:

Hi guys

 

I've been trying to teach myself Python over the last few weeks and fm seemed to be a good place to start, and this thread has been a big inspiration for me and I refer back to it every couple days.

 

My goal is to ultimately unearth good value players from scouting only in game statistics not attributes. 

 

An issue that i have run into is converting the Value string into a usable float.  The way the value data is extracted from the game makes it incredibly difficult (for my simple mind) to apply a set of rules to convert it into usable data.

 

Hopefully below will highlight the issue i'm running into.

 

The way I had been looking to take the issue is to replace K or M with a set number of 0's and remove the non-numeric characters. This is obviously isn't going to work due to the structure of the exported data. For example if i replaced M with 000000 i would receive: 

  • 2m = 2000000
  • 7.5m = 75000000
  • 9.75m = 975000000

 

Can anyone tell me how they have solved this? Or if there is a different field available? I'm really not keen on this being a manual process. 

 

image.png.9ee487c62bada4ca7eb9ce518e4bb7e9.png

image.png.e1f874406140340f5bd1581a6be7131b.png

 

image.png

I can send you my code to show you how i solved this.

financial = squad[['Name', 'Age', 'Wage', 'Value', 'Expires', 'Mins']].copy()
for column in ['Value', 'Wage']:
    financial[column] = financial[column].str.replace('Â', '')
    financial[column] = financial[column].str.replace('p/w', '')
    financial[column] = financial[column].str.replace('£', '').copy()

Kind of weird out of context, but hopefully makes sense.

Link to post
Share on other sites

On 12/10/2020 at 00:15, EnigMattic1 said:

Damn. I really wish I found this thread months ago I actually have the stuff on my laptop to install Python but never got round to it. I kinda wish I had now. Instead, I manually did all the formulas in excel for my club dna AND every position available. 🙄

I always got too confused when it came to some of the stuff like tackles per 90 and tackle win %, so I just didn't bother with that, despite wanting to. 

If I can help at all give me a shout. I was a complete novice when I started. I still don't fully understand all of what I'm doing but you make big gains by diving in and having a go.

Link to post
Share on other sites

My code is an absolute shambles at the moment as I have been trying all sorts of things and been busy in work but feel free to poke around and have a look.

I've uploaded a squad view and scouting view for exporting the data. Also a css file to make the html output look prettier.

All you need to do is set the correct path so the program can find your exported fm data (change bold text to your location)

 

squad = pd.read_html(
    r"C:\Users\stuar\Documents\Sports Interactive\Football Manager 2020\html\fmi_4_sq.html"
 )[0]
scouting = pd.read_html(
    r"C:\Users\stuar\Documents\Sports Interactive\Football Manager 2020\html\fmi_4_sc.html"
 )[0]

 

 

fmi_4.py df_style.css scout_analysis_fmi4.fmf squad_analysis_fmi_4.fmf

Edited by CowShedBarmyArmy
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...