8.1 Predictions vs probabilities
So far we’ve been looking at predictions, with a straight 0
or 1
. Many classifiers can give you a probability measurement instead of a straight prediction, which can be useful if you’d like to take the top 500 “most-likely” items to review instead of just the ones predicted as category 1
.
In the case below, we’re using the LogisticRegression
classifier to assign not only a prediction
column, but also a predict_proba
column. This column is the chance that the given row is in category 1
.
# Create a new classifier - LogisticRegression can use probabilities
clf = LogisticRegression(C=1e9)
# Teach the classifier how the words (X) relate to the categories (y)
clf.fit(X, y)
# Make our predictions and see how it looks
## LogisticRegression(C=1000000000.0, class_weight=None, dual=False,
## fit_intercept=True, intercept_scaling=1, l1_ratio=None,
## max_iter=100, multi_class='warn', n_jobs=None, penalty='l2',
## random_state=None, solver='warn', tol=0.0001, verbose=0,
## warm_start=False)
We can take a look at the top 20 reports most likely to be serious assaults.
CCDESC | DO_NARRATIVE | is_part_i | reported | prediction | predict_proba | |
---|---|---|---|---|---|---|
8967 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO- SUSPS DROVE PASS VICT AS HE WAS PUMPING GAS INTO HIS VEH AND THE REAR PASSGR S1 FIRED ON SHOT IN VICT DIR STRIKING V VEH SUSP FLED SB. INHERENT GANG | 1 | 1 | 1 | 1.0000000 |
5033 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S CONFRONTED VS AS THEY EXITED DONUT SHOP ACCUSED THEM OF VANDALIZING HIS TRUCK S PEPPERSPRAYED V1S FACE AND POINTED KNIFE AT BOTH VS RELTD 121507330 | 1 | 1 | 1 | 1.0000000 |
17880 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSPS DROVE BY LOC AND FIRED APPROX 8-9 ROUNDS AT VICT WHO WAS SEATED AT UPSTAIRS BALCONY SUSPS FLED LOC IN A NEWER 4DR GOLD SEDAN EB 37TH | 1 | 1 | 1 | 1.0000000 |
11528 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSPS DROVE BY LOC AND FIRED APPROX 8-9 ROUNDS AT VICT WHO WAS SEATED AT UPSTAIRS BALCONY SUSPS FLED LOC IN A NEWER 4DR GOLD SEDAN EB 37TH | 1 | 1 | 1 | 1.0000000 |
30685 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO–S ONE PRODUCED KNIFE AND FIGHT OCCURRED S TWO THEN CAME TO STORE AND ADW STABBING OCCURRED KNIFE IS BRASS KNUCKLE HOOKED BLADE PACAS GANG MEMBER | 1 | 1 | 1 | 1.0000000 |
5634 | CHILD ABUSE (PHYSICAL) - AGGRAVATED ASSAULT | DO-VICT WAS BROUGHT TO HOSPITAL WITH A HEAD TRAUMA V WAS ALSO DIAGNOSED W RETINAL HEMORRHAGES VICT IS IN CRITICAL CONDITION | 1 | 1 | 1 | 1.0000000 |
17517 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP AND VICT INVOLVED IN DISPUTE OVER CABINETS IN GARAGE SUSP BECAME ENRAGED AND HIT VICT W LG STICK AND HAMMER IN THE RIB CAGE | 1 | 1 | 1 | 1.0000000 |
31224 | CHILD ABUSE (PHYSICAL) - AGGRAVATED ASSAULT | DO-VICT DISCLOSED THAT SUSP HIT HIM WITH A BELT OR A WIRE WHICH HE DESCRIBES AS A POWER CORD | 1 | 1 | 1 | 1.0000000 |
15140 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-UNK SUSPS ATTEMPTED TO ROBB A TACO TRUCK SUSP FIRED ONE ROUND STRIKING VICT SUSPS THEN FLED ON FOOT NORTHBOUND MCKINLEY FROM VERNON AVE | 1 | 1 | 1 | 1.0000000 |
11504 | INTIMATE PARTNER - AGGRAVATED ASSAULT | DO- SUSP GOT ANGRY AT VICT SUSP BACKHANDED BICT TWICE IN THE FACE SUSP STRUCK VICT WITH SOUVERNIR BASEBALL BAT SUSP CHOKED VICT BCIT FLED LOC | 1 | 1 | 1 | 1.0000000 |
12428 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 FIRED TWO ROUNDS FROM A 9MM SEMI AUTOMATIC HANDGUN AT V1 V1 WAS WOUNDED IN BOTH ANKLES S1 FLED SOUTHBOUND FIGUEROA BL VIA VEH | 1 | 1 | 1 | 1.0000000 |
11884 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 FIRED TWO ROUNDS FROM A 9MM SEMI AUTOMATIC HANDGUN AT V1 V1 WAS WOUNDED IN BOTH ANKLES S1 FLED SOUTHBOUND FIGUEROA BL VIA VEH | 1 | 1 | 1 | 1.0000000 |
15647 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-VICT AND SUSP BECAME INVOLVED IN A VERBAL ARGUEMENT S PRODUCE BAT AND STRUCK V1 AND V2 SUSP FLED LOCATION PER V S1 & S2 ARE SUR13 G/M’S W/GANG TT’S | 1 | 1 | 1 | 0.9999999 |
12625 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-VICT AND SUSP BECAME INVOLVED IN A VERBAL ARGUEMENT S PRODUCE BAT AND STRUCK V1 AND V2 SUSP FLED LOCATION PER V S1 & S2 ARE SUR13 G/M’S W/GANG TT’S | 1 | 1 | 1 | 0.9999999 |
8854 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-UNK S IN A BLK SUV PULLED TO THE LEFT OF THE V AND FRNT PSGR PULLED OUTA HANDGUN AND SHOT V ONCE HITTING HIM IN THE ARM SUSPS THEN FLED LOC | 1 | 1 | 1 | 0.9999999 |
10000 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-V CONFRONTED S BELIEVING S BURGLARIZED VS RESIDENCE PREVIOUS DAY S AND V FIGHT S STABBED V ONCE IN THE BACK AND FLED INTO APT COMPLEX BKG 3093566 | 1 | 1 | 1 | 0.9999999 |
31316 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP BRANDISHED AND THREATENED VICT WITH EYEBROW RAZOR STATING IM GOING TO CUT YOU USING A STRIKING MOTION AT VICT | 1 | 1 | 1 | 0.9999999 |
11684 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 PUSHED V1 AND THEN SWUNG A KNIFE AT THE V1 IN A SLICING MOTION CAUSIA CUT APPROX 2 INCHES ON THE LEFT SIDE OF V1 NECK | 1 | 1 | 1 | 0.9999999 |
30790 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-DEFT SWUNG SHOVEL MUL TIMES AT VICT AND NARROWLY MISSED VICT HEAD S THRTO KILL VICT SUSP IS 5 TREY AVALON CRIP | 1 | 1 | 1 | 0.9999998 |
7521 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP POINTED UNK CALIBER SEMIAUTO HANDGUN AT VICT STATING MOTHERFUCKER CUAISNG VICT TO RUN AWAY SUSP FLED ON FOOT | 1 | 1 | 1 | 0.9999997 |
As well as the top 20 assaults least likely to be serious assault.
CCDESC | DO_NARRATIVE | is_part_i | reported | prediction | predict_proba | |
---|---|---|---|---|---|---|
8967 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO- SUSPS DROVE PASS VICT AS HE WAS PUMPING GAS INTO HIS VEH AND THE REAR PASSGR S1 FIRED ON SHOT IN VICT DIR STRIKING V VEH SUSP FLED SB. INHERENT GANG | 1 | 1 | 1 | 1.0000000 |
5033 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S CONFRONTED VS AS THEY EXITED DONUT SHOP ACCUSED THEM OF VANDALIZING HIS TRUCK S PEPPERSPRAYED V1S FACE AND POINTED KNIFE AT BOTH VS RELTD 121507330 | 1 | 1 | 1 | 1.0000000 |
17880 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSPS DROVE BY LOC AND FIRED APPROX 8-9 ROUNDS AT VICT WHO WAS SEATED AT UPSTAIRS BALCONY SUSPS FLED LOC IN A NEWER 4DR GOLD SEDAN EB 37TH | 1 | 1 | 1 | 1.0000000 |
11528 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSPS DROVE BY LOC AND FIRED APPROX 8-9 ROUNDS AT VICT WHO WAS SEATED AT UPSTAIRS BALCONY SUSPS FLED LOC IN A NEWER 4DR GOLD SEDAN EB 37TH | 1 | 1 | 1 | 1.0000000 |
30685 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO–S ONE PRODUCED KNIFE AND FIGHT OCCURRED S TWO THEN CAME TO STORE AND ADW STABBING OCCURRED KNIFE IS BRASS KNUCKLE HOOKED BLADE PACAS GANG MEMBER | 1 | 1 | 1 | 1.0000000 |
5634 | CHILD ABUSE (PHYSICAL) - AGGRAVATED ASSAULT | DO-VICT WAS BROUGHT TO HOSPITAL WITH A HEAD TRAUMA V WAS ALSO DIAGNOSED W RETINAL HEMORRHAGES VICT IS IN CRITICAL CONDITION | 1 | 1 | 1 | 1.0000000 |
17517 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP AND VICT INVOLVED IN DISPUTE OVER CABINETS IN GARAGE SUSP BECAME ENRAGED AND HIT VICT W LG STICK AND HAMMER IN THE RIB CAGE | 1 | 1 | 1 | 1.0000000 |
31224 | CHILD ABUSE (PHYSICAL) - AGGRAVATED ASSAULT | DO-VICT DISCLOSED THAT SUSP HIT HIM WITH A BELT OR A WIRE WHICH HE DESCRIBES AS A POWER CORD | 1 | 1 | 1 | 1.0000000 |
15140 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-UNK SUSPS ATTEMPTED TO ROBB A TACO TRUCK SUSP FIRED ONE ROUND STRIKING VICT SUSPS THEN FLED ON FOOT NORTHBOUND MCKINLEY FROM VERNON AVE | 1 | 1 | 1 | 1.0000000 |
11504 | INTIMATE PARTNER - AGGRAVATED ASSAULT | DO- SUSP GOT ANGRY AT VICT SUSP BACKHANDED BICT TWICE IN THE FACE SUSP STRUCK VICT WITH SOUVERNIR BASEBALL BAT SUSP CHOKED VICT BCIT FLED LOC | 1 | 1 | 1 | 1.0000000 |
12428 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 FIRED TWO ROUNDS FROM A 9MM SEMI AUTOMATIC HANDGUN AT V1 V1 WAS WOUNDED IN BOTH ANKLES S1 FLED SOUTHBOUND FIGUEROA BL VIA VEH | 1 | 1 | 1 | 1.0000000 |
11884 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 FIRED TWO ROUNDS FROM A 9MM SEMI AUTOMATIC HANDGUN AT V1 V1 WAS WOUNDED IN BOTH ANKLES S1 FLED SOUTHBOUND FIGUEROA BL VIA VEH | 1 | 1 | 1 | 1.0000000 |
15647 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-VICT AND SUSP BECAME INVOLVED IN A VERBAL ARGUEMENT S PRODUCE BAT AND STRUCK V1 AND V2 SUSP FLED LOCATION PER V S1 & S2 ARE SUR13 G/M’S W/GANG TT’S | 1 | 1 | 1 | 0.9999999 |
12625 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-VICT AND SUSP BECAME INVOLVED IN A VERBAL ARGUEMENT S PRODUCE BAT AND STRUCK V1 AND V2 SUSP FLED LOCATION PER V S1 & S2 ARE SUR13 G/M’S W/GANG TT’S | 1 | 1 | 1 | 0.9999999 |
8854 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-UNK S IN A BLK SUV PULLED TO THE LEFT OF THE V AND FRNT PSGR PULLED OUTA HANDGUN AND SHOT V ONCE HITTING HIM IN THE ARM SUSPS THEN FLED LOC | 1 | 1 | 1 | 0.9999999 |
10000 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-V CONFRONTED S BELIEVING S BURGLARIZED VS RESIDENCE PREVIOUS DAY S AND V FIGHT S STABBED V ONCE IN THE BACK AND FLED INTO APT COMPLEX BKG 3093566 | 1 | 1 | 1 | 0.9999999 |
31316 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP BRANDISHED AND THREATENED VICT WITH EYEBROW RAZOR STATING IM GOING TO CUT YOU USING A STRIKING MOTION AT VICT | 1 | 1 | 1 | 0.9999999 |
11684 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-S1 PUSHED V1 AND THEN SWUNG A KNIFE AT THE V1 IN A SLICING MOTION CAUSIA CUT APPROX 2 INCHES ON THE LEFT SIDE OF V1 NECK | 1 | 1 | 1 | 0.9999999 |
30790 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-DEFT SWUNG SHOVEL MUL TIMES AT VICT AND NARROWLY MISSED VICT HEAD S THRTO KILL VICT SUSP IS 5 TREY AVALON CRIP | 1 | 1 | 1 | 0.9999998 |
7521 | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT | DO-SUSP POINTED UNK CALIBER SEMIAUTO HANDGUN AT VICT STATING MOTHERFUCKER CUAISNG VICT TO RUN AWAY SUSP FLED ON FOOT | 1 | 1 | 1 | 0.9999997 |
Using this technique we can easily expand out net to handle as many cases as we feel we can process, without the arbitrary boundary of an algorithm scoring a 0
or 1
.