起こった こと
以下のような
スクリプト
from sklearn.feature_extraction.text import CountVectorizer import numpy as np # テキスト内の単語の出現頻度を数えて、結果を素性ベクトル化する(Bag of words) count_vectorizer = CountVectorizer() # csr_matrix(疎行列)が返る feature_vectors = count_vectorizer.fit_transform(keywords) # 学習したデータのみ切り出し learning_vectors = feature_vectors[:len(read_from_learning_tsv(0))] # データに対応したラベルを取得 learning_labels = np.array(read_from_learning_tsv(1)) learning_vectors
OUTPUT
learning_vectors
を内容を 確認したいので、 標準出力していますが、 sparse matrix
なので以下出力となり、 内容の 確認が できません。 <940x655 sparse matrix of type '<type 'numpy.int64'>' with 2650 stored elements in Compressed Sparse Row format>
todense
StackOverFlow で
python - How to access sparse matrix elements? - Stack Overflow
sparse matrix の
learning_vectors
learning_vectors. todense()
- OUTPUT
matrix([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 1], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]])
全てが
以上です。
コメント