Hate_Speech_IMAYFLY_and_HOR.../FINAL_DESIGN_RUN_HORSEHERD.m

59 lines
1.4 KiB
Mathematica
Raw Permalink Normal View History

2022-07-14 07:27:48 +00:00
clc
clear all
close all
%%
[datanum,datatxt_final,dataraw]=xlsread('labeled_data.csv');
datatxt=datatxt_final(2:end,6);
no_of_data_to_process=1000;
txtdataout=datatxt(1:no_of_data_to_process);
classdata=datanum(1:no_of_data_to_process,6);
neitherloc=find(classdata==2);
offensiveloc=find(classdata==1);
hateloc=find(classdata==0);
txtdataout=string(txtdataout);
traindata_doc=textpreprocessing(txtdataout);
encode_word=wordEncoding(traindata_doc);
seq_maxleen=10;
traindata=doc2sequence(encode_word,traindata_doc,'Length',seq_maxleen);
testdata=doc2sequence(encode_word,traindata_doc,'Length',seq_maxleen);
trainclass=categorical(classdata+1);
numofdata=length(trainclass);
networkiter=5;
datapass{1}=traindata;
datapass{2}=trainclass;
datapass{3}=testdata;
datapass{5}=numofdata;
datapass{6}=encode_word;
datapass{21}=0;
datapass{22}=networkiter;
pop_size=2;
no_of_iter=10;
[conver_result,Final_result,all_result]=horseherd_process(datapass,pop_size,no_of_iter);
tardata=all_result{3};resdata=all_result{4};
figure,chadata=confusionchart(all_result{2},{'Hate speech','offensive' , 'neither'});
chadata.Title='Horse Herd optimization Algorithm';
chadata.RowSummary = 'row-normalized';
chadata.ColumnSummary = 'column-normalized';
figure,plot(conver_result,'r-s','linewidth',2);
grid on;xlabel('iteration');ylabel('Accuracy');
title('Convergence graph for Horse Herd optimization Algorithm');