0
0

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.

自然言語処理のためのポケモン

0
Posted at
# MeCabとPythonバインディングのインストール
!apt-get -q install mecab libmecab-dev mecab-ipadic-utf8
!pip install mecab-python3

# -*- coding: utf-8 -*-
# Program Name: pokemon_mecab_analysis.py
# Description: ポケモン解説文を形態素解析(環境依存対策付き)

import MeCab

# --- MeCab初期化(環境依存対策) / Initialize MeCab with rcfile option ---
try:
    tagger = MeCab.Tagger("-r /etc/mecabrc")
except RuntimeError as e:
    print("MeCab initialization failed. Please check mecabrc path.")
    raise e

# --- 解析対象テキスト / Define Text ---
txt = '''はじめまして、こちらはポケモン統計学習チャンネルです。
Pythonを使ってポケモンデータを自在に分析し、バトルや育成に役立てる力を一緒に身につけましょう。
本講義では特にポケモンの種族値や技データを使った機械学習や自然言語処理に挑戦します。
様々なライブラリを活用することで、タイプ相性や強さ分析が簡単にできます。
それでは早速、ポケモンデータ分析の世界へ進んでいきましょう。'''

# --- 形態素解析実行 / Run Morphological Analysis ---
result = tagger.parse(txt)

# --- 解析結果表示 / Show Result ---
print(result)

# -*- coding: utf-8 -*-
# Program Name: simple_word_pca_visualization.py
# Description: English sentence to dummy vectors and PCA 2D visualization

import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA

# --- Example English Sentence ---
sentence = "Learn data science with Python and apply machine learning to analyze Pokemon data"

# --- Tokenize Sentence ---
words = sentence.lower().split()

# --- Simulate Dummy Word Vectors (50-dimensional random vectors) ---
np.random.seed(42)
dummy_vectors = np.random.rand(len(words), 50)

# --- Dimensionality Reduction (PCA) to 2D ---
pca = PCA(n_components=2)
reduced_vectors = pca.fit_transform(dummy_vectors)

# --- 2D Plot ---
plt.figure(figsize=(8, 6))
plt.scatter(reduced_vectors[:, 0], reduced_vectors[:, 1], color='blue')

for i, word in enumerate(words):
    plt.text(reduced_vectors[i, 0] + 0.01, reduced_vectors[i, 1] + 0.01, word, fontsize=9)

plt.title('2D PCA Projection of Dummy Word Vectors')
plt.xlabel('PCA Component 1')
plt.ylabel('PCA Component 2')
plt.show()

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?