-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_EXPORT_POS.ipynb copy
1255 lines (1255 loc) · 189 KB
/
_EXPORT_POS.ipynb copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data & Lib"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.metrics import accuracy_score\n",
"from sklearn.metrics import classification_report\n",
"from sklearn.metrics import f1_score, precision_score, recall_score\n",
"from transformers import AdamW, get_linear_schedule_with_warmup\n",
"\n",
"import emoji, re\n",
"from fetchData import fetchdata, cv_events\n",
"import __MLP\n",
"# from __MLP import getSamplers, convert_df_to_unsqueezed_tensor, train_sequential, clf_report\n",
"import random\n",
"\n",
"import os\n",
"import re\n",
"from tqdm import tqdm\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from sklearn.svm import SVC\n",
"from sklearn.svm import LinearSVC\n",
"\n",
"\n",
"from sklearn.model_selection import cross_val_score\n",
"from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score\n",
"from sklearn.metrics import classification_report\n",
"\n",
"from sklearn.naive_bayes import GaussianNB\n",
"\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.ensemble import AdaBoostClassifier\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import RandomizedSearchCV, GridSearchCV\n",
"from sklearn.ensemble import GradientBoostingClassifier\n",
"\n",
"pd.set_option('display.max_columns', None)\n",
"pd.set_option('display.max_rows', 150)\n",
"pd.set_option('display.max_colwidth', 150)"
]
},
{
"cell_type": "code",
"execution_count": 127,
"metadata": {},
"outputs": [],
"source": [
"# ext_sparse_processed = pd.read_csv('./data/tagged/_PHEMEext_textonly_token.csv')\n",
"pheme_textonly= pd.read_csv('./data/tagged/_PHEME_textonly.csv',sep='\\t')\n",
"pheme_text= pd.read_csv('./data/_PHEME_text.csv')\n",
"pheme_extonly= pd.read_csv('./data/_PHEMEext_textonly.csv',sep='\\t')\n",
"pheme_pos= pd.read_csv('./data/tagged/_PHEME_textonly_token.csv',sep='\\t')\n",
"ext_pos= pd.read_csv('./data/tagged/_PHEMEext_textonly_token2.csv',sep='\\t')\n",
"pheme_sparse= pd.read_csv('./data/_PHEME_sparse.csv')\n",
"ext_sparse= pd.read_csv('./data/_PHEMEext_sparse.csv')\n",
" \n",
"pheme_pos_final= pd.read_csv('./data/tagged/_PHEME_pos_final.csv',sep='\\t')\n",
"ext_pos_final= pd.read_csv('./data/tagged/_PHEMEext_pos_final.csv',sep='\\t')\n",
"\n",
"pheme_y= fetchdata('pheme','target').target\n",
"ext_y= fetchdata('ext','target').target\n",
"\n",
"pheme_text = fetchdata('pheme','text')"
]
},
{
"cell_type": "code",
"execution_count": 214,
"metadata": {},
"outputs": [],
"source": [
"phemeall = pd.read_csv('./data/all/_PHEMEall_text.csv').text\n",
"phemeall.to_csv('./data/all/_PHEMEall_text.csv',index=False)\n",
"extall = pd.read_csv('./data/all/_PHEMEextall_text.csv').text\n",
"extall.to_csv('./data/all/_PHEMEextall_text.csv',index=False)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"pheme_sparse_pos = pheme_sparse[['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs']]\n",
"ext_sparse_pos = ext_sparse[['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs']]\n",
"pheme_sparse_pos_pronouns = pheme_sparse[['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs', 'FirstPersonPronoun',\n",
" 'SecondPersonPronoun', 'ThirdPersonPronoun']]\n",
"ext_sparse_pos_pronouns = ext_sparse[['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs', 'FirstPersonPronoun',\n",
" 'SecondPersonPronoun', 'ThirdPersonPronoun']]\n",
"pheme_sparse_pronouns = pheme_sparse[['FirstPersonPronoun',\n",
" 'SecondPersonPronoun', 'ThirdPersonPronoun']]\n",
"ext_sparse_pronouns = ext_sparse[['FirstPersonPronoun',\n",
" 'SecondPersonPronoun', 'ThirdPersonPronoun']]\n",
"pheme_sparse_nopos = pheme_sparse.drop(['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs'], axis=1)\n",
"ext_sparse_nopos = ext_sparse.drop(['Noun', 'Verb', 'Adjective', 'Pronoun', 'Adverb', 'Numeral',\n",
" 'Conjunction_inj', 'Particle', 'Determiner', 'Modal', 'Whs'],axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PHEME ALL"
]
},
{
"cell_type": "code",
"execution_count": 236,
"metadata": {},
"outputs": [],
"source": [
"extall_POS = pd.read_csv('/Users/june/Documents/Code/FYP/TweetNLP/temp_result.csv',sep='\\n')\n",
"extall_POS2 = pd.read_csv('/Users/june/Documents/Code/FYP/TweetNLP/temp_result.txt',sep='\\t')"
]
},
{
"cell_type": "code",
"execution_count": 237,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1963,)\n",
"(2140, 1)\n"
]
},
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>text\\tN\\t0.7899\\ttext</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>@Mourinholic 😕😕 http://t.co/sFoV1v8uDo\\t@ G U\\t0.9992 0.2120 0.9967\\t@Mourinholic 😕😕 http://t.co/sFoV1v8uDo</td>\n </tr>\n <tr>\n <th>1</th>\n <td>“ @Mourinholic : Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS ”\\t, @ ~ ^ ^ V D ^ N P U ,\\t0.9421 0.9968 0.9910 0.9994 0.9...</td>\n </tr>\n <tr>\n <th>2</th>\n <td>@Mourinholic Hmmm .\\t@ ! ,\\t0.9990 0.9982 0.9969\\t@Mourinholic Hmmm.</td>\n </tr>\n <tr>\n <th>3</th>\n <td>@Mourinholic Even though it was against us , it was a bloody amazing goal . \\t, @ R P O V P O , O V D A A N , ,\\t0.9203 0.9983 0.9970 0.9575 0.99...</td>\n </tr>\n <tr>\n <th>4</th>\n <td>@CdtChoco1er thanks bro .\\t@ N N ,\\t0.9985 0.9199 0.9924 0.9988\\t@CdtChoco1er thanks bro.</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " text\\tN\\t0.7899\\ttext\n0 @Mourinholic 😕😕 http://t.co/sFoV1v8uDo\\t@ G U\\t0.9992 0.2120 0.9967\\t@Mourinholic 😕😕 http://t.co/sFoV1v8uDo\n1 “ @Mourinholic : Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS ”\\t, @ ~ ^ ^ V D ^ N P U ,\\t0.9421 0.9968 0.9910 0.9994 0.9...\n2 @Mourinholic Hmmm .\\t@ ! ,\\t0.9990 0.9982 0.9969\\t@Mourinholic Hmmm.\n3 @Mourinholic Even though it was against us , it was a bloody amazing goal . \\t, @ R P O V P O , O V D A A N , ,\\t0.9203 0.9983 0.9970 0.9575 0.99...\n4 @CdtChoco1er thanks bro .\\t@ N N ,\\t0.9985 0.9199 0.9924 0.9988\\t@CdtChoco1er thanks bro."
},
"execution_count": 237,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(extall.shape)\n",
"print(extall_POS.shape)\n",
"extall_POS.head()"
]
},
{
"cell_type": "code",
"execution_count": 235,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1963,)\n",
"(2184, 4)\n"
]
},
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>text</th>\n <th>N</th>\n <th>0.7899</th>\n <th>text.1</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>@Mourinholic 😕😕 http://t.co/sFoV1v8uDo</td>\n <td>@ G U</td>\n <td>0.9992 0.2120 0.9967</td>\n <td>@Mourinholic 😕😕 http://t.co/sFoV1v8uDo</td>\n </tr>\n <tr>\n <th>1</th>\n <td>“ @Mourinholic : Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS ”</td>\n <td>, @ ~ ^ ^ V D ^ N P U ,</td>\n <td>0.9421 0.9968 0.9910 0.9994 0.9937 0.9997 0.9993 0.8274 0.8219 0.9100 0.9868 0.9449</td>\n <td>“@Mourinholic: Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS”</td>\n </tr>\n <tr>\n <th>2</th>\n <td>@Mourinholic Hmmm .</td>\n <td>@ ! ,</td>\n <td>0.9990 0.9982 0.9969</td>\n <td>@Mourinholic Hmmm.</td>\n </tr>\n <tr>\n <th>3</th>\n <td>@Mourinholic Even though it was against us , it was a bloody amazing goal .</td>\n <td>, @ R P O V P O , O V D A A N , ,</td>\n <td>0.9203 0.9983 0.9970 0.9575 0.9987 0.9995 0.9853 0.9344 0.9977 0.9971 0.9997 0.9988 0.8880 0.9957 0.9986 0.9989 0.9709</td>\n <td>@Mourinholic Even though it was against us, it was a bloody amazing goal.</td>\n </tr>\n <tr>\n <th>4</th>\n <td>@CdtChoco1er thanks bro .</td>\n <td>@ N N ,</td>\n <td>0.9985 0.9199 0.9924 0.9988</td>\n <td>@CdtChoco1er thanks bro.</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " text \\\n0 @Mourinholic 😕😕 http://t.co/sFoV1v8uDo \n1 “ @Mourinholic : Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS ” \n2 @Mourinholic Hmmm . \n3 @Mourinholic Even though it was against us , it was a bloody amazing goal . \n4 @CdtChoco1er thanks bro . \n\n N \\\n0 @ G U \n1 , @ ~ ^ ^ V D ^ N P U , \n2 @ ! , \n3 , @ R P O V P O , O V D A A N , , \n4 @ N N , \n\n 0.7899 \\\n0 0.9992 0.2120 0.9967 \n1 0.9421 0.9968 0.9910 0.9994 0.9937 0.9997 0.9993 0.8274 0.8219 0.9100 0.9868 0.9449 \n2 0.9990 0.9982 0.9969 \n3 0.9203 0.9983 0.9970 0.9575 0.9987 0.9995 0.9853 0.9344 0.9977 0.9971 0.9997 0.9988 0.8880 0.9957 0.9986 0.9989 0.9709 \n4 0.9985 0.9199 0.9924 0.9988 \n\n text.1 \n0 @Mourinholic 😕😕 http://t.co/sFoV1v8uDo \n1 “@Mourinholic: Micheal Essien denying the Ebola rumours like https://t.co/8Yo8iLgISS” \n2 @Mourinholic Hmmm. \n3 @Mourinholic Even though it was against us, it was a bloody amazing goal. \n4 @CdtChoco1er thanks bro. "
},
"execution_count": 235,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(extall.shape)\n",
"print(extall_POS2.shape)\n",
"extall_POS2.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Check"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(5802, 1)\n",
"(485, 1)\n"
]
}
],
"source": [
"print(pheme_textonly.shape); print(pheme_extonly.shape)"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>processed_text</th>\n <th>POStags</th>\n <th>proba</th>\n <th>original_text</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>BREAKING : Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt</td>\n <td>N , A N V N P A N N P ^ U</td>\n <td>0.6086 0.9832 0.4822 0.9973 0.9819 0.9780 0.9852 0.9810 0.9235 0.5818 0.9989 0.9989 0.9981</td>\n <td>BREAKING: Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt ...</td>\n </tr>\n <tr>\n <th>1</th>\n <td>#CharlieHebdo killers dead , confirmed by gendarmerie .</td>\n <td># N A , V P ^ ,</td>\n <td>0.7572 0.5413 0.7980 0.9988 0.9810 0.9893 0.7627 0.9939</td>\n <td>#CharlieHebdo killers dead, confirmed by gendarmerie. ...</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Top French cartoonists Charb , Cabu , Wolinski , Tignous confirmed among dead in #Paris #CharlieHebdo attack . Editor is critically wounded .</td>\n <td>A ^ N V , ^ , ^ , ^ V P A P ^ ^ N , N V R A ,</td>\n <td>0.9429 0.5236 0.9900 0.3360 0.9967 0.8644 0.9948 0.9043 0.9948 0.6443 0.9759 0.9830 0.8947 0.9914 0.6474 0.8114 0.5487 0.9977 0.9616 0.9952 0.9975...</td>\n <td>Top French cartoonists Charb, Cabu, Wolinski, Tignous confirmed among dead in #Paris #CharlieHebdo attack. Editor is critically wounded. ...</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be : http://t.co/3tGXEIX4F2 https://t.co/aBSezf2QWS</td>\n <td>^ V V D N R D ^ V V V V P V , U U</td>\n <td>0.5557 0.9941 0.9846 0.9993 0.8847 0.9220 0.9868 0.9265 0.8443 0.8949 0.9825 0.9309 0.9817 0.9960 0.9067 0.9947 0.9977</td>\n <td>Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be: http://t.co/3tGXEIX4F2 https://t.co/aBSezf2QWS ...</td>\n </tr>\n <tr>\n <th>4</th>\n <td>PHOTO : Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0</td>\n <td>N , A N N N N P ^ ^ P ^ U U</td>\n <td>0.9901 0.9859 0.6329 0.9879 0.9015 0.6475 0.7908 0.9858 0.8528 0.9006 0.9963 0.9977 0.9955 0.9994</td>\n <td>PHOTO: Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0 ...</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " processed_text \\\n0 BREAKING : Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt \n1 #CharlieHebdo killers dead , confirmed by gendarmerie . \n2 Top French cartoonists Charb , Cabu , Wolinski , Tignous confirmed among dead in #Paris #CharlieHebdo attack . Editor is critically wounded . \n3 Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be : http://t.co/3tGXEIX4F2 https://t.co/aBSezf2QWS \n4 PHOTO : Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0 \n\n POStags \\\n0 N , A N V N P A N N P ^ U \n1 # N A , V P ^ , \n2 A ^ N V , ^ , ^ , ^ V P A P ^ ^ N , N V R A , \n3 ^ V V D N R D ^ V V V V P V , U U \n4 N , A N N N N P ^ ^ P ^ U U \n\n proba \\\n0 0.6086 0.9832 0.4822 0.9973 0.9819 0.9780 0.9852 0.9810 0.9235 0.5818 0.9989 0.9989 0.9981 \n1 0.7572 0.5413 0.7980 0.9988 0.9810 0.9893 0.7627 0.9939 \n2 0.9429 0.5236 0.9900 0.3360 0.9967 0.8644 0.9948 0.9043 0.9948 0.6443 0.9759 0.9830 0.8947 0.9914 0.6474 0.8114 0.5487 0.9977 0.9616 0.9952 0.9975... \n3 0.5557 0.9941 0.9846 0.9993 0.8847 0.9220 0.9868 0.9265 0.8443 0.8949 0.9825 0.9309 0.9817 0.9960 0.9067 0.9947 0.9977 \n4 0.9901 0.9859 0.6329 0.9879 0.9015 0.6475 0.7908 0.9858 0.8528 0.9006 0.9963 0.9977 0.9955 0.9994 \n\n original_text \n0 BREAKING: Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt ... \n1 #CharlieHebdo killers dead, confirmed by gendarmerie. ... \n2 Top French cartoonists Charb, Cabu, Wolinski, Tignous confirmed among dead in #Paris #CharlieHebdo attack. Editor is critically wounded. ... \n3 Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be: http://t.co/3tGXEIX4F2 https://t.co/aBSezf2QWS ... \n4 PHOTO: Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0 ... "
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pheme_pos_final.head()"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>processed_text</th>\n <th>POStags</th>\n <th>proba</th>\n <th>original_text</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Micheal Essien denying the Ebola rumours like https://t.co/H2E1TAzeha</td>\n <td>^ ^ V D ^ N P U</td>\n <td>0.9987 0.9934 0.9997 0.9994 0.8274 0.8091 0.9177 0.9935</td>\n <td>Micheal Essien denying the Ebola rumours like https://t.co/H2E1TAzeha</td>\n </tr>\n <tr>\n <th>1</th>\n <td>No truth in internet rumours that I have contracted Ebola . i m very well & I'm doing very gud & will be training as usual tomorrow . #falsenews</td>\n <td>D N P N N P O V V ^ , O V R R & L V R A & V V N P A N , #</td>\n <td>0.8772 0.9968 0.9936 0.9153 0.9477 0.9752 0.9995 0.9998 0.9695 0.7780 0.9965 0.9333 0.9256 0.9917 0.5153 0.9895 0.9959 0.9939 0.9895 0.9981 0.9942...</td>\n <td>No truth in internet rumours that I have contracted Ebola.i m very well &amp; I'm doing very gud &amp; will be training as usual tomorrow.#falsenews</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Essien and his lawyers are considering to file a lawsuit against the Nigerian media that reported the fake Ebola story .</td>\n <td>^ & D N V V P V D N P D ^ N P V D A ^ N ,</td>\n <td>0.9064 0.9984 0.9978 0.9972 0.9944 0.9660 0.9899 0.9900 0.9966 0.9953 0.9998 0.9985 0.8974 0.8566 0.8431 0.9956 0.9996 0.9763 0.6529 0.9933 0.9978</td>\n <td>Essien and his lawyers are considering to file a lawsuit against the Nigerian media that reported the fake Ebola story.</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Good news : The rumours that Michael Essien has contracted the Ebola virus are false . http://t.co/5d7hCL46mR http://t.co/VtGuLnjWBD</td>\n <td>A N , D N P ^ ^ V V D ^ N V A , U U</td>\n <td>0.9648 0.9985 0.7902 0.9930 0.9866 0.8974 0.9996 0.9949 0.9966 0.9981 0.9993 0.9321 0.9860 0.9878 0.9896 0.9979 0.9954 0.9986</td>\n <td>Good news: The rumours that Michael Essien has contracted the Ebola virus are false. http://t.co/5d7hCL46mR http://t.co/VtGuLnjWBD</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Milan have stated that the reports about Essien having Ebola are completely false . http://t.co/Sb9v9ulfTX @MichaelEssien</td>\n <td>^ V V P D N P ^ V ^ V R A , U @</td>\n <td>0.9883 0.9935 0.9839 0.8956 0.9968 0.9879 0.9860 0.9582 0.9981 0.7131 0.9523 0.9994 0.9815 0.9984 0.9959 0.9964</td>\n <td>Milan have stated that the reports about Essien having Ebola are completely false. http://t.co/Sb9v9ulfTX @MichaelEssien</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " processed_text \\\n0 Micheal Essien denying the Ebola rumours like https://t.co/H2E1TAzeha \n1 No truth in internet rumours that I have contracted Ebola . i m very well & I'm doing very gud & will be training as usual tomorrow . #falsenews \n2 Essien and his lawyers are considering to file a lawsuit against the Nigerian media that reported the fake Ebola story . \n3 Good news : The rumours that Michael Essien has contracted the Ebola virus are false . http://t.co/5d7hCL46mR http://t.co/VtGuLnjWBD \n4 Milan have stated that the reports about Essien having Ebola are completely false . http://t.co/Sb9v9ulfTX @MichaelEssien \n\n POStags \\\n0 ^ ^ V D ^ N P U \n1 D N P N N P O V V ^ , O V R R & L V R A & V V N P A N , # \n2 ^ & D N V V P V D N P D ^ N P V D A ^ N , \n3 A N , D N P ^ ^ V V D ^ N V A , U U \n4 ^ V V P D N P ^ V ^ V R A , U @ \n\n proba \\\n0 0.9987 0.9934 0.9997 0.9994 0.8274 0.8091 0.9177 0.9935 \n1 0.8772 0.9968 0.9936 0.9153 0.9477 0.9752 0.9995 0.9998 0.9695 0.7780 0.9965 0.9333 0.9256 0.9917 0.5153 0.9895 0.9959 0.9939 0.9895 0.9981 0.9942... \n2 0.9064 0.9984 0.9978 0.9972 0.9944 0.9660 0.9899 0.9900 0.9966 0.9953 0.9998 0.9985 0.8974 0.8566 0.8431 0.9956 0.9996 0.9763 0.6529 0.9933 0.9978 \n3 0.9648 0.9985 0.7902 0.9930 0.9866 0.8974 0.9996 0.9949 0.9966 0.9981 0.9993 0.9321 0.9860 0.9878 0.9896 0.9979 0.9954 0.9986 \n4 0.9883 0.9935 0.9839 0.8956 0.9968 0.9879 0.9860 0.9582 0.9981 0.7131 0.9523 0.9994 0.9815 0.9984 0.9959 0.9964 \n\n original_text \n0 Micheal Essien denying the Ebola rumours like https://t.co/H2E1TAzeha \n1 No truth in internet rumours that I have contracted Ebola.i m very well & I'm doing very gud & will be training as usual tomorrow.#falsenews \n2 Essien and his lawyers are considering to file a lawsuit against the Nigerian media that reported the fake Ebola story. \n3 Good news: The rumours that Michael Essien has contracted the Ebola virus are false. http://t.co/5d7hCL46mR http://t.co/VtGuLnjWBD \n4 Milan have stated that the reports about Essien having Ebola are completely false. http://t.co/Sb9v9ulfTX @MichaelEssien "
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ext_pos_final.head()"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"def text_preprocessing_simple(text, lemma=False, twttknzr=True): # Create a function to tokenize a set of texts\n",
"\n",
" \"\"\"\n",
" - Remove entity mentions (eg. '@united')\n",
" - Correct errors (eg. '&' to '&')\n",
" @param text (str): a string to be processed.\n",
" @return text (Str): the processed string.\n",
" \"\"\"\n",
"\n",
" # text = re.sub(r\"http\\S+\", \"*\", text) # http link -> '*'\n",
" # sent = re.sub(r'([^\\s\\w@#\\*]|_)+', '', sent) # Erasing Special Characters\n",
"\n",
" text = emoji.demojize(text)\n",
" text = re.sub(r':[^:\\s]*:', r' \\g<0>', text) # http link -> '*'\n",
"\n",
" # text = re.sub(r':[^:\\s]*(?:::[^:\\s]*)*:', r' \\g<0> ', text) # http link -> '*'\n",
"\n",
" # text = re.sub(r\"\\n\", \" \", text) # mention -> '@'\n",
" text = re.sub(r\"http\\S+\", \"HTTPURL\", text) # http link -> '*'\n",
" # text = re.sub(r\"@\\S+\", \"@USER\", text) # mention -> '@'\n",
" \n",
" text = re.sub(r\"@[A-Za-z0-9]+\", \"@USER\", text) # mention -> '@'\n",
"\n",
" # Remove trailing whitespace\n",
" text = re.sub(r'\\s+', ' ', text).strip()\n",
" text = re.sub(r'&', '&', text)\n",
" # text = tweetTokenizer.tokenize(text)\n",
" # text = [emoji.demojize(token) for token in text]\n",
"\n",
" return text\n",
"\n",
"def text_preprocessing_pos(text, lemma=False, twttknzr=False): # Create a function to tokenize a set of texts\n",
"\n",
" \"\"\"\n",
" - Remove entity mentions (eg. '@united')\n",
" - Correct errors (eg. '&' to '&')\n",
" @param text (str): a string to be processed.\n",
" @return text (Str): the processed string.\n",
" \"\"\"\n",
"\n",
" # text = re.sub(r\"http\\S+\", \"*\", text) # http link -> '*'\n",
" # sent = re.sub(r'([^\\s\\w@#\\*]|_)+', '', sent) # Erasing Special Characters\n",
"\n",
" text = emoji.demojize(text)\n",
" text = re.sub(r':[^:\\s]*:', r' \\g<0>', text) # http link -> '*'\n",
"\n",
" # text = re.sub(r':[^:\\s]*(?:::[^:\\s]*)*:', r' \\g<0> ', text) # http link -> '*'\n",
"\n",
" # text = re.sub(r\"\\n\", \" \", text) # mention -> '@'\n",
" text = re.sub(r\"http\\S+\", \"HTTPURL\", text) # http link -> '*'\n",
" # text = re.sub(r\"@\\S+\", \"@USER\", text) # mention -> '@'\n",
" \n",
" text = re.sub(r\"@[A-Za-z0-9]+\", \"@USER\", text) # mention -> '@'\n",
"\n",
" # Remove trailing whitespace\n",
" text = re.sub(r'\\s+', ' ', text).strip()\n",
" text = re.sub(r'&', '&', text)\n",
" # text = tweetTokenizer.tokenize(text)\n",
" # text = [emoji.demojize(token) for token in text]\n",
"\n",
" return text"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
"result = [text_preprocessing_pos(sent) for sent in pheme_textonly.text]"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['I@@', \"'m\", 'very', 'fit', 'and', 'very', 'health@@', 'y@@', ',@@', 'No', 'truth', 'in', 'the', 'internet', 'rumours', 'that', 'I', 'have', 'contracted', 'E@@', 'bol@@', 'a.@@', 'im', 'well', '&@@', '…', 'HTTPURL']\n"
]
}
],
"source": [
"print(tokenizer.tokenize(text_preprocessing_simple(pheme_extonly.iloc[5][0])))"
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm very fit and very healthy,No truth in the internet rumours that I have contracted Ebola.im well &… http://t.co/TGidyI5JVG\n",
"I'm very fit and very healthy , No truth in the internet rumours that I have contracted Ebola.im well & … http://t.co/TGidyI5JVG\n",
"L R V & R A , D N P D N N P O V V U R & , U\n",
"I'm very fit and very healthy,No truth in the internet rumours that I have contracted Ebola.im well &… HTTPURL\n"
]
}
],
"source": [
"print(pheme_extonly.iloc[5][0])\n",
"print(ext_pos_final.iloc[5][0])\n",
"print(ext_pos_final.iloc[5][1])\n",
"print(text_preprocessing_simple(pheme_extonly.iloc[5][0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Processing"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.feature_extraction.text import CountVectorizer\n",
"from sklearn.feature_extraction.text import TfidfVectorizer"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"pheme_pos_final= pd.read_csv('./data/tagged/_PHEME_pos_final.csv',sep='\\t')\n",
"\n",
"# pheme_pos_final.iloc[1304].processed_text=\"' We are all Charlie ” : European newspapers show solidarity with Charlie Hebdo after attack http://t.co/xq1OQhDJVF http://t.co/jt7D6fuIBH\"\n",
"# pheme_pos_final.iloc[1304].POStags=\", O V D ^ , , A N V N P ^ ^ P N U U\"\n",
"# pheme_pos_final.iloc[1304].proba=\"0.9905 0.9951 0.9998 0.8048 0.9974 0.9494 0.9120 0.9475 0.9980 0.5189 0.9962 0.9990 0.9996 0.9758 0.8693 0.7830 0.9949 0.9991\"\n",
"# pheme_pos_final.iloc[1304].original_text=\"We are all Charlie”: European newspapers show solidarity with Charlie Hebdo after attack http://t.co/xq1OQhDJVF http://t.co/jt7D6fuIBH\""
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty DataFrame\n",
"Columns: [processed_text, POStags, proba, original_text]\n",
"Index: []\n"
]
}
],
"source": [
"print(pheme_pos_final.loc[pheme_pos_final.POStags.isna() == True])\n",
"# print(pheme_pos_final.iloc[1304])\n",
"# print(pheme_pos_final.iloc[1305].processed_text)"
]
},
{
"cell_type": "code",
"execution_count": 191,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'n': 13, ' ': 0, ',': 5, 'a': 8, 'v': 20, 'p': 15, '^': 7, 'u': 19, '#': 2, 'r': 16, 'd': 9, '$': 3, 's': 17, 'o': 14, '&': 4, 'l': 12, '@': 6, 't': 18, '~': 23, '!': 1, 'g': 11, 'z': 22, 'x': 21, 'e': 10}\n"
]
}
],
"source": [
"pheme_POS = [sent for sent in pheme_pos_final['POStags'].values]\n",
"ext_POS = [sent for sent in ext_pos_final['POStags'].values]\n",
"\n",
"# vector = CountVectorizer(analyzer='char_wb')\n",
"vector = CountVectorizer(analyzer='char')\n",
"train = vector.fit_transform(pheme_POS)\n",
"test = vector.transform(ext_POS)\n",
"print(vector.vocabulary_) # 각 단어의 인덱스가 어떻게 부여되었는지를 보여준다.\n",
"# print(vector.transform(pheme_POS).toarray()) # 코퍼스로부터 각 단어의 빈도 수를 기록한다. \n",
"# pd.DataFrame(vector.fit_transform(POS).toarray())\n",
"countvect_train = pd.DataFrame(train.todense(), columns=vector.get_feature_names())\n",
"countvect_test = pd.DataFrame(test.todense(), columns=vector.get_feature_names())\n",
"countvect_train = countvect_train.iloc[:,1:].drop(['e','$'],axis=1)\n",
"countvect_test = countvect_test.iloc[:,1:].drop(['e','$'],axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Export"
]
},
{
"cell_type": "code",
"execution_count": 192,
"metadata": {},
"outputs": [],
"source": [
"countvect_train.to_csv(\"./data/_PHEME_postags\", index = False)\n",
"countvect_test.to_csv(\"./data/_PHEMEext_postags\",index = False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 데이터 비교"
]
},
{
"cell_type": "code",
"execution_count": 194,
"metadata": {},
"outputs": [],
"source": [
"train = pd.concat([countvect_train,pheme_sparse_pos,pheme_text, pheme_sparse_nopos],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_pos,ext_sparse_nopos],axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 201,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "Index(['!', '#', '&', ',', '@', '^', 'a', 'd', 'g', 'l', 'n', 'o', 'p', 'r',\n 's', 't', 'u', 'v', 'x', 'z', '~', 'Noun', 'Verb', 'Adjective',\n 'Pronoun', 'Adverb', 'Numeral', 'Conjunction_inj', 'Particle',\n 'Determiner', 'Modal', 'Whs', 'text', 'Event', 'target', 'emoji_count',\n 'URLcount', 'has_media', 'Skepticism', 'MentionCount',\n 'FirstPersonPronoun', 'SecondPersonPronoun', 'ThirdPersonPronoun',\n 'char_count', 'word_count', 'HashTag', 'has_question', 'has_exclaim',\n 'has_period', 'capital_ratio', 'retweet_count', 'isRT', 'tweet_count',\n 'listed_count', 'friends_count', 'follower_count', 'followers/friend',\n 'favourites_count', 'account_age_days', 'verified'],\n dtype='object')"
},
"execution_count": 201,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train.columns\n",
"\n",
"# ndex(['!', '#', '$', '&', ',', '@', '^', 'a', 'd', 'e', 'g', 'l', 'n', 'o',\n",
"# 'p', 'r', 's', 't', 'u', 'v', 'x', 'z', '~', 'Noun', 'Verb',\n",
"# 'Adjective', 'Pronoun', 'Adverb', 'Numeral', 'Conjunction_inj',\n",
"# 'Particle', 'Determiner', 'Modal', 'Whs', 'text', 'Event', 'target',\n",
"# 'emoji_count', 'URLcount', 'has_media', 'Skepticism', 'MentionCount',\n",
"# 'FirstPersonPronoun', 'SecondPersonPronoun', 'ThirdPersonPronoun',\n",
"# 'char_count', 'word_count', 'HashTag', 'has_question', 'has_exclaim',\n",
"# 'has_period', 'capital_ratio', 'retweet_count', 'isRT', 'tweet_count',\n",
"# 'listed_count', 'friends_count', 'follower_count', 'followers/friend',\n",
"# 'favourites_count', 'account_age_days', 'verified'],\n",
"# dtype='object')"
]
},
{
"cell_type": "code",
"execution_count": 238,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>text</th>\n <th>^</th>\n <th>v</th>\n <th>Verb</th>\n <th>n</th>\n <th>Noun</th>\n <th>o</th>\n <th>Pronoun</th>\n <th>a</th>\n <th>Adjective</th>\n <th>Adverb</th>\n <th>r</th>\n <th>#</th>\n <th>HashTag</th>\n <th>u</th>\n <th>URLcount</th>\n <th>@</th>\n <th>MentionCount</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>BREAKING: Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt</td>\n <td>1</td>\n <td>1</td>\n <td>3</td>\n <td>5</td>\n <td>6</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>#CharlieHebdo killers dead, confirmed by gendarmerie.</td>\n <td>1</td>\n <td>1</td>\n <td>2</td>\n <td>1</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Top French cartoonists Charb, Cabu, Wolinski, Tignous confirmed among dead in #Paris #CharlieHebdo attack. Editor is critically wounded.</td>\n <td>6</td>\n <td>3</td>\n <td>4</td>\n <td>3</td>\n <td>3</td>\n <td>0</td>\n <td>0</td>\n <td>3</td>\n <td>6</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be: http://t.co/3tGXEIX4F2\\nhttps://t.co/aBSezf2QWS</td>\n <td>2</td>\n <td>7</td>\n <td>5</td>\n <td>1</td>\n <td>4</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>4</th>\n <td>PHOTO: Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0</td>\n <td>3</td>\n <td>0</td>\n <td>2</td>\n <td>5</td>\n <td>6</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>5797</th>\n <td>'I'll ride with you' http://t.co/llZnuCAzg5 Australia unites during #SydneySiege http://t.co/WIU22VPgkz</td>\n <td>2</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>2</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5798</th>\n <td>Canada's thoughts and prayers are with our Australian friends. #MartinPlace #SydneySiege</td>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n <td>4</td>\n <td>0</td>\n <td>1</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5799</th>\n <td>Every non-muslim in the world must watch this video https://t.co/sZdyhISoVh &amp; show it every other non-muslim! #sydneysiege</td>\n <td>0</td>\n <td>3</td>\n <td>3</td>\n <td>2</td>\n <td>4</td>\n <td>1</td>\n <td>1</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>1</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5800</th>\n <td>Suspect in Sydney cafe siege identified as Man Haron Monis, an Iranian granted asylum in Australia http://t.co/6Lrl9DEMXA</td>\n <td>3</td>\n <td>1</td>\n <td>3</td>\n <td>6</td>\n <td>7</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5801</th>\n <td>Australians respond to racism by telling #Muslim community #illridewithyou. #sydneysiege #MartinPlace</td>\n <td>2</td>\n <td>2</td>\n <td>3</td>\n <td>3</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>4</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n </tbody>\n</table>\n<p>5802 rows × 18 columns</p>\n</div>",
"text/plain": " text \\\n0 BREAKING: Armed man takes hostage in kosher grocery east of Paris http://t.co/PBs3sMwhLt \n1 #CharlieHebdo killers dead, confirmed by gendarmerie. \n2 Top French cartoonists Charb, Cabu, Wolinski, Tignous confirmed among dead in #Paris #CharlieHebdo attack. Editor is critically wounded. \n3 Police have surrounded the area where the #CharlieHebdo attack suspects are believed to be: http://t.co/3tGXEIX4F2\\nhttps://t.co/aBSezf2QWS \n4 PHOTO: Armed gunmen face police officers near #CharlieHebdo HQ in Paris http://t.co/3Jsosc7yl3 http://t.co/iOpVNO6Iq0 \n... ... \n5797 'I'll ride with you' http://t.co/llZnuCAzg5 Australia unites during #SydneySiege http://t.co/WIU22VPgkz \n5798 Canada's thoughts and prayers are with our Australian friends. #MartinPlace #SydneySiege \n5799 Every non-muslim in the world must watch this video https://t.co/sZdyhISoVh & show it every other non-muslim! #sydneysiege \n5800 Suspect in Sydney cafe siege identified as Man Haron Monis, an Iranian granted asylum in Australia http://t.co/6Lrl9DEMXA \n5801 Australians respond to racism by telling #Muslim community #illridewithyou. #sydneysiege #MartinPlace \n\n ^ v Verb n Noun o Pronoun a Adjective Adverb r # HashTag u \\\n0 1 1 3 5 6 0 0 2 0 0 0 0 0 1 \n1 1 1 2 1 2 0 0 1 0 0 0 1 1 0 \n2 6 3 4 3 3 0 0 3 6 1 1 0 2 0 \n3 2 7 5 1 4 0 0 0 0 0 1 0 1 2 \n4 3 0 2 5 6 0 0 1 0 0 0 0 1 2 \n... .. .. ... .. ... .. ... .. ... ... .. .. ... .. \n5797 2 2 2 0 2 1 1 0 0 0 0 0 1 2 \n5798 0 1 2 3 4 0 1 1 1 0 0 2 2 0 \n5799 0 3 3 2 4 1 1 3 1 0 0 1 1 1 \n5800 3 1 3 6 7 0 0 2 2 0 0 0 0 1 \n5801 2 2 3 3 2 0 0 0 0 0 0 2 4 0 \n\n URLcount @ MentionCount \n0 1 0 0 \n1 0 0 0 \n2 0 0 0 \n3 2 0 0 \n4 2 0 0 \n... ... .. ... \n5797 2 0 0 \n5798 0 0 0 \n5799 1 0 0 \n5800 1 0 0 \n5801 0 0 0 \n\n[5802 rows x 18 columns]"
},
"execution_count": 238,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train.describe()\n",
"train[['text','^','v','Verb','n','Noun', 'o','Pronoun','a','Adjective','Adverb','r', '#', 'HashTag','u','URLcount','@','MentionCount']]"
]
},
{
"cell_type": "code",
"execution_count": 239,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>text</th>\n <th>@</th>\n <th>MentionCount</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>462</th>\n <td>Brilliant #CharlieHebdo satirists did not attack #Islam, but poked fun @ #intolerance &amp; #extremism of all kind inc #racism &amp; #islamophobia.</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>471</th>\n <td>The shooting @ \"Charlie Hebdo\", in France, is a horrible tragedy. Ignorance, hatred and cowardice has no religion, no political allegiance.</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>1044</th>\n <td>@FT's Tony Barber describes #CharlieHebdo as \"editorially foolish\" and \"stupid\" http://t.co/dFan6rptkM http://t.co/cmiaUNA0eO</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>2104</th>\n <td>Police have named the cop who shot Michael Brown. @alicesperi's latest report from #Ferguson: http://t.co/1K79nsOtx3 http://t.co/cV3VCkUR6L</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>2920</th>\n <td>This is sheer insanity. Just look at @sebwalker's photo from #Ferguson. http://t.co/6f8dNxWBeO</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>3840</th>\n <td>#RCMP news conference on #Ottawa shootings expected to begin momentarily. Watch live @ http://t.co/kngapKTSCe</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4035</th>\n <td>#RCMP to hold news conference on #Ottawa shootings at 2 pm ET, 11 am PT. Watch live coverage @ http://t.co/kngapKTSCe</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4199</th>\n <td>.@IvisonJ's first-hand account of the scene in Ottawa that will 'change this country forever' http://t.co/g5lhxHqNNs http://t.co/AP0stmObnn</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4363</th>\n <td>#RCMP asking for assistance if you have any photos or videos from #ottawa shooting send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4374</th>\n <td>#RCMP asking for assistance if you have any photos or videos from #ottawa shooting please send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4397</th>\n <td>#RCMP asking for assistance if you have any photos or videos from #ottawa shooting please send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4442</th>\n <td>The powerful War Memorial mouth-to-mouth image being shared is by @OttawaCitizen's Wayne Cuddington. #ottnews #ottawa http://t.co/FcSGb097G9</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4462</th>\n <td>If you have pictures or video of the suspect, email them NatDiv_Media_DivNat@rcmp-grc.gc.ca #ottawa #ottcity #ottnews</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4478</th>\n <td>Please forward any tips, photos or videos to NatDiv_Media_DivNat@rcmp-grc.gc.ca #OttawaShooting c: @RCMP_Nat_Div ^JT</td>\n <td>1</td>\n <td>2</td>\n </tr>\n <tr>\n <th>4567</th>\n <td>Ottawa youth: If you need to talk: 24/7 Crisis Line\\n613-260-2360 or 1-877-377-7775 (toll free for Eastern Ontario)\\ncrisis@ysb.on.ca</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4735</th>\n <td>#sydneysiege is a misnomer. It's a hostage situation. Inside a cafe. You want 2 know what being under siege looks like? look @ #Gaza.</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>5093</th>\n <td>Hostage situation in Sydney is happening next door to @7NewsSydney's studio -- this is a live stream of the coverage https://t.co/uNXkJmspr8</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>5470</th>\n <td>.@amcoren's report on what we know right now about the #sydneysiege: http://t.co/lkXAAgN5Rg</td>\n <td>0</td>\n <td>1</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " text \\\n462 Brilliant #CharlieHebdo satirists did not attack #Islam, but poked fun @ #intolerance & #extremism of all kind inc #racism & #islamophobia. \n471 The shooting @ \"Charlie Hebdo\", in France, is a horrible tragedy. Ignorance, hatred and cowardice has no religion, no political allegiance. \n1044 @FT's Tony Barber describes #CharlieHebdo as \"editorially foolish\" and \"stupid\" http://t.co/dFan6rptkM http://t.co/cmiaUNA0eO \n2104 Police have named the cop who shot Michael Brown. @alicesperi's latest report from #Ferguson: http://t.co/1K79nsOtx3 http://t.co/cV3VCkUR6L \n2920 This is sheer insanity. Just look at @sebwalker's photo from #Ferguson. http://t.co/6f8dNxWBeO \n3840 #RCMP news conference on #Ottawa shootings expected to begin momentarily. Watch live @ http://t.co/kngapKTSCe \n4035 #RCMP to hold news conference on #Ottawa shootings at 2 pm ET, 11 am PT. Watch live coverage @ http://t.co/kngapKTSCe \n4199 .@IvisonJ's first-hand account of the scene in Ottawa that will 'change this country forever' http://t.co/g5lhxHqNNs http://t.co/AP0stmObnn \n4363 #RCMP asking for assistance if you have any photos or videos from #ottawa shooting send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca \n4374 #RCMP asking for assistance if you have any photos or videos from #ottawa shooting please send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca \n4397 #RCMP asking for assistance if you have any photos or videos from #ottawa shooting please send to: NatDiv_Media_DivNat@rcmp-grc.gc.ca \n4442 The powerful War Memorial mouth-to-mouth image being shared is by @OttawaCitizen's Wayne Cuddington. #ottnews #ottawa http://t.co/FcSGb097G9 \n4462 If you have pictures or video of the suspect, email them NatDiv_Media_DivNat@rcmp-grc.gc.ca #ottawa #ottcity #ottnews \n4478 Please forward any tips, photos or videos to NatDiv_Media_DivNat@rcmp-grc.gc.ca #OttawaShooting c: @RCMP_Nat_Div ^JT \n4567 Ottawa youth: If you need to talk: 24/7 Crisis Line\\n613-260-2360 or 1-877-377-7775 (toll free for Eastern Ontario)\\ncrisis@ysb.on.ca \n4735 #sydneysiege is a misnomer. It's a hostage situation. Inside a cafe. You want 2 know what being under siege looks like? look @ #Gaza. \n5093 Hostage situation in Sydney is happening next door to @7NewsSydney's studio -- this is a live stream of the coverage https://t.co/uNXkJmspr8 \n5470 .@amcoren's report on what we know right now about the #sydneysiege: http://t.co/lkXAAgN5Rg \n\n @ MentionCount \n462 0 1 \n471 0 1 \n1044 0 1 \n2104 0 1 \n2920 0 1 \n3840 0 1 \n4035 0 1 \n4199 0 1 \n4363 0 1 \n4374 0 1 \n4397 0 1 \n4442 0 1 \n4462 0 1 \n4478 1 2 \n4567 0 1 \n4735 0 1 \n5093 0 1 \n5470 0 1 "
},
"execution_count": 239,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train.loc[train.MentionCount != train['@']][['text','@','MentionCount']]"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "0 5802\nName: isRT, dtype: int64"
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train.isRT.value_counts()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CLF - Root"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Trad"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"def train_test(X_train, X_test, y_train, y_test, clf):\n",
" clf.fit(X_train, y_train)\n",
" result = clf.predict(X_test)\n",
" print(\"Accuracy:\\t\\t\",accuracy_score(y_test,result))\n",
" print('Precision Score:\\t', str(precision_score(y_test,result)))\n",
" print('Recall Score:\\t\\t' + str(recall_score(y_test,result)))\n",
" print(\"F1 Score:\\t\\t\",f1_score(y_test, result, average='macro', zero_division=True))\n",
" print(classification_report(y_test, result))\n"
]
},
{
"cell_type": "code",
"execution_count": 337,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.naive_bayes import MultinomialNB\n",
"\n",
"tfidf_vectorizer = TfidfVectorizer(\n",
" max_features=5000, min_df=1, max_df=0.9, ngram_range=(1,2), analyzer='char')\n",
"train_pos = tfidf_vectorizer.fit_transform(pheme_POS)\n",
"test_pos = tfidf_vectorizer.transform(ext_POS)\n",
"\n",
"clf = MultinomialNB(alpha=0.1).fit(train_pos, pheme_y)\n",
"predicted = clf.predict(test_pos)\n"
]
},
{
"cell_type": "code",
"execution_count": 188,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.2556701030927835\n",
"Precision Score:\t 0.6428571428571429\n",
"Recall Score:\t\t0.04878048780487805\n",
"F1 Score:\t\t 0.23033132437434337\n",
" precision recall f1-score support\n",
"\n",
" 0 0.23 0.91 0.37 116\n",
" 1 0.64 0.05 0.09 369\n",
"\n",
" accuracy 0.26 485\n",
" macro avg 0.44 0.48 0.23 485\n",
"weighted avg 0.54 0.26 0.16 485\n",
"\n"
]
}
],
"source": [
"clf = SVC()\n",
"train_test(countvect_train[['$','v']], countvect_test[['$','v']], pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 183,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.2556701030927835\n",
"Precision Score:\t 0.7\n",
"Recall Score:\t\t0.037940379403794036\n",
"F1 Score:\t\t 0.2253184607692614\n",
" precision recall f1-score support\n",
"\n",
" 0 0.24 0.95 0.38 116\n",
" 1 0.70 0.04 0.07 369\n",
"\n",
" accuracy 0.26 485\n",
" macro avg 0.47 0.49 0.23 485\n",
"weighted avg 0.59 0.26 0.15 485\n",
"\n"
]
}
],
"source": [
"clf = SVC()\n",
"train_test(pheme_sparse_pos, ext_sparse_pos, pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 190,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.27422680412371137\n",
"Precision Score:\t 0.7575757575757576\n",
"Recall Score:\t\t0.06775067750677506\n",
"F1 Score:\t\t 0.25232989979679066\n",
" precision recall f1-score support\n",
"\n",
" 0 0.24 0.93 0.38 116\n",
" 1 0.76 0.07 0.12 369\n",
"\n",
" accuracy 0.27 485\n",
" macro avg 0.50 0.50 0.25 485\n",
"weighted avg 0.63 0.27 0.19 485\n",
"\n"
]
}
],
"source": [
"clf = SVC()\n",
"\n",
"train_test(pheme_sparse_pos_pronouns[['Numeral','Verb']], ext_sparse_pos_pronouns[['Numeral','Verb']], pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 448,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.23917525773195877\n",
"Precision Score:\t 0.0\n",
"Recall Score:\t\t0.0\n",
"F1 Score:\t\t 0.1930116472545757\n",
" precision recall f1-score support\n",
"\n",
" 0 0.24 1.00 0.39 116\n",
" 1 0.00 0.00 0.00 369\n",
"\n",
" accuracy 0.24 485\n",
" macro avg 0.12 0.50 0.19 485\n",
"weighted avg 0.06 0.24 0.09 485\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n"
]
}
],
"source": [
"clf = SVC()\n",
"train_test(pheme_sparse_pronouns, ext_sparse_pronouns, pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 444,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.23917525773195877\n",
"Precision Score:\t 0.0\n",
"Recall Score:\t\t0.0\n",
"F1 Score:\t\t 0.1930116472545757\n",
" precision recall f1-score support\n",
"\n",
" 0 0.24 1.00 0.39 116\n",
" 1 0.00 0.00 0.00 369\n",
"\n",
" accuracy 0.24 485\n",
" macro avg 0.12 0.50 0.19 485\n",
"weighted avg 0.06 0.24 0.09 485\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n",
"/Users/june/miniconda3/envs/rosetta/lib/python3.8/site-packages/sklearn/metrics/_classification.py:1245: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
" _warn_prf(average, modifier, msg_start, len(result))\n"
]
}
],
"source": [
"clf = SVC()\n",
"train_test(pheme_sparse_nopos, ext_sparse_nopos, pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 451,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Noun</th>\n <th>Verb</th>\n <th>Adjective</th>\n <th>Pronoun</th>\n <th>Adverb</th>\n <th>Numeral</th>\n <th>Conjunction_inj</th>\n <th>Particle</th>\n <th>Determiner</th>\n <th>Modal</th>\n <th>Whs</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>6</td>\n <td>3</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>4</td>\n <td>6</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>5</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>4</th>\n <td>6</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>5797</th>\n <td>2</td>\n <td>2</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5798</th>\n <td>4</td>\n <td>2</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5799</th>\n <td>4</td>\n <td>3</td>\n <td>1</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>4</td>\n <td>1</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5800</th>\n <td>7</td>\n <td>3</td>\n <td>2</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>3</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n </tr>\n <tr>\n <th>5801</th>\n <td>2</td>\n <td>3</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n </tr>\n </tbody>\n</table>\n<p>5802 rows × 11 columns</p>\n</div>",
"text/plain": " Noun Verb Adjective Pronoun Adverb Numeral Conjunction_inj \\\n0 6 3 0 0 0 0 2 \n1 2 2 0 0 0 0 1 \n2 3 4 6 0 1 0 2 \n3 4 5 0 0 0 0 0 \n4 6 2 0 0 0 0 2 \n... ... ... ... ... ... ... ... \n5797 2 2 0 1 0 0 2 \n5798 4 2 1 1 0 0 2 \n5799 4 3 1 1 0 0 1 \n5800 7 3 2 0 0 0 3 \n5801 2 3 0 0 0 0 1 \n\n Particle Determiner Modal Whs \n0 0 0 0 0 \n1 0 0 0 0 \n2 0 0 0 0 \n3 0 2 0 1 \n4 0 0 0 0 \n... ... ... ... ... \n5797 0 0 1 0 \n5798 0 0 0 0 \n5799 0 4 1 0 \n5800 0 1 0 0 \n5801 0 0 0 0 \n\n[5802 rows x 11 columns]"
},
"execution_count": 451,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pheme_sparse_pos"
]
},
{
"cell_type": "code",
"execution_count": 457,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.5752577319587628\n",
"Precision Score:\t 0.8075471698113208\n",
"Recall Score:\t\t0.5799457994579946\n",
"F1 Score:\t\t 0.5309918131290371\n",
" precision recall f1-score support\n",
"\n",
" 0 0.30 0.56 0.39 116\n",
" 1 0.81 0.58 0.68 369\n",
"\n",
" accuracy 0.58 485\n",
" macro avg 0.55 0.57 0.53 485\n",
"weighted avg 0.69 0.58 0.61 485\n",
"\n"
]
}
],
"source": [
"train = pd.concat([countvect_train,pheme_sparse_pronouns],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_pronouns],axis=1)\n",
"clf = GaussianNB()\n",
"train_test(train, test, pheme_y, ext_y, clf)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy:\t\t 0.24536082474226803\n",
"Precision Score:\t 0.6666666666666666\n",
"Recall Score:\t\t0.016260162601626018\n",
"F1 Score:\t\t 0.20675139425139424\n",
" precision recall f1-score support\n",
"\n",
" 0 0.24 0.97 0.38 116\n",
" 1 0.67 0.02 0.03 369\n",
"\n",
" accuracy 0.25 485\n",
" macro avg 0.45 0.50 0.21 485\n",
"weighted avg 0.56 0.25 0.12 485\n",
"\n"
]
}
],
"source": [
"# TweetNLP 결과 + 기존 PHEME POS tag의 pronouns 카운트 + POStagging을 제외한 기존 sparse\n",
"train = pd.concat([countvect_train,pheme_sparse_nopos],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_nopos],axis=1)\n",
"clf = GaussianNB()\n",
"train_test(train, test, pheme_y, ext_y, clf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MLP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Library"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import torch\n",
"import torch.nn as nn\n",
"import torch.nn.functional as F\n",
"import torch.optim as optim\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"from torch.utils.data import TensorDataset, DataLoader\n",
"import torchvision\n",
"import torchvision.transforms as transforms\n",
"from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler\n",
"from torch.utils.data.sampler import WeightedRandomSampler\n",
"from torch.optim import lr_scheduler\n",
"\n",
"from sklearn.preprocessing import StandardScaler\n",
"\n",
"from sklearn.metrics import accuracy_score\n",
"from sklearn.metrics import classification_report\n",
"from sklearn.metrics import f1_score, precision_score, recall_score\n",
"from transformers import AdamW, get_linear_schedule_with_warmup\n",
"\n",
"\n",
"from fetchData import fetchdata, cv_events\n",
"import __MLP\n",
"# from __MLP import getSamplers, convert_df_to_unsqueezed_tensor, train_sequential, clf_report\n",
"import random\n",
"\n",
"pd.set_option('display.max_columns', None)"
]
},
{
"cell_type": "code",
"execution_count": 244,
"metadata": {},
"outputs": [],
"source": [
"pheme_thread = pd.read_csv('./data/_PHEME_thread_avg.csv')\n",
"ext_thread = pd.read_csv('./data/_PHEMEext_thread_avg.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Execution"
]
},
{
"cell_type": "code",
"execution_count": 246,
"metadata": {},
"outputs": [],
"source": [
"# New POS tags + Sparse\n",
"train = pd.concat([countvect_train,pheme_sparse_nopos],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_nopos],axis=1)\n",
"# Old POS tags + Sparse\n",
"train = pd.concat([pheme_sparse_pos,pheme_sparse_nopos],axis=1)\n",
"test = pd.concat([ext_sparse_pos,ext_sparse_nopos],axis=1)\n",
"# Old POS tags + Sparse\n",
"train = pd.concat([pheme_sparse_pos,pheme_sparse_pronouns],axis=1)\n",
"test = pd.concat([ext_sparse_pos,ext_sparse_pronouns],axis=1)\n",
"# # New POS tags + Sparse\n",
"train = pd.concat([countvect_train,pheme_sparse_pronouns],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_pronouns],axis=1)\n",
"\n",
"train = pd.concat([countvect_train,pheme_sparse_pos,pheme_text,pheme_thread],axis=1)\n",
"test = pd.concat([countvect_test,ext_sparse_pos,ext_thread],axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 247,
"metadata": {},
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>!</th>\n <th>#</th>\n <th>&</th>\n <th>,</th>\n <th>@</th>\n <th>^</th>\n <th>a</th>\n <th>d</th>\n <th>g</th>\n <th>l</th>\n <th>n</th>\n <th>o</th>\n <th>p</th>\n <th>r</th>\n <th>s</th>\n <th>t</th>\n <th>u</th>\n <th>v</th>\n <th>x</th>\n <th>z</th>\n <th>~</th>\n <th>Noun</th>\n <th>Verb</th>\n <th>Adjective</th>\n <th>Pronoun</th>\n <th>Adverb</th>\n <th>Numeral</th>\n <th>Conjunction_inj</th>\n <th>Particle</th>\n <th>Determiner</th>\n <th>Modal</th>\n <th>Whs</th>\n <th>target</th>\n <th>depth</th>\n <th>SUM FriendsCount</th>\n <th>AVG FriendsCount</th>\n <th>AVG WordCount</th>\n <th>SUM WordCount</th>\n <th>AVG CharCount</th>\n <th>AVG HashTag</th>\n <th>SUM HashTag</th>\n <th>Ratio HashTag</th>\n <th>SUM Url</th>\n <th>AVG Url</th>\n <th>RATIO Url</th>\n <th>SUM Mention</th>\n <th>AVG Mention</th>\n <th>Ratio Mention</th>\n <th>AVG Statues</th>\n <th>AVG Listed</th>\n <th>AVG Follower</th>\n <th>AVG followers/friend</th>\n <th>AVG favorite</th>\n <th>Tweets Count</th>\n <th>Ratio Verified</th>\n <th>SUM Verified</th>\n <th>SUM RT</th>\n <th>AVG RT</th>\n <th>AVG AccAge</th>\n <th>thread_time</th>\n <th>AVG Emoji</th>\n <th>RATIO Emoji</th>\n <th>Ratio Media</th>\n <th>RATIO Question</th>\n <th>RATIO Exclaim</th>\n <th>RATIO Period</th>\n <th>AVG FPP</th>\n <th>AVG SPP</th>\n <th>AVG TPP</th>\n <th>AVG Skepticism</th>\n <th>Ratio Skepticism</th>\n <th>test_auxiliary</th>\n <th>test_tentat</th>\n <th>test_certain</th>\n <th>root_user_ratio</th>\n <th>unique_user_ratio</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>count</th>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.00000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5.802000e+03</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5.802000e+03</td>\n <td>5802.000000</td>\n <td>5.802000e+03</td>\n <td>5.802000e+03</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5.802000e+03</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n <td>5802.000000</td>\n </tr>\n <tr>\n <th>mean</th>\n <td>0.026370</td>\n <td>0.642709</td>\n <td>0.292658</td>\n <td>2.024647</td>\n <td>0.165288</td>\n <td>1.958290</td>\n <td>0.933816</td>\n <td>1.135643</td>\n <td>0.030334</td>\n <td>0.094450</td>\n <td>3.524130</td>\n <td>0.503102</td>\n <td>2.217166</td>\n <td>0.563771</td>\n <td>0.023957</td>\n <td>0.067046</td>\n <td>0.875733</td>\n <td>2.687349</td>\n <td>0.021717</td>\n <td>0.049293</td>\n <td>0.048949</td>\n <td>4.774560</td>\n <td>2.784385</td>\n <td>1.25991</td>\n <td>0.500000</td>\n <td>0.580834</td>\n <td>0.286108</td>\n <td>2.143571</td>\n <td>0.073251</td>\n <td>1.042572</td>\n <td>0.108239</td>\n <td>0.181834</td>\n <td>0.339883</td>\n <td>4.444847</td>\n <td>2.633307e+04</td>\n <td>1733.570913</td>\n <td>14.125338</td>\n <td>255.770079</td>\n <td>98.171466</td>\n <td>0.496359</td>\n <td>5.682179</td>\n <td>0.301478</td>\n <td>2.000862</td>\n <td>0.169802</td>\n <td>0.159550</td>\n <td>30.283006</td>\n <td>1.410343</td>\n <td>0.856806</td>\n <td>2.811923e+04</td>\n <td>1.188886</td>\n <td>1.327177e+05</td>\n <td>4.730672e+03</td>\n <td>3661.967253</td>\n <td>17.789038</td>\n <td>0.090144</td>\n <td>0.935539</td>\n <td>593.678904</td>\n <td>54.183651</td>\n <td>1301.455119</td>\n <td>4.204234e+04</td>\n <td>0.051571</td>\n <td>0.026130</td>\n <td>0.150894</td>\n <td>0.128175</td>\n <td>0.115823</td>\n <td>0.680897</td>\n <td>0.280068</td>\n <td>0.168354</td>\n <td>0.364289</td>\n <td>3.434852</td>\n <td>0.913416</td>\n <td>0.454008</td>\n <td>0.013465</td>\n <td>0.014904</td>\n <td>0.160519</td>\n <td>1.765709</td>\n </tr>\n <tr>\n <th>std</th>\n <td>0.172674</td>\n <td>0.826882</td>\n <td>0.548786</td>\n <td>1.585656</td>\n <td>0.447269</td>\n <td>1.563124</td>\n <td>0.978707</td>\n <td>1.186479</td>\n <td>0.191466</td>\n <td>0.330134</td>\n <td>1.765864</td>\n <td>0.884898</td>\n <td>1.332783</td>\n <td>0.842226</td>\n <td>0.158465</td>\n <td>0.258928</td>\n <td>0.748659</td>\n <td>1.727758</td>\n <td>0.146947</td>\n <td>0.224320</td>\n <td>0.302292</td>\n <td>2.004439</td>\n <td>1.745349</td>\n <td>1.12685</td>\n <td>0.856996</td>\n <td>0.846888</td>\n <td>0.638243</td>\n <td>1.336208</td>\n <td>0.272850</td>\n <td>1.128870</td>\n <td>0.343388</td>\n <td>0.431313</td>\n <td>0.473710</td>\n <td>3.886665</td>\n <td>8.265039e+04</td>\n <td>8908.546640</td>\n <td>3.310602</td>\n <td>322.040398</td>\n <td>20.474917</td>\n <td>0.589339</td>\n <td>6.190115</td>\n <td>0.266754</td>\n <td>2.683403</td>\n <td>0.246276</td>\n <td>0.226585</td>\n <td>46.743261</td>\n <td>0.650232</td>\n <td>0.224672</td>\n <td>3.792127e+04</td>\n <td>0.624923</td>\n <td>6.159211e+05</td>\n <td>3.625373e+04</td>\n <td>5009.969132</td>\n <td>20.094870</td>\n <td>0.166361</td>\n <td>1.547161</td>\n <td>3559.900906</td>\n <td>253.023384</td>\n <td>404.981863</td>\n <td>1.059661e+05</td>\n <td>0.223547</td>\n <td>0.075204</td>\n <td>0.232642</td>\n <td>0.133937</td>\n <td>0.135471</td>\n <td>0.226197</td>\n <td>0.289474</td>\n <td>0.227774</td>\n <td>0.336942</td>\n <td>1.188174</td>\n <td>0.125498</td>\n <td>0.248231</td>\n <td>0.040178</td>\n <td>0.054032</td>\n <td>0.236356</td>\n <td>2.599912</td>\n </tr>\n <tr>\n <th>min</th>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.00000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000e+00</td>\n <td>0.000000</td>\n <td>4.000000</td>\n <td>4.000000</td>\n <td>32.052632</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>2.100000e+01</td>\n <td>0.000000</td>\n <td>1.400000e+01</td>\n <td>7.650273e-02</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>25.000000</td>\n <td>0.803987</td>\n <td>0.000000</td>\n <td>0.000000e+00</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.002890</td>\n <td>0.031792</td>\n </tr>\n <tr>\n <th>25%</th>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>3.000000</td>\n <td>1.000000</td>\n <td>0.00000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>5.072750e+03</td>\n <td>550.987500</td>\n <td>12.000000</td>\n <td>89.000000</td>\n <td>85.559524</td>\n <td>0.142857</td>\n <td>2.000000</td>\n <td>0.105263</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>8.000000</td>\n <td>1.000000</td>\n <td>0.857143</td>\n <td>1.145628e+04</td>\n <td>0.798263</td>\n <td>2.914953e+03</td>\n <td>2.785679e+00</td>\n <td>1064.941176</td>\n <td>7.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>135.000000</td>\n <td>11.363636</td>\n <td>1050.459091</td>\n <td>8.525000e+02</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.545455</td>\n <td>0.066667</td>\n <td>0.000000</td>\n <td>0.125000</td>\n <td>2.666667</td>\n <td>0.863636</td>\n <td>0.294118</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.047619</td>\n <td>0.523810</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>3.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>5.000000</td>\n <td>3.000000</td>\n <td>1.00000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>3.000000</td>\n <td>1.136250e+04</td>\n <td>811.346816</td>\n <td>14.032744</td>\n <td>188.000000</td>\n <td>97.699248</td>\n <td>0.333333</td>\n <td>4.000000</td>\n <td>0.230769</td>\n <td>1.000000</td>\n <td>0.066667</td>\n <td>0.066667</td>\n <td>20.000000</td>\n <td>1.333333</td>\n <td>0.937500</td>\n <td>1.921985e+04</td>\n <td>1.059736</td>\n <td>1.156036e+04</td>\n <td>1.776215e+01</td>\n <td>2285.028571</td>\n <td>14.000000</td>\n <td>0.043478</td>\n <td>1.000000</td>\n <td>214.000000</td>\n <td>21.142857</td>\n <td>1278.362500</td>\n <td>6.901500e+03</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.050000</td>\n <td>0.111111</td>\n <td>0.090909</td>\n <td>0.681818</td>\n <td>0.225000</td>\n <td>0.105263</td>\n <td>0.321429</td>\n <td>3.345804</td>\n <td>0.964286</td>\n <td>0.470588</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.071429</td>\n <td>0.785714</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>3.000000</td>\n <td>0.000000</td>\n <td>3.000000</td>\n <td>1.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>5.000000</td>\n <td>1.000000</td>\n <td>3.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>4.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>6.000000</td>\n <td>4.000000</td>\n <td>2.00000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>3.000000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>5.000000</td>\n <td>2.308150e+04</td>\n <td>1288.510417</td>\n <td>16.000000</td>\n <td>306.000000</td>\n <td>109.600000</td>\n <td>0.652174</td>\n <td>8.000000</td>\n <td>0.421053</td>\n <td>3.000000</td>\n <td>0.250000</td>\n <td>0.227273</td>\n <td>34.000000</td>\n <td>1.737489</td>\n <td>0.962963</td>\n <td>3.180953e+04</td>\n <td>1.424568</td>\n <td>7.510993e+04</td>\n <td>1.658462e+02</td>\n <td>4544.706981</td>\n <td>21.000000</td>\n <td>0.105263</td>\n <td>1.000000</td>\n <td>486.000000</td>\n <td>42.741071</td>\n <td>1524.675439</td>\n <td>3.090225e+04</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.200000</td>\n <td>0.200000</td>\n <td>0.166667</td>\n <td>0.818182</td>\n <td>0.400000</td>\n <td>0.250000</td>\n <td>0.521739</td>\n <td>4.045455</td>\n <td>1.000000</td>\n <td>0.619048</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.142857</td>\n <td>1.571429</td>\n </tr>\n <tr>\n <th>max</th>\n <td>3.000000</td>\n <td>8.000000</td>\n <td>4.000000</td>\n <td>15.000000</td>\n <td>5.000000</td>\n <td>10.000000</td>\n <td>7.000000</td>\n <td>7.000000</td>\n <td>3.000000</td>\n <td>4.000000</td>\n <td>11.000000</td>\n <td>8.000000</td>\n <td>7.000000</td>\n <td>6.000000</td>\n <td>2.000000</td>\n <td>2.000000</td>\n <td>3.000000</td>\n <td>10.000000</td>\n <td>2.000000</td>\n <td>2.000000</td>\n <td>6.000000</td>\n <td>13.000000</td>\n <td>10.000000</td>\n <td>8.00000</td>\n <td>7.000000</td>\n <td>7.000000</td>\n <td>10.000000</td>\n <td>8.000000</td>\n <td>3.000000</td>\n <td>9.000000</td>\n <td>3.000000</td>\n <td>4.000000</td>\n <td>1.000000</td>\n <td>48.000000</td>\n <td>2.783373e+06</td>\n <td>423700.000000</td>\n <td>37.750000</td>\n <td>5320.000000</td>\n <td>228.000000</td>\n <td>7.500000</td>\n <td>97.000000</td>\n <td>1.000000</td>\n <td>30.000000</td>\n <td>2.666667</td>\n <td>1.000000</td>\n <td>972.000000</td>\n <td>6.166667</td>\n <td>1.000000</td>\n <td>1.167536e+06</td>\n <td>6.357100</td>\n <td>2.171632e+07</td>\n <td>1.078299e+06</td>\n <td>165383.000000</td>\n <td>346.000000</td>\n <td>1.000000</td>\n <td>40.000000</td>\n <td>207563.000000</td>\n <td>13837.533333</td>\n <td>3462.666667</td>\n <td>1.317255e+06</td>\n <td>7.166667</td>\n <td>1.000000</td>\n <td>1.666667</td>\n <td>1.000000</td>\n <td>1.666667</td>\n <td>1.666667</td>\n <td>4.000000</td>\n <td>4.000000</td>\n <td>6.000000</td>\n <td>12.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>1.000000</td>\n <td>11.000000</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " ! # & , @ \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.026370 0.642709 0.292658 2.024647 0.165288 \nstd 0.172674 0.826882 0.548786 1.585656 0.447269 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 0.000000 0.000000 0.000000 1.000000 0.000000 \n50% 0.000000 0.000000 0.000000 2.000000 0.000000 \n75% 0.000000 1.000000 1.000000 3.000000 0.000000 \nmax 3.000000 8.000000 4.000000 15.000000 5.000000 \n\n ^ a d g l \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 1.958290 0.933816 1.135643 0.030334 0.094450 \nstd 1.563124 0.978707 1.186479 0.191466 0.330134 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 1.000000 0.000000 0.000000 0.000000 0.000000 \n50% 2.000000 1.000000 1.000000 0.000000 0.000000 \n75% 3.000000 1.000000 2.000000 0.000000 0.000000 \nmax 10.000000 7.000000 7.000000 3.000000 4.000000 \n\n n o p r s \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 3.524130 0.503102 2.217166 0.563771 0.023957 \nstd 1.765864 0.884898 1.332783 0.842226 0.158465 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 2.000000 0.000000 1.000000 0.000000 0.000000 \n50% 3.000000 0.000000 2.000000 0.000000 0.000000 \n75% 5.000000 1.000000 3.000000 1.000000 0.000000 \nmax 11.000000 8.000000 7.000000 6.000000 2.000000 \n\n t u v x z \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.067046 0.875733 2.687349 0.021717 0.049293 \nstd 0.258928 0.748659 1.727758 0.146947 0.224320 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 0.000000 0.000000 1.000000 0.000000 0.000000 \n50% 0.000000 1.000000 2.000000 0.000000 0.000000 \n75% 0.000000 1.000000 4.000000 0.000000 0.000000 \nmax 2.000000 3.000000 10.000000 2.000000 2.000000 \n\n ~ Noun Verb Adjective Pronoun \\\ncount 5802.000000 5802.000000 5802.000000 5802.00000 5802.000000 \nmean 0.048949 4.774560 2.784385 1.25991 0.500000 \nstd 0.302292 2.004439 1.745349 1.12685 0.856996 \nmin 0.000000 0.000000 0.000000 0.00000 0.000000 \n25% 0.000000 3.000000 1.000000 0.00000 0.000000 \n50% 0.000000 5.000000 3.000000 1.00000 0.000000 \n75% 0.000000 6.000000 4.000000 2.00000 1.000000 \nmax 6.000000 13.000000 10.000000 8.00000 7.000000 \n\n Adverb Numeral Conjunction_inj Particle Determiner \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.580834 0.286108 2.143571 0.073251 1.042572 \nstd 0.846888 0.638243 1.336208 0.272850 1.128870 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 0.000000 0.000000 1.000000 0.000000 0.000000 \n50% 0.000000 0.000000 2.000000 0.000000 1.000000 \n75% 1.000000 0.000000 3.000000 0.000000 2.000000 \nmax 7.000000 10.000000 8.000000 3.000000 9.000000 \n\n Modal Whs target depth SUM FriendsCount \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5.802000e+03 \nmean 0.108239 0.181834 0.339883 4.444847 2.633307e+04 \nstd 0.343388 0.431313 0.473710 3.886665 8.265039e+04 \nmin 0.000000 0.000000 0.000000 1.000000 0.000000e+00 \n25% 0.000000 0.000000 0.000000 2.000000 5.072750e+03 \n50% 0.000000 0.000000 0.000000 3.000000 1.136250e+04 \n75% 0.000000 0.000000 1.000000 5.000000 2.308150e+04 \nmax 3.000000 4.000000 1.000000 48.000000 2.783373e+06 \n\n AVG FriendsCount AVG WordCount SUM WordCount AVG CharCount \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 1733.570913 14.125338 255.770079 98.171466 \nstd 8908.546640 3.310602 322.040398 20.474917 \nmin 0.000000 4.000000 4.000000 32.052632 \n25% 550.987500 12.000000 89.000000 85.559524 \n50% 811.346816 14.032744 188.000000 97.699248 \n75% 1288.510417 16.000000 306.000000 109.600000 \nmax 423700.000000 37.750000 5320.000000 228.000000 \n\n AVG HashTag SUM HashTag Ratio HashTag SUM Url AVG Url \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.496359 5.682179 0.301478 2.000862 0.169802 \nstd 0.589339 6.190115 0.266754 2.683403 0.246276 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 0.142857 2.000000 0.105263 0.000000 0.000000 \n50% 0.333333 4.000000 0.230769 1.000000 0.066667 \n75% 0.652174 8.000000 0.421053 3.000000 0.250000 \nmax 7.500000 97.000000 1.000000 30.000000 2.666667 \n\n RATIO Url SUM Mention AVG Mention Ratio Mention AVG Statues \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5.802000e+03 \nmean 0.159550 30.283006 1.410343 0.856806 2.811923e+04 \nstd 0.226585 46.743261 0.650232 0.224672 3.792127e+04 \nmin 0.000000 0.000000 0.000000 0.000000 2.100000e+01 \n25% 0.000000 8.000000 1.000000 0.857143 1.145628e+04 \n50% 0.066667 20.000000 1.333333 0.937500 1.921985e+04 \n75% 0.227273 34.000000 1.737489 0.962963 3.180953e+04 \nmax 1.000000 972.000000 6.166667 1.000000 1.167536e+06 \n\n AVG Listed AVG Follower AVG followers/friend AVG favorite \\\ncount 5802.000000 5.802000e+03 5.802000e+03 5802.000000 \nmean 1.188886 1.327177e+05 4.730672e+03 3661.967253 \nstd 0.624923 6.159211e+05 3.625373e+04 5009.969132 \nmin 0.000000 1.400000e+01 7.650273e-02 0.000000 \n25% 0.798263 2.914953e+03 2.785679e+00 1064.941176 \n50% 1.059736 1.156036e+04 1.776215e+01 2285.028571 \n75% 1.424568 7.510993e+04 1.658462e+02 4544.706981 \nmax 6.357100 2.171632e+07 1.078299e+06 165383.000000 \n\n Tweets Count Ratio Verified SUM Verified SUM RT \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 17.789038 0.090144 0.935539 593.678904 \nstd 20.094870 0.166361 1.547161 3559.900906 \nmin 1.000000 0.000000 0.000000 25.000000 \n25% 7.000000 0.000000 0.000000 135.000000 \n50% 14.000000 0.043478 1.000000 214.000000 \n75% 21.000000 0.105263 1.000000 486.000000 \nmax 346.000000 1.000000 40.000000 207563.000000 \n\n AVG RT AVG AccAge thread_time AVG Emoji RATIO Emoji \\\ncount 5802.000000 5802.000000 5.802000e+03 5802.000000 5802.000000 \nmean 54.183651 1301.455119 4.204234e+04 0.051571 0.026130 \nstd 253.023384 404.981863 1.059661e+05 0.223547 0.075204 \nmin 0.803987 0.000000 0.000000e+00 0.000000 0.000000 \n25% 11.363636 1050.459091 8.525000e+02 0.000000 0.000000 \n50% 21.142857 1278.362500 6.901500e+03 0.000000 0.000000 \n75% 42.741071 1524.675439 3.090225e+04 0.000000 0.000000 \nmax 13837.533333 3462.666667 1.317255e+06 7.166667 1.000000 \n\n Ratio Media RATIO Question RATIO Exclaim RATIO Period AVG FPP \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.150894 0.128175 0.115823 0.680897 0.280068 \nstd 0.232642 0.133937 0.135471 0.226197 0.289474 \nmin 0.000000 0.000000 0.000000 0.000000 0.000000 \n25% 0.000000 0.000000 0.000000 0.545455 0.066667 \n50% 0.050000 0.111111 0.090909 0.681818 0.225000 \n75% 0.200000 0.200000 0.166667 0.818182 0.400000 \nmax 1.666667 1.000000 1.666667 1.666667 4.000000 \n\n AVG SPP AVG TPP AVG Skepticism Ratio Skepticism \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.168354 0.364289 3.434852 0.913416 \nstd 0.227774 0.336942 1.188174 0.125498 \nmin 0.000000 0.000000 0.000000 0.000000 \n25% 0.000000 0.125000 2.666667 0.863636 \n50% 0.105263 0.321429 3.345804 0.964286 \n75% 0.250000 0.521739 4.045455 1.000000 \nmax 4.000000 6.000000 12.000000 1.000000 \n\n test_auxiliary test_tentat test_certain root_user_ratio \\\ncount 5802.000000 5802.000000 5802.000000 5802.000000 \nmean 0.454008 0.013465 0.014904 0.160519 \nstd 0.248231 0.040178 0.054032 0.236356 \nmin 0.000000 0.000000 0.000000 0.002890 \n25% 0.294118 0.000000 0.000000 0.047619 \n50% 0.470588 0.000000 0.000000 0.071429 \n75% 0.619048 0.000000 0.000000 0.142857 \nmax 1.000000 1.000000 1.000000 1.000000 \n\n unique_user_ratio \ncount 5802.000000 \nmean 1.765709 \nstd 2.599912 \nmin 0.031792 \n25% 0.523810 \n50% 0.785714 \n75% 1.571429 \nmax 11.000000 "
},
"execution_count": 247,
"metadata": {},
"output_type": "execute_result"
}