Loading...
Loading...
# 🤖 機械学習・データ可視化プレビューガイド
## ✅ 新機能: TensorFlow/ML/データ可視化対応
### 実装完了
- ✅ TensorFlow MNIST CNN モデル訓練
- ✅ データ可視化 (matplotlib)
- ✅ データ分析 (pandas)
- ✅ 訓練履歴の可視化
- ✅ 予測結果の画像生成
- ✅ 複数画像の自動プレビュー
---
## 📝 テストコマンド
### 1. TensorFlow MNIST CNN (推奨)
**コマンド:**
```
TensorFlowを使用して手書き数字認識のCNNモデルを作成してください。MNIST データセットを使用し、訓練過程の可視化も含めてください。
```
**期待される動作:**
1. **コード生成**:
- `mnist_cnn.py` 作成
- TensorFlow CNN モデル実装
- MNIST データセット自動ダウンロード
- 5エポック訓練
- 可視化コード含む
2. **実行結果**:
- MNISTデータセット読み込み (60,000訓練, 10,000テスト)
- CNNモデルビルド (Conv2D → MaxPooling → Dense)
- モデル訓練 (5エポック)
- テスト精度評価 (~98-99%)
- 2つの画像生成:
- `mnist_training_history.png` - 訓練履歴グラフ
- `mnist_predictions.png` - 予測サンプル10個
3. **プレビューボタン**:
- ✅ "MNIST Training History" ボタン
- ✅ "MNIST Predictions" ボタン
4. **プレビューURL**:
- `http://192.168.0.135:8090/html/images/mnist_training_history.png`
- `http://192.168.0.135:8090/html/images/mnist_predictions.png`
**実行時間**: 約2-3分 (CPUの場合)
**生成される画像**:
1. **Training History** (2つのグラフ):
- 左: 訓練精度 vs 検証精度
- 右: 訓練損失 vs 検証損失
2. **Predictions** (10個のサンプル):
- 手書き数字画像
- 真のラベル vs 予測ラベル
- 正解は緑、不正解は赤で表示
---
### 2. データ可視化
**コマンド:**
```
matplotlibを使用してデータ可視化を作成してください
```
または
```
グラフを作成してください。折れ線グラフ、散布図、棒グラフ、ヒストグラムを含めてください。
```
**期待される動作:**
1. **生成画像**: `visualization.png`
2. **内容** (4つのグラフ):
- Line Plot: sin(x), cos(x)
- Scatter Plot: 相関データ
- Bar Chart: カテゴリ別データ
- Histogram: 正規分布
3. **プレビューボタン**: "Data Visualization"
4. **URL**: `http://192.168.0.135:8090/html/images/visualization.png`
---
### 3. データ分析
**コマンド:**
```
pandasを使用してデータ分析を行ってください。売上データの分析と可視化を含めてください。
```
または
```
csvデータを分析して、統計情報とグラフを作成してください
```
**期待される動作:**
1. **生成画像**: `data_analysis.png`
2. **内容** (4つのグラフ):
- Sales Trend: 時系列データ
- Revenue Distribution: ヒストグラム
- Sales vs Customers: 散布図
- Correlation Matrix: ヒートマップ
3. **プレビューボタン**: "Data Analysis"
4. **URL**: `http://192.168.0.135:8090/html/images/data_analysis.png`
---
## 🔍 検出キーワード
### Machine Learning
- `tensorflow`, `keras`, `pytorch`
- `機械学習`, `ml`, `深層学習`
- `cnn`, `rnn`, `lstm`
- `mnist`, `アイリス`
- `モデル訓練`, `分類`, `回帰`
### 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)
```python
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" が表示される
**原因:**
1. Pythonコードの実行エラー
2. 画像ファイルが生成されていない
3. コンテナにTensorFlow/matplotlibがインストールされていない
**解決策:**
1. **コンテナのPython環境確認**:
```bash
docker exec <container_id> python3 -c "import tensorflow; print(tensorflow.__version__)"
docker exec <container_id> python3 -c "import matplotlib; print(matplotlib.__version__)"
```
2. **必要なライブラリインストール**:
```bash
docker exec <container_id> pip3 install tensorflow matplotlib numpy pandas
```
3. **生成されたファイル確認**:
```bash
docker exec <container_id> ls -la /workspace/*.png
ls -la ./html/images/
```
4. **サーバーログ確認**:
```bash
# バックグラウンドジョブのログ確認
```
### 訓練が遅い
- **CPU使用**: 2-3分程度 (正常)
- **GPU使用可能な場合**: TensorFlow GPU版を使用すると高速化
### 画像が表示されない
1. **画像ファイルの存在確認**:
```bash
ls -la /Users/suetaketakaya/1.prog/remote_manual/server/build_clean/html/images/
```
2. **ブラウザで直接アクセス**:
```
http://192.168.0.135:8090/html/images/mnist_training_history.png
```
3. **画像ファイルの権限確認**:
```bash
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()`内:
```go
epochs=5 → epochs=10
```
### モデル構造の変更
Pythonコード内のmodel定義を変更:
```python
# より深いモデル
layers.Conv2D(128, (3, 3), activation='relu'),
```
---
## ✅ 成功基準
### TensorFlow MNIST
- [x] コマンド検出: "machine_learning"
- [x] Pythonコード生成
- [x] Docker内で実行
- [x] MNISTデータセット自動ダウンロード
- [x] モデル訓練完了
- [x] 2つの画像生成
- [x] 画像コピー
- [x] 2つのプレビューボタン表示
- [x] 画像表示成功
---
**接続情報:**
- 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
**ステータス**: ✅ 実装完了・テスト可能
IMPORTANT: Fallow the rules in the './.rules.md' file
A clear, well-structured prompt dramatically improves the quality of AI-generated outputs. This guide outlines key principles and examples for writing effective prompts using the **RTCF** framework and other best practices.
<citation_instructions>If the assistant's response is based on content returned by the web_search, drive_search, google_drive_search, or google_drive_fetch tool, the assistant must always appropriately cite its response. Here are the rules for good citations:
description: Publishable Prompt Engineering skill package that compiles a user request into a ready-to-use high-quality Prompt, with support for diagnosis, module injection, debugging, and evaluation.