[R&F] Use machine learning to select better city settlement locations

What I found particular interesting about the result is the NOT settling next to a river is quantifiably negative. It doesn't determine if the city will be good, but it tells you that not settling next to a river is a poor choice. (On average given the limited information provided). Likewise, the Lux seems a no brainer to me. Also, the fact that the model values GrasslandMountains is telling. You can't work a mountain tile, but it does provide adjacency bonuses. The fact that the model detected this with limited information is interesting to me.

All of the above makes a great deal of sense to me, when talking about your first few cities. The free housing from the river lets the city grow bigger, faster. (You don't even need an amenity for your first two Pop in a city, a big reason why "infinite city spam" is still powerful in civ 6). Later on more smaller cities > fewer big cities and avoiding water starts in order to fit an extra city or two in makes sense (plus you can spend gold getting the new cities up and running), but early on a river start > coastal start >> waterless start.

Having Mountains nearby is also really useful for your initial cities. It provides adjacency bonuses to what will often be the two earliest districts you have access to: Campuses and Holy Sites. I'm a bit surprised the model is sensitive enough to pick up on that, as it only plays out once the districts are completed. I wonder if the AI is programmed to be more likely to build these districts if there's a Mountain nearby, and since building these districts improves yields without occupying a Population, what the model is actually picking up is the value of getting districts out early?

Luxuries are also very valuable, although mostly for reasons your model wouldn't detect: the ability to support a larger population or to sell them for early gold.

A variety of bonus resources is also extremely good for a reason your model wouldn't detect: one Stone (or Marble) gets a eureka, one Wheat/Rice gets a eureka, one Horse/Sheep gets a eureka, etc. Those boosts are like getting a ton of hidden science yield.

That your model picked up on the value of Luxuries is likely for the reason that @Arent11 mentioned. Probably the most important factor in the value of a city site is how many tiles does it have within it's first two rings that have a combined yield of 4 or more? Bonus and strategic resources should contribute to this, too, not just luxuries, but possibly the AI favours improving the luxury tiles before the other resource tiles, making the boost from luxuries more obvious to the model.
 
I mean the dataset is biased to only those location that AI prefers. So it is only learning "how AI performs on AI preferred starting locations.", that makes no sense to human players, since in Civ 6 AI basically play at a terribly low level.

I must be a terribly player then cause the yields some of these AI cities got too are admirable :) Granted this may just be because of fantastic starting locations, but then I want to know what those locations are.

Anyway, thank you for explaining. It makes sense, I disagree that the exercise has no value for human players, but see your point.

A variety of bonus resources is also extremely good for a reason your model wouldn't detect: one Stone (or Marble) gets a eureka, one Wheat/Rice gets a eureka, one Horse/Sheep gets a eureka, etc. Those boosts are like getting a ton of hidden science yield.

That your model picked up on the value of Luxuries is likely for the reason that @Arent11 mentioned. Probably the most important factor in the value of a city site is how many tiles does it have within it's first two rings that have a combined yield of 4 or more? Bonus and strategic resources should contribute to this, too, not just luxuries, but possibly the AI favours improving the luxury tiles before the other resource tiles, making the boost from luxuries more obvious to the model.
Almost all the bonuses were deemed positive and I think the only reason that they are not all there is limited input data.

Very useful, to me, reply. Thanks
 
Last edited by a moderator:
Hi!

I think you don't need machine learning to do this. Why not use OLS, as you would also get interpretable results? Also, you don't tell us what the graph means (numbers, colors, shape). And what are the variables? These things should be part of the introduction, so we can see what is going on. If you try to be scientific, don't skip the most important parts.

And you also don't tell us why do you do this, so what are we learning from these results. I mean, as someone else already said, you calculate something using the nonrandom placement of ai cities, that are managed by the ai. Why a human should be interested what is good or not good for the ai? What happens if a city is captured? City growth definitely depends on whether city builds units/settlers/workers/barracks or buildings that affects growth. Also it depends how many workers are used in that city. Etc. Without discussing things like these, a don't beleive your claims (order of significance).
 
Hi!

I think you don't need machine learning to do this. Why not use OLS, as you would also get interpretable results? Also, you don't tell us what the graph means (numbers, colors, shape). And what are the variables? These things should be part of the introduction, so we can see what is going on. If you try to be scientific, don't skip the most important parts.

And you also don't tell us why do you do this, so what are we learning from these results. I mean, as someone else already said, you calculate something using the nonrandom placement of ai cities, that are managed by the ai. Why a human should be interested what is good or not good for the ai? What happens if a city is captured? City growth definitely depends on whether city builds units/settlers/workers/barracks or buildings that affects growth. Also it depends how many workers are used in that city. Etc. Without discussing things like these, a don't beleive your claims (order of significance).

Hi @fiziqs, I'm happy to see you made your first post on this thread. Not that I am a regular, but welcome to civfanatics nevertheless.

I don't believe the average reader of this thread is into the science side of it, which is why I left it on the GitHub repo. Have you read the report and looked at the jupyter notebooks?
 
I don't believe the average reader of this thread is into the science side of it, which is why I left it on the GitHub repo. Have you read the report and looked at the jupyter notebooks?

Hi, thanks for the fast response. I read the github readme file (Civ6RFCitySettlement). Oh, now I just found your full report (the pdf), but the link pointing to it in the readme file is not working. The papers in the reference document folder are definitely beyond my programming and machine learning level :D. But I still cant connect the red and blue graph to your interpretation of the results. Could you help me out? :)
 
Hi, thanks for the fast response. I read the github readme file (Civ6RFCitySettlement). Oh, now I just found your full report (the pdf), but the link pointing to it in the readme file is not working. The papers in the reference document folder are definitely beyond my programming and machine learning level :D. But I still cant connect the red and blue graph to your interpretation of the results. Could you help me out? :)

I fixed the link in the README, thank you for pointing it out. Got caught out by case sensitivity! Took me a while to spot the faulty capital I.

SHAP is a module developed by Scott Lundberg. Scott describes the module as "a unified approach to explain the output of any machine learning model. SHAP connects game theory with local explanations..." If you want to understand what Shapley values are the following video made the most sense to me.

Mathematically the XGBoost classifier model outputs a number between 0 and 1. If the number is larger than 0.5 the city is classified as "good", and if less "poor". This model uses input features consisting of terrain/feature combos, resources, and cityHasRiver to determine the output number.

The SHAP summary graph gives you the list of features that contribute the most to the predicted value of whether a city is good or poor. Features that have the most influence on the output value are deemed more significant and appear at the top of the Summary graph. Visually you can see this in the graph as it looks a little like a funnel as you read down the list. Also the blue and red blobs are closer together as you move down the list.

The blue to red gradient feature value is literally indicative of the number of the feature. Blue are small values and Red are large values. Small and Large are relative to the feature. That is, the SHAP summary normalises these to output them in one graph. For example the low value of cityHasRiver is 0 and the high value is 1. Likewise for GrasslandHillsWoods the input value ranges between 0 and 0.21. In the graph High for cityHasRiver is 1 and for GrasslandHillsWoods High is 0.21. To see this you need to look at the Jupiter notebook with the name starting 05c Modelling...

I'll use the cityHasRiver to explain the last part because it is the simplest. The input is either 0 or 1. The blue bit is flat as the output of the model when the input for cityHasRiver is 0 more spread out and there are fewer of them. The red bit is a blob indicating the output value impact is more concentrated. I interpret this as the impact of cityHasRiver being 0 is a negative contribution with a wider range, while the impact of cityHasRiver being 1 is a positive contribution with a narrower output range.

Lastly, the graph is plotted using all the individual city input/output values.

I hope it make more sense now.
 
Ok, I understand now, thanks. Last question: the two red dots of the bananas mean that
a, 2 bananas is much better than 1 banana
b, in some cases 1 banana is very good, on other cases 1 banana is good, but less good
c, banana is a 0/1 variable, blue is 0 banana, 1 is at least 1 bananas?
 
Ok, I understand now, thanks. Last question: the two red dots of the bananas mean that
a, 2 bananas is much better than 1 banana
b, in some cases 1 banana is very good, on other cases 1 banana is good, but less good
c, banana is a 0/1 variable, blue is 0 banana, 1 is at least 1 bananas?

It is actually d :) (Or maybe your description of b?)

Red indicates high value of Bananas,. The position on the graph is the impact having Bananas has on that specific city. That is, the two read dots may have the same value of Bananas hence the same colour. In the graph the impact of there being Bananas was calculated as more impactful on the eventual model estimate score in one of the instances where there was a Bananas. For the record the highest input Bananas value is 0.158 which equates to 3 Bananas.

You can also think of the graph as the Shapley score for each feature for each city. A bit like a multidimensional scatter plot.
 
Last edited:
Top Bottom