pythonで疎な文書ベクトルの類似度や距離を計算をするメモ Scipyで疎行列を使う際の基本的な操作について 書いたのが昔なので、どっか間違ってるかも import scipy.sparse as sp import numpy as np a = sp.lil_matrix((1, 10000)) # 1*10000の疎行列が作成される b = sp.lil_matrix((1, 10000)) # a.shape => (1, 10000) for i in xrange(a.shape[1]): r = np.random.rand() if r < 0.9: r = 0.0 a[0, i] = r # aの各要素にrandomで数値を格納した a # => <1x10000 sparse matrix of type '<type 'numpy.float64'>' with 9
私のブログが引用されているこんな記事 (未解決)大規模疎行列のコサイン類似度 – studylog/北の雲 を見つけたので乗っかってみる。しかも、未解決って書いてあるし。 文書群データが疎行列\(A\)で与えられているとする。ここで、各行が文書を、各列が語を表しているとする。ここで文書間のコサイン類似度を総当りで計算したいものとして、その方法を示す。 \(A\)の各行をベクトルと見てL2ノルムで正規化したものを\(\tilde{A}\)とすると、コサイン類似度を示す行列は \[ \tilde{A} \tilde{A}^T \] で計算できる。 では\(\tilde{A}\)をどう計算するかだが、ブロードキャスティングを使ってインプレイスで求めるのがいいかと思う。以下にサンプルコードを示す。 from scipy.sparse import lil_matrix import numpy a
numpy.random.randint¶ numpy.random.randint(low, high=None, size=None, dtype='l')¶ Return random integers from low (inclusive) to high (exclusive). Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low). low : int Lowest (signed) integer to be drawn from the distrib
numpy.nan_to_num# numpy.nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None)[source]# Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords. If x is inexact, NaN is replaced by zero or by the user defined value in nan keyword, infinity is replaced by the largest finite floating po
numpy.matrix# class numpy.matrix(data, dtype=None, copy=True)[source]# Returns a matrix from an array-like object, or from a string of data. A matrix is a specialized 2-D array that retains its 2-D nature through operations. It has certain special operators, such as * (matrix multiplication) and ** (matrix power). Note It is no longer recommended to use this class, even for linear algebra. Instead
In the field of machine learning and specifically the problem of statistical classification, a confusion matrix, also known as error matrix,[1] is a specific table layout that allows visualization of the performance of an algorithm, typically a supervised learning one; in unsupervised learning it is usually called a matching matrix. Each row of the matrix represents the instances in an actual clas
数学の線型代数学周辺分野における行列(ぎょうれつ、英: matrix)は、数や記号や式などを縦と横に矩形状に配列したものである。 概要[編集] 行・列[編集] 横に並んだ一筋を行(row)、縦に並んだ一筋を列(column)と呼ぶ。 例えば、下記のような行列 は2つの行と3つの列によって構成されているため、(2,3)型または2×3型の行列と呼ばれる。 成分[編集] 書き並べられた要素は行列の成分と呼ばれ、行列の第 i 行目、j 列目の成分を特に行列の (i, j) 成分と言う。行列の (i, j) 成分はふつう ai j のように二つの添字を単に横並びに書くが、誤解を避けるために添字の間にコンマを入れることもある。また略式的に、行列 A の (i, j) 成分を指定するのに Ai j という記法を用いることもある。 和・積[編集] 行列の和は、行の数と列の数が同じ行列において、成分ごとの計
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く