🤖 機械学習・データ可視化プレビューガイド
✅ 新機能: TensorFlow/ML/データ可視化対応
実装完了
- ✅ TensorFlow MNIST CNN モデル訓練
- ✅ データ可視化 (matplotlib)
- ✅ データ分析 (pandas)
- ✅ 訓練履歴の可視化
- ✅ 予測結果の画像生成
- ✅ 複数画像の自動プレビュー
📝 テストコマンド
1. TensorFlow MNIST CNN (推奨)
コマンド:
TensorFlowを使用して手書き数字認識のCNNモデルを作成してください。MNIST データセットを使用し、訓練過程の可視化も含めてください。
期待される動作:
-
コード生成:
mnist_cnn.py作成- TensorFlow CNN モデル実装
- MNIST データセット自動ダウンロード
- 5エポック訓練
- 可視化コード含む
-
実行結果:
- MNISTデータセット読み込み (60,000訓練, 10,000テスト)
- CNNモデルビルド (Conv2D → MaxPooling → Dense)
- モデル訓練 (5エポック)
- テスト精度評価 (~98-99%)
- 2つの画像生成:
mnist_training_history.png- 訓練履歴グラフmnist_predictions.png- 予測サンプル10個
-
プレビューボタン:
- ✅ "MNIST Training History" ボタン
- ✅ "MNIST Predictions" ボタン
-
プレビューURL:
http://192.168.0.135:8090/html/images/mnist_training_history.pnghttp://192.168.0.135:8090/html/images/mnist_predictions.png
実行時間: 約2-3分 (CPUの場合)
生成される画像:
-
Training History (2つのグラフ):
- 左: 訓練精度 vs 検証精度
- 右: 訓練損失 vs 検証損失
-
Predictions (10個のサンプル):
- 手書き数字画像
- 真のラベル vs 予測ラベル
- 正解は緑、不正解は赤で表示
2. データ可視化
コマンド:
matplotlibを使用してデータ可視化を作成してください
または
グラフを作成してください。折れ線グラフ、散布図、棒グラフ、ヒストグラムを含めてください。
期待される動作:
-
生成画像:
visualization.png -
内容 (4つのグラフ):
- Line Plot: sin(x), cos(x)
- Scatter Plot: 相関データ
- Bar Chart: カテゴリ別データ
- Histogram: 正規分布
-
プレビューボタン: "Data Visualization"
-
URL:
http://192.168.0.135:8090/html/images/visualization.png
3. データ分析
コマンド:
pandasを使用してデータ分析を行ってください。売上データの分析と可視化を含めてください。
または
csvデータを分析して、統計情報とグラフを作成してください
期待される動作:
-
生成画像:
data_analysis.png -
内容 (4つのグラフ):
- Sales Trend: 時系列データ
- Revenue Distribution: ヒストグラム
- Sales vs Customers: 散布図
- Correlation Matrix: ヒートマップ
-
プレビューボタン: "Data Analysis"
-
URL:
http://192.168.0.135:8090/html/images/data_analysis.png
🔍 検出キーワード
Machine Learning
tensorflow,keras,pytorch機械学習,ml,深層学習cnn,rnn,lstmmnist,アイリスモデル訓練,分類,回帰
Visualization
matplotlib,seaborn,plotグラフ,可視化,visualization散布図,ヒストグラム,棒グラフheatmap,scatter,line plot
Data Analysis
pandas,csv,dataframeデータ分析,data analysis統計,相関
🚀 処理フロー
TensorFlow MNISTの場合
1. コマンド受信
"TensorFlowを使用して手書き数字認識のCNNモデルを作成..."
2. コマンド分析
determineCommandType() → "machine_learning"
3. コード生成
generateMLCode(command, "machine_learning")
→ mnist_cnn.py + bash script
4. Dockerコンテナで実行
docker exec <container> bash -c "python3 mnist_cnn.py"
→ 訓練開始 (約2-3分)
→ mnist_training_history.png 生成
→ mnist_predictions.png 生成
5. 画像をホストにコピー
docker cp <container>:/workspace/mnist_training_history.png ./html/images/
docker cp <container>:/workspace/mnist_predictions.png ./html/images/
6. プレビューメッセージ送信 (2つ)
preview_ready: "MNIST Training History"
preview_ready: "MNIST Predictions"
7. アプリでプレビューボタン表示 (2つ)
[MNIST Training History] ボタン
[MNIST Predictions] ボタン
📊 サーバーログ例
🎯 Executing command: TensorFlowを使用して手書き数字認識...
📤 Stage 1: Sending analyzing progress
📊 Command analysis: type=machine_learning, framework=standard
📤 Sending code_generated message (XXX bytes)
🔍 Looking for container for project: demo-1759406078
✅ Found container by project_id: 8f0bf28051d0
🐳 Executing generated code in container 8f0bf28051d0
✅ Code executed successfully
📋 Copying visualization/ML images from container to host
✅ Copied image: mnist_training_history.png
✅ Copied image: mnist_predictions.png
📤 Sending preview_ready for mnist_training_history.png
✅ Successfully sent preview_ready for MNIST Training History
📤 Sending preview_ready for mnist_predictions.png
✅ Successfully sent preview_ready for MNIST Predictions
🎨 生成されるPythonコード (mnist_cnn.py)
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import matplotlib.pyplot as plt
import numpy as np
# Load MNIST dataset
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
# Preprocess
x_train = x_train.reshape(-1, 28, 28, 1).astype('float32') / 255.0
x_test = x_test.reshape(-1, 28, 28, 1).astype('float32') / 255.0
# Build CNN
model = keras.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dropout(0.5),
layers.Dense(10, activation='softmax')
])
# Train
history = model.fit(x_train, y_train, epochs=5, validation_split=0.2)
# Evaluate
test_loss, test_acc = model.evaluate(x_test, y_test)
# Visualize training history & predictions
# (完全なコードはml_templates.goを参照)
🐛 トラブルシューティング
"Error Loading Page" が表示される
原因:
- Pythonコードの実行エラー
- 画像ファイルが生成されていない
- コンテナにTensorFlow/matplotlibがインストールされていない
解決策:
- コンテナのPython環境確認:
docker exec <container_id> python3 -c "import tensorflow; print(tensorflow.__version__)"
docker exec <container_id> python3 -c "import matplotlib; print(matplotlib.__version__)"
- 必要なライブラリインストール:
docker exec <container_id> pip3 install tensorflow matplotlib numpy pandas
- 生成されたファイル確認:
docker exec <container_id> ls -la /workspace/*.png
ls -la ./html/images/
- サーバーログ確認:
# バックグラウンドジョブのログ確認
訓練が遅い
- CPU使用: 2-3分程度 (正常)
- GPU使用可能な場合: TensorFlow GPU版を使用すると高速化
画像が表示されない
- 画像ファイルの存在確認:
ls -la /Users/suetaketakaya/1.prog/remote_manual/server/build_clean/html/images/
- ブラウザで直接アクセス:
http://192.168.0.135:8090/html/images/mnist_training_history.png
- 画像ファイルの権限確認:
chmod 644 ./html/images/*.png
📈 パフォーマンス
MNIST CNN訓練
-
データセット: 60,000訓練, 10,000テスト
-
モデルパラメータ: ~1.2M
-
訓練時間 (CPU):
- Epoch 1: ~30秒
- Epoch 2-5: ~20秒/epoch
- 合計: ~2-3分
-
期待される精度:
- 訓練精度: 98-99%
- テスト精度: 97-99%
データ可視化
- 実行時間: ~1秒
- 画像サイズ: ~100-200KB
🔧 カスタマイズ
エポック数を増やす
ml_templates.goのgenerateTensorFlowMNIST()内:
epochs=5 → epochs=10
モデル構造の変更
Pythonコード内のmodel定義を変更:
# より深いモデル
layers.Conv2D(128, (3, 3), activation='relu'),
✅ 成功基準
TensorFlow MNIST
- コマンド検出: "machine_learning"
- Pythonコード生成
- Docker内で実行
- MNISTデータセット自動ダウンロード
- モデル訓練完了
- 2つの画像生成
- 画像コピー
- 2つのプレビューボタン表示
- 画像表示成功
接続情報:
- WebSocket:
ws://192.168.0.135:8090/ws?key=6661755000 - Session Key:
6661755000 - 画像ディレクトリ:
/Users/suetaketakaya/1.prog/remote_manual/server/build_clean/html/images/
作成日: 2025年10月4日 バージョン: v4.2 - ML/Visualization Support ステータス: ✅ 実装完了・テスト可能
Related Documents
Prompts
<img width="395" alt="prompts.chat" src="https://github.com/user-attachments/assets/e0d0e32d-d2ce-4459-9f37-e951d9f4f5de" />
Daily Agent Tasks Framework
**Your Daily System for Working with Claude and Codex**
VPM Package Template
Starter for making Packages, including automation for building and publishing them.
Script Kit Guide
<!-- value: https://github.com/johnlindquist/kit/blob/main/GUIDE.md -->