Clustering sequences of data with different lengths using ngrams.

조회 수: 5 (최근 30일)
SOPAE YI
SOPAE YI 2020년 3월 16일
편집: SOPAE YI 2020년 3월 21일
I am trying to cluster sequences of data that have different lengths.
I am treating the element of my sequence as a word. In other words, a list is a sentence.
To be able to achive this I am thinking of extracting ngrams like my code below.
However, I keep getting following error message:
“Arguments to IMPORT must either end with ".*" or else specify a fully qualified class name: "nltk" fails this test.”
1. How can I solve this error?
2. Am I going toward right direction?
I am a novice Matlab user and I hope I am not asking too basic questions.
Following is my Matlab code:
-------------------------------------------------------
A = [1.2,1.5; 2.4,0.5; 3.2,1.5];
B = [1.0,1.0; 2.0,0; 3.0,1.0; 4.0,0.5];
C = [1.1,1.2; 2.2,1.3; 3.3,1.5];
D = [1.3,1.3; 2.1,1.4; 3.2,1.7; 4.3, 2.0];
E = [1.3,1.8; 2.3,0.4; 3.1,1.6; 4.3,0.8];
figure()
plot(A(:,1), A(:,2)) % first column is the time-values
hold on;
plot(B(:,1), B(:,2))
hold on;
plot(E(:,1), E(:,2))
figure()
plot(C(:,1), C(:,2)) % first column is the time-values
hold on;
plot(D(:,1), D(:,2))
import nltk
from nltk import ngrams
aa = A(:)'
bb = B(:)'
cc = C(:)'
dd = D(:)'
ee = E(:)'
bb = list()
bb append(str(','.join(str(e) for e in ['x' + str(e) for e in aa])))
bb append(str(','.join(str(e) for e in ['x' + str(e) for e in bb])))
bb append(str(','.join(str(e) for e in ['x' + str(e) for e in cc])))
bb append(str(','.join(str(e) for e in ['x' + str(e) for e in dd])))
bb append(str(','.join(str(e) for e in ['x' + str(e) for e in ee])))
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(bb)
X.toarray()

답변 (1개)

Prabhanjan Mentla
Prabhanjan Mentla 2020년 3월 20일
NLTK is not supported in MATLAB however one can run python functions in MATLAB by following this. There is also text analytics toolbox in MATLAB which deals text data.
  댓글 수: 1
SOPAE YI
SOPAE YI 2020년 3월 20일
편집: SOPAE YI 2020년 3월 21일
Thank you so much for crrecting me, sir.
My data is not text.
I am working on spoken sentence (or an utterance) especialy, pitch of a sentence.
Can I use NLTK to cluster sequences of (pitch) data that have different lengths?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by