2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

UMAP使い方2023.12

Last updated at Posted at 2023-12-23

UMAPは多次元量を2次元にマッピングしてくれる。CNNを使ってカテゴリ判別しているときに、学習していないカテゴリの判別や、経時変化で正常サンプルの特徴量が変化し検出精度が低下する予兆をとらえたり利用できるよう。
先日聞いた話では、CNNの最終層(全結合の手前)の情報を利用すると言っていた。

参考文献

ユーザーガイド 閲覧時バージョン0.5最新版

UMAPの概要、詳細は上記サイトを参照のこと。

ユーザーガイドで動作しない部分の修正

umapのインストールをpip install umap-learnではなく、pip install umap で行っていたようだ。-learnを付けないと、ver0.1.1がインストールされるようだ。 2024.04

3カ所 2カ所の修正で動作した。

ユーザーガイドの0から9の手書き数字のマッピングの例の部分で
ユーザーガイドのコードが依存ライブラリ等のバージョンアップのため動作しない部分があったので微修正を行った。元コードをコメントアウト。

def embeddable_image(data):
    img_data = 255 - 15 * data.astype(np.uint8)
    image = Image.fromarray(img_data, mode='L').resize((64, 64), Image.BICUBIC)

    # image = Image.fromarray(img_data, mode='L').resize((64, 64), Image.Resampling.BICUBIC) リサンプリング古い?
    buffer = BytesIO()
    image.save(buffer, format='png')
    for_encoding = buffer.getvalue()
    return 'data:image/png;base64,' + base64.b64encode(for_encoding).decode()
# reducer = umap.UMAP(random_state=42) カッコ内ランダムステートがあると失敗する
reducer = umap.UMAP()
この部分は間違ってumap 0.1 をインストールしたときに必要だった修正

plot_figure = figure(
    title='UMAP projection of the Digits dataset',
    
    # plot_width=600,
    # plot_height=600, 古い記述形式
    
    width=600,
    height=600,
    tools=('pan, wheel_zoom, reset')
)

このときの環境Python 3.10.12

bokeh==3.3.2
matplotlib==3.7.1
matplotlib-inline==0.1.6
numpy==1.24.3
pandas==2.1.4
Pillow==10.1.0
scikit-learn==1.2.2
scipy==1.10.1
seaborn==0.13.0
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?