В этом примере показано, как визуализировать текстовые данные с помощью облаков слов.
Панель инструментов Text Analytics расширяет функциональные возможности wordcloud (MATLAB) функция. Он добавляет поддержку для создания облаков слов непосредственно из массивов строк и создания облаков слов из моделей пакетов слов и разделов LDA.
Загрузите данные примера. Файл factoryReports.csv содержит заводские отчеты, включая текстовое описание и категориальные метки для каждого события.
filename = "factoryReports.csv"; tbl = readtable(filename,'TextType','string');
Извлеките текстовые данные из Description столбец.
textData = tbl.Description; textData(1:10)
ans = 10x1 string
"Items are occasionally getting stuck in the scanner spools."
"Loud rattling and banging sounds are coming from assembler pistons."
"There are cuts to the power when starting the plant."
"Fried capacitors in the assembler."
"Mixer tripped the fuses."
"Burst pipe in the constructing agent is spraying coolant."
"A fuse is blown in the mixer."
"Things continue to tumble off of the belt."
"Falling items from the conveyor belt."
"The scanner reel is split, it will soon begin to curve."
Создайте облако слов из отчетов.
figure
wordcloud(textData);
title("Factory Reports")
Сравнение слов в отчетах с метками "Leak" и "Mechanical Failure". Создайте облака слов отчетов для каждой из этих меток. Укажите цвета слов, которые должны быть синими и пурпурными для каждого облака слов соответственно.
figure labels = tbl.Category; subplot(1,2,1) idx = labels == "Leak"; wordcloud(textData(idx),'Color','blue'); title("Leak") subplot(1,2,2) idx = labels == "Mechanical Failure"; wordcloud(textData(idx),'Color','magenta'); title("Mechanical Failure")

Сравните слова в докладах с срочностью «Low», «Medium» и «High».
figure urgency = tbl.Urgency; subplot(1,3,1) idx = urgency == "Low"; wordcloud(textData(idx)); title("Urgency: Low") subplot(1,3,2) idx = urgency == "Medium"; wordcloud(textData(idx)); title("Urgency: Medium") subplot(1,3,3) idx = urgency == "High"; wordcloud(textData(idx)); title("Urgency: High")

Сравните слова в отчетах со стоимостью, указанной в сотнях долларов, с стоимостью, указанной в тысячах долларов. Создайте облака слов отчетов для каждой из этих сумм с выделением синего и красного цветов соответственно.
cost = tbl.Cost; idx = cost > 100; figure wordcloud(textData(idx),'HighlightColor','blue'); title("Cost > $100")

idx = cost > 1000; figure wordcloud(textData(idx),'HighlightColor','red'); title("Cost > $1,000")

bagOfWords | tokenizedDocument | wordcloud