# Automated Detection of Misinformation: A Hybrid Approach for Fake News Detection
## Appendix B Application of Main Code Listings and Callbacks
```
1 defget_results(algorithm,precision,recall,accuracy,f1_score):
2 defword_stemming(input,output,columns):
3 df=pd.read_csv(input)
4 stemmer=PorterStemmer()
5
7 forcolumnincolumns:
8 df[column].replace(';np.nam,inplace=True)
9 df.dropn(subset=[column],inplace=True)
10 df[column]=df[column].apply(lambdarow:word_tokenize(row))
11 df[column]=df[column].apply(lambdarow:[stemmer.stem(y)forymrow])
12 df[column]=df[column].apply(lambdarow:''''.join(row))
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
333
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
510
52
53
54
555
56
570
581
59
60
591
611
62
63
64
64
652
653
654
666
671
672
682
692
693
60
6100
611
63
612
62
63
63
64
64
655
666
673
674
68
695
696
697
69
798
800
999
990
101
902
903
9111
912
921
922
93
944
955
966
979
98
999
113
1401
142
154
155



## Appendix D Feature Extraction and Selection Implementation
```
1 deffeature_extraction(input,column,label):
2 start_time=time.time()
3 lexicon=Empath()
4
5 res=lexicon.analyze(''po'',normalize=True)
6 dict_keys=1
7 forkeyinres:
8 dict_keys.append(key)
9
10 df=pd.DataFrame(columns=dict_keys)
11 df1=pd.read_csv(input)
12 dict=[]
13 forkeyindefnation.analyze(vals,normalize=True)
14 dict.append(res)
15
16
17 df=pd.DataFrame(dict)
18 df=df.assign(labels=df1[label])
19 print(''---%seconds---''%(time.time()-start_time))
20 returndf
```
Listing 16: Methods for ANOVA computation and selection of the most significant features. ```
1 defcomputeAnova(dataset,labels):
2#scikitlearnlibrarymethodtoperformANOVA
3 fstatAnova=SelectResult(score_func=f_classif,k='all')
4#herecomputeddataframereturnsthesameddatasetbutwithinformationabout
5#f-scoresandp-values
6 fstatAnova.fit(dataset,labels)
7 returnfstatAnova
8
9
10 defgetDatasetWithSignificantFeatures(dataset,labels,pvalueMargin):
11 fanova=computeAnova(dataset,labels)
12#variablestostorevaluesandindexesofeveriteration
13 nosignificantFeatureIndex=0
146 ollIndices=list()
15 significantFeatures=list()
161 notSignificantFeatures=list()
17j=1
18#looptoiteratoneverfeatureofdataset
19 foriinrange(len(fanova.scores_)):
20#conditiontotakeimportantfeaturesbasedonpvalueandwritethenew dataset
21 print(''Featurenr:{},f-stat:{},pvalue:{}'.format(i,
22 fanova.scores_[i],fanova.pvalues_[i]))
23
24 iffanova.pvalues_[i]<pvalueMargin:
25j+=1
26 significantFeatures.append(fanova.scores_[i])
27 else:
28 notisignificantFeatureIndex++=1
296 oIndices.append(i)
30 notSignificantFeatures.append(fanova.scores_[i])
31
32#newreduceddatasetwithsignificantfeatures
33 df=pd.DataFrame(dataset)
34 print(colIndices)
35 reducedDataSet=df.drop(df.columns[colIndices],axis-1)
36
37 returnreducedDataSet,significantFeatures
```

Listing 17: Feature extraction method from input dataset. ## References

* [PERSON] et al. (2018) [PERSON]; [PERSON]; [PERSON] The spread of true and false news online. _Science_**2018**, _359_, 1146-1151. [CrossRef] [PubMed]
* [PERSON] and [PERSON] (2020) [PERSON]; [PERSON] An overview of online fake news: Characterization, detection, and discussion. _Inf. Process. Manag._**2020**, _57_, 102025. [CrossRef]* [PERSON] and [PERSON] (2019) [PERSON]; [PERSON] Fake news detection using machine learning approaches: A systematic review. In Proceedings of the 2019 3 rd international conference on trends in electronics and informatics (ICOEI), Tirunelveli, India, 23-25 April 2019; IEEE: New York, NY, USA, 2019; pp. 230-234. * [PERSON] et al. (2021) [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON] A benchmark study of machine learning models for online fake news detection. _Mach. Learn. Appl._**2021**, \(4\), 100032. [CrossRef]
* [PERSON] and [PERSON] (2020) [PERSON]; [PERSON] An empirical comparison of fake news detection using different machine learning algorithms. _Int. J. Adv. Comput. Sci. Appl._**2020**, _11_, 146-152. [CrossRef]
* [PERSON] and [PERSON] (2019) [PERSON]; [PERSON] A Survey on Automatic Fake News Identification Techniques for Online and Socially Produced Data.