6

Plotting Predictive Crime Curves | Andrew Wheeler

 3 years ago
source link: https://andrewpwheeler.com/2019/04/15/plotting-predictive-crime-curves/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Plotting Predictive Crime Curves

Writing some notes on this has been in the bucket list for a bit, how to evaluate crime prediction models. A recent paper on knife homicides in London is a good use case scenario for motivation. In short, when you have continuous model predictions, there are a few different graphs I would typically like to see, in place of accuracy tables.

The linked paper does not provide data, so what I do for a similar illustration is grab the lower super output area crime stats from here, and use the 08-17 data to predict homicides in 18-Feb19. I’ve posted the SPSS code I used to do the data munging and graphs here — all the stats could be done in Excel though as well (just involves sorting, cumulative sums, and division). Note this is not quite a replication of the paper, as it includes all cases in the homicide/murder minor crime category, and not just knife crime. There ends up being a total of 147 homicides/murders from 2018 through Feb-2019, so the nature of the task is very similar though, predicting a pretty rare outcome among almost 5,000 lower super output areas (4,831 to be exact).

So the first plot I like to make goes like this. Use whatever metric you want based on historical data to rank your areas. So here I used assaults from 08-17. Sort the dataset in descending order based on your prediction. And then calculate the cumulative number of homicides. Then calculate two more columns; the total proportion of homicides your ranking captures given the total proportion of areas.

Easier to show than to say. So for reference your data might look something like below (pretend we have 100 homicides and 1000 areas for a simpler looking table):

 PriorAssault  CurrHom CumHom PropHom PropArea
 1000          1         1      1/100    1/1000
  987          0         1      1/100    2/1000
  962          2         4      4/100    3/1000
  920          1         5      5/100    4/1000
    .          .         .       .        .
    .          .         .       .        .
    .          .         .       .        .
    0          0       100    100/100 1000/1000

You would sort the PriorCrime column, and then calculate CumHom (Cumulative Homicides), PropHom (Proportion of All Homicides) and PropArea (Proportion of All Areas). Then you just plot the PropArea on the X axis, and the PropHom on the Y axis. Here is that plot using the London data.

AOTcuF2azrqVnaVLVfii6n4vx5eo6lpoVKA92_F3eCub9IrNpcg6RewQC_SiimtVsizEVn4xhdTBHYNghJAu9zC8D7JR4sJJgn6lImeMLj6mbvniNhrjyrBDB-LGggTX_3TgmI0Wbe9X3DqEgVGtChBn406t01LoZq83vgeB5jZLofCMOVxVcU3vL6-gRINJ_oooKHC_UqMhb0uToPSD7oV7r44Z9m59RBPtfSU6Ubn5KImb6X6EMVAISc6L7v6cG8fVwJM0AueXdrvXRMjMVjowUmeYKQqUVExkH45QP5znnzXFAhbqzu2YtIAna2LDuBJUt4XMAekXBwBbuQaH7iB-9zOHaSMs_BoAITIlaegf1-7sLPT3Juri52vRjT2fU53GWLQ7Lf3E3aHXBUo5fIJKSmYjJixTUMp2ItSg7qZGQDb0xrAs2MJkIyxJge0QpzLuQjsnugq9LO5xDW5PXhqVFdy6zUQoy1JnKL2eYLJNXc3kicFduoBtnF76pTVNVvXwTOa5jkG5o0a0w5PQbFr4tbnSYJGoWIkTThhemTifrX7-Gz805F5zxZNAWKVEgy7iu_2rbKIij0e0LzZIsS3KDr2x8gpWqmh5JJZ0sc-XSrlKWHcxw_ec7ZPNMg8vE3e29AjbRNBKuVRarC1skqRnSprWauI=s500-no

Paul Ekblom suggests plotting the ROC curve, and I am too lazy now to show it, but it is very similar to the above graph. Basically you can do a weighted ROC curve (so predicting areas with more than 1 homicide get more weight in the graph). (See Mohler and Porter, 2018 for an academic reference to this point.)

Here is the weighted ROC curve that SPSS spits out, I’ve also superimposed the predictions generated via prior homicides. You can see that prior homicides as the predictor is very near the line of equality, suggesting prior homicides are no better than a coin-flip, whereas using all prior assaults does alittle better job, although not great. SPSS gives the area-under-the-curve stat at 0.66 with a standard error of 0.02.

V-s_swb4WFgGWcqN9GL_6blAvDQo99j6VcuSVYyo4FAJtpVgZRS-Plgz5PB0zEoAXr-xLSExchJzwIemVKgO1PhN38dCKTPG1toctFmhrffrxPRwYfQqa71Bl3dFolN6ZV36HjRPg0if6cOOID6e-r8ANlSNlRAV_gHzL1rWwB6TxBUV0CzSbOquV5AvqgdH8xFp_99pF-Zh_5UhamBBfq4kHHT3G9ZCTfizXZ39fFGHZqOrJC9dBRxTcYS8gbpgPqgWv71VJ_s21btVoy_GfD_iyYdugdjz9aKe3wM1GGE49WS9HvoHHVidBzwYw-21vKiur5peyJeU_Zw1AGaTHYYo8nvpPSq90_UGw5ATp7e1lGthaizLQk8FUbq_qr6n9OdFqIiAb_2pRkLPNQS_HLk1zJVqwDNfXQqcplB5D2YoK1cMkyYubEbQBQ3us09zsR9EEPCT8VSc0ECiaTDe42ZjmnDS8bxjlOfnQE2ApWtjLNWpik1nv-N7a_9gMVd9CGQ96zkGVHjK2ZFwJ_jRNpz1kIxSxbrWoWI3aJSiOiisLphc93Tvy2TShBZ-nemmdr0JhMLsq7-wYip7Dit-2KgvUM5KKrn3mzkJkPSflc_0SnnKKJ8fqeZXWcI55rGf0KM9i_J4Gw4mlJs2a_mYgbQ0cO-1DCw=w850-h500-no

Note that the prediction can be anything, it does not have to be prior crimes. It could be predictions from a regression model (like RTM), see this paper of mine for an example.

So while these do an OK job of showing the overall predictive ability of whatever metric — here they show using assaults are better than random, it isn’t real great evidence that hot spots are the go to strategy. Hot spots policing relies on very targeted enforcement of a small number of areas. The ROC curve shows the entire area. If you need to patrol 1,000 LSOA’s to effectively capture enough crimes to make it worth your while I wouldn’t call that hot spots policing anymore, it is too large.

So another graph you can do is to just plot the cumulative number of crimes you capture versus the total number of areas. Note this is based on the same information as before (using rankings based on assaults), just we are plotting whole numbers instead of proportions. But it drives home the point abit better that you need to go to quite a large number of areas to be able to capture a substantive number of homicides. Here I zoom in the plot to only show the first 800 areas.

7upCYqpga-em1zNV4xQYfqG4rLMe9FwSdoByB7CE_VHKNcx5to_uotesTglDOUiLa52UVTeYJp0RZAxnP57sAjpP3ioLclMOnRu8mdSYm3hgdqg5FNgTrLkQjpcQZFBoqENGsM_vBxuXuvBmZdhVi5GYEXQeGpuEZ2oRddNEElVFkjCOWWj9-E0e75yfuYgzwbi0lo8IVxswgT0HQW61PREy37ySnmw8zy8IGA8AqLsxNt7JxIIqVJKHBxi4Kscoyag7ZtyeaGQcCUheZ7K6cANaYX7XZPnQki70KiHYnwo6imObIVLpDeYod7pM14nNb0kaiXSfP31P6J4pgA1YN635dKewm2XDvgxbgoOMVoZ7E4-7tmMTAxH-GZF41sJeg2SZfyS4sC4iCeznweNt1cme9i1obkAvN3ml3AY-vltyu3aipmbmGng1x7RtOaB0pPZeG6M2KplTu08SGHtBRaNxA-9Am4Xj3TukuJunS4Wg3IyKv2CEE7UuFtK_HSBgCijm8QpL35tY9WIuygsgv1cMfpV9CkSSuKWkJwj0KXnzckcfHFtOsXNSChIM8jHxNS0C3OkffV8Bf2TTOtrfIfim2NPt1BOkMmbWNsvUcpByGHNIN38c9zXZF11mLo-EYcBmKeQInD9KgZqHNZXVvaVGEFk4Vb4=w850-h500-no

So even though the overall curve shows better than random predictive ability, it is unclear to me if a rare homicide event is effectively concentrated enough to justify hot spots policing. Better than random predictions are not necessarily good enough.

A final metric worth making note of is the Predictive Accuracy Index (PAI). The PAI is often used in evaluating forecast accuracy, see some of the work of Spencer Chainey or Grant Drawve for some examples. The PAI is simply % Crime Captured/% Area, which we have already calculated in our prior graphs. So you want a value much higher than 1.

While those cited examples again use tables with simple cut-offs, you can make a graph like this to show the PAI metric under different numbers of areas, same as the above plots.

dJq94VNtFHCPUyPXPzNN0CWAlXtv0b8Y5HBJCa9ZPpPYK4psp5EQBzcKYffvKDZnPDiOMJnq3rZzV3D-4tpOTvXaW1BSnQEUy-YpskK9BPDWS8Q4d_Y2WtfA5qdHVj2-C7-42hKOyRgtYJGBx-Kho-JdZWfku8h8hiHalYT5izevtVHqasSfRLkl83-a0jJ2iLcuH0VFHoIv8QnbL9WoJAAxlolUth5tyT3MK9lxgan62h5Nd0F6IiHZ9OlAlWVrreROV1lllb8HvPCxwOvVRmGb3gLWPovHpVcNBXSlSp0M7ZnWtbYWQpdopSqxoFDLY2jPNm0mv7_C_ztajid75755pSxW3pFIVn6c1kFzy1ym_g3ZCMna-RGpuS3yqFxH9G_5gkcKiMdO3ZYysgWDVzvakLMQbOfAlwkZMApfGP4_qZtdrCett0zcM_1aO-0Ieek-yhCbpsZ4zudob1opqiolYQogIooe9omq6N8tzRbNozxcFwb9oqcrhalo1rhEFITbk7DEKH2T31GovKiRUjoGaeuTAgMqhmCm-ybAzdKKiodxpy6_Yb63ztZT_npIoOmF2J5IkGkFU5Zh9F_W-l0i4cL_CQdZiq9MWX9-fQLICuFKwisGahESIc6nm_cmDQUBCJcGDT0ZCnOBLCp8YIcx8JzqJuE=w850-h500-no

The saw-tooth ends up looking very much like a precision-recall curve, but I haven’t sat down and figured out the equivalence between the two as of yet. It is pretty noisy, but we might have two regimes based on this — target around 30 areas for a PAI of 3-5, or target 150 areas for a PAI of 3. PAI values that low are not something to brag to your grandma about though.

There are other stats like the predictive efficiency index (PAI vs the best possible PAI) and the recapture-rate index that you could do the same types of plots with. But I don’t want to put everyone to sleep.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK