In [22]:
import tag_article
from tag_article import LemmaTokenizer
import load_data as ld
import sklearn.metrics
import numpy as np
In [3]:
crimes, crime_strings = ld.load_crime_data()
In [4]:
articles = ld.load_data()
C:\Users\kevin.rose\AppData\Local\Continuum\Anaconda2\envs\py35\lib\site-packages\IPython\core\interactiveshell.py:2881: DtypeWarning: Columns (3) have mixed types. Specify dtype option on import or set low_memory=False.
exec(code_obj, self.user_global_ns, self.user_ns)
In [5]:
clf, vectorizer = tag_article.load_model()
In [15]:
v_c = vectorizer.transform(crime_strings.fillna('').values)
In [106]:
v_a = vectorizer.transform([articles['bodytext'].values[32]])
In [107]:
cs = sklearn.metrics.pairwise.cosine_similarity(v_c, v_a).flatten()
In [ ]:
In [114]:
sorted_idx = np.argsort(cs, 0)
In [115]:
cs[sorted_idx[-1]]
Out[115]:
0.16633695978261512
In [116]:
print(articles['bodytext'].values[32])
crimes.iloc[sorted_idx[-10:], :]
# Cops: Man shot to death after leaving wake of gang member
SUN-TIMES MEDIA WIRE May 24, 2011 02:14PM
* * * * [ Reprints ][1]
* [ E-Mail ][2]
* [ Print ][3]
A 23-year-old man was shot to death early Tuesday in the Logan Square
neighborhood shortly after attending the wake of a gang member, according to
police.
The victim and another man had left the wake when someone opened fire,
striking the victim twice, police News Affairs Officer Michael Sullivan said.
Police were notified at 4:17 a.m. and the body was found in an alley on the
2700 block of North Albany Avenue, according to Sullivan.
The shooting is believed to be gang-related, Sullivan said. The victim was not
believed to be in a gang but the man he was with is in a gang, Sullivan said.
The shooter was described as a Hispanic male, 5-foot-8 to 5-foot-9, and
150-160 pounds.
No one was in custody as of Tuesday afternoon.
The Cook County Medical Examiner’s office confirmed the death, but a spokesman
said the man’s identity could not be released pending notification of family.
Grand Central detectives are investigating.
© 2011 Sun-Times Media, LLC. All rights reserved. This material may not be
copied or distributed without permission. For more information about reprints
and permissions, visit [ www.suntimesreprints.com ][4] . To order a reprint of
this article, [ click here ][4] .
[ Special Home Delivery Offer ][5]
Comments Click here to view or make a comment
[ Advertise Here ][6]
[1]: http://www.SunTimesReprints.com (Order Reprints)
[2]: /csp/cms/sites/STM/templates/forms/emailtofriend.csp
[3]: ?print=true (Print This Story)
[4]: http://www.suntimesreprints.com
[5]: https://register.suntimesnewsgroup.com/clickshare/selectDeliveryPublicat
ion.do
[6]: http://www.suntimesmediaholdings.com/media-kit
Out[116]:
ID
Case Number
Date
Block
IUCR
Primary Type
Description
Location Description
Arrest
Domestic
...
Ward
Community Area
FBI Code
X Coordinate
Y Coordinate
Year
Updated On
Latitude
Longitude
Location
874859
9358175
HW501469
10/21/2013 11:05:00 AM
020XX N CALIFORNIA AVE
1811
NARCOTICS
POSS: CANNABIS 30GMS OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
35.0
22.0
18
1157378.0
1913344.0
2013
02/04/2016 06:33:39 AM
41.917980
-87.697212
(41.917980381, -87.697212498)
264163
8383484
HT616929
12/04/2011 01:00:00 AM
017XX W ARMITAGE AVE
1811
NARCOTICS
POSS: CANNABIS 30GMS OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
32.0
22.0
18
1164276.0
1913355.0
2011
02/04/2016 06:33:39 AM
41.917867
-87.671869
(41.917867367, -87.671868599)
20555
8006212
HT237806
04/06/2011 09:20:00 PM
039XX W FULLERTON AVE
1811
NARCOTICS
POSS: CANNABIS 30GMS OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
30.0
22.0
18
1149541.0
1915660.0
2011
02/04/2016 06:33:39 AM
41.924492
-87.725946
(41.924491602, -87.725945966)
1015527
9602751
HX252850
05/07/2014 10:25:00 PM
028XX W FULLERTON AVE
1811
NARCOTICS
POSS: CANNABIS 30GMS OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
35.0
22.0
18
1157222.0
1915830.0
2014
02/04/2016 06:33:39 AM
41.924805
-87.697718
(41.92480533, -87.697717952)
403504
8607286
HV280856
05/10/2012 09:47:00 PM
034XX W DIVERSEY AVE
1811
NARCOTICS
POSS: CANNABIS 30GMS OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
35.0
22.0
18
1152987.0
1918406.0
2012
02/04/2016 06:33:39 AM
41.931959
-87.713211
(41.931959172, -87.71321084)
1321583
10210645
HY397547
08/25/2015 10:15:00 PM
023XX W LOGAN BLVD
1821
NARCOTICS
MANU/DEL:CANNABIS 10GM OR LESS
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
1.0
22.0
18
1160418.0
1917765.0
2015
09/01/2015 03:10:12 PM
41.930049
-87.685921
(41.930049492, -87.685920733)
735114
9134757
HW279456
05/17/2013 09:55:00 PM
021XX N CALIFORNIA AVE
3750
INTERFERENCE WITH PUBLIC OFFICER
ESCAPE
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
35.0
22.0
24
1157345.0
1914452.0
2013
02/04/2016 06:33:39 AM
41.921021
-87.697304
(41.921021491, -87.69730355)
4058603
10734534
HZ493706
10/29/2016 07:33:00 AM
027XX N MILWAUKEE AVE
4386
OTHER OFFENSE
VIOLATION OF CIVIL NO CONTACT ORDER
PARKING LOT/GARAGE(NON.RESID.)
False
False
...
35.0
22.0
26
1153986.0
1917838.0
2016
11/05/2016 03:47:16 PM
41.930381
-87.709555
(41.930380649, -87.709554828)
739363
9141223
HW286182
05/22/2013 02:23:00 PM
026XX N ELSTON AVE
3710
INTERFERENCE WITH PUBLIC OFFICER
RESIST/OBSTRUCT/DISARM OFFICER
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
1.0
22.0
24
1160906.0
1917621.0
2013
02/04/2016 06:33:39 AM
41.929644
-87.684131
(41.929644221, -87.684131464)
15902
7999236
HT230544
04/02/2011 07:45:00 AM
020XX N MILWAUKEE AVE
3710
INTERFERENCE WITH PUBLIC OFFICER
RESIST/OBSTRUCT/DISARM OFFICER
PARKING LOT/GARAGE(NON.RESID.)
True
False
...
1.0
22.0
24
1159269.0
1913573.0
2011
02/04/2016 06:33:39 AM
41.918570
-87.690259
(41.918570075, -87.690258545)
10 rows × 22 columns
In [ ]:
Content source: kbrose/article-tagging
Similar notebooks: