LLMを用いたデータ自動分析
はじめに
近年、IoTデバイスによる現場データの取得が容易となり、膨大なセンサーログの活用が重要視されています。本記事では、当社が支援したプロジェクトで活躍しているLTE-M基板から取得した測定データログ(但し、自社実験データログ)を対象に、大規模言語モデル(LLM)による自動分析がどこまで現実的かを検証しました。従来は人手による確認や分析が主流でしたが、生成AI技術の進展により、データのQ&Aや可視化を自然言語で自動化する可能性について探ります。
使用データ
期間:2025年4月1日~2025年7月7日
構成:日ごとに1ファイル、JSON形式 (デバイスは5分毎にメッセージを送信)
測定データ:時刻、起動時およびPOST直前のバッテリー電圧、ネットワーク状態、ヒープサイズなど
分析に利用したLLM・ツール
モデル:ChatGPT-4o
ライブラリ・ツール:
- Python(データ前処理、グラフ描画)
- LangChain create_csv_agent
- OpenAI AssistantsAPI
データ前処理
各日のJSONログから、主要なフィールドごとに代表統計量(min, max, mean, std, 25%, 75%)を抽出し、1行1日分のCSVデータへ整形しました。これにより、LLMがデータ全体の傾向や個別の記録を参照しやすいようにしています。
実験1:LangChain create_csv_agentによる分析
LangChainのcreate_csv_agent機能を用いることで、自然言語でCSVデータに対してQ&Aや集計が可能か検証しました。
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langchain_openai import ChatOpenAI
cav_file_path = ${Your csv file path}
llm = ChatOpenAI(temperature=0, model="gpt-4o")
agent = create_csv_agent(
llm,
csv_file_path,
verbose=True,
allow_dangerous_code=True,
handle_parsing_errors=True)
prompt = "Your prompt"
agent.run((prompt))
Q&A
プロンプト
2025年4月4日のバッテリー電圧の最大値は?
出力
2025年4月4日のバッテリー電圧の最大値は3678です。
期待通り正確に応答しました。
グラフ可視化
プロンプト
バッテリー電圧とPOST前のバッテリー電圧を時系列でプロットして。平均と標準偏差も表示して。グラフの特徴について説明して。
出力
The graph shows the time series of the battery voltage and the battery voltage before POST. The blue line represents the mean battery voltage, and the shaded area around it represents the standard deviation. Similarly, the green line represents the mean battery voltage before POST, with its shaded area indicating the standard deviation. The graph allows us to observe the trends and variability in the battery voltages over the given time period.
LangChain経由でも、比較的直感的な日本語指示でデータ可視化ができました。ただし、説明が英語となりました。これはPromptに日本語で回答して
と加えても変更されませんでした。
実験2:OpenAI AssistantsAPIによる分析
比較のため、OpenAIのAssistantsAPI(code interpreter)を用いて、同様の分析・可視化を実施しました。なお、AssistantsAPIは現在β版でResponsesAPIへの移行が計画されています。本実験では日本語プロンプトではうまく動作しなかったため、英語でプロンプトを与えています。
プロンプト
Plot mean and std of Battery voltage and Battery voltage before POST in time series. Use Python matplotlib. Explain also about the graph characteristics.
出力
1. **Battery Voltage (Mean and Standard Deviation):**
- The solid blue line represents the mean battery voltage over time.
- The dashed cyan lines show one standard deviation above and below the mean, providing a sense of the voltage variability.
2. **Battery Voltage Before POST (Mean and Standard Deviation):**
- The solid red line indicates the mean voltage before the POST process.
- The dashed orange lines illustrate one standard deviation away from the mean for before POST voltage, capturing variability.
### Graph Insights:
- **Trends and Patterns:**
- The mean battery voltage remains relatively stable over time, with minor fluctuations.
- The mean voltage before POST shows a slightly declining trend.
- **Variability:**
- Both battery voltage and before POST voltage have relatively consistent variability over time, as indicated by their standard deviation bands.
- **Comparison:**
- The overall level of the mean battery voltage is higher than the voltage before POST. There is a noticeable gap between the two throughout the observation period.
This plot helps in assessing any significant changes or anomalies in battery performance and the voltage behavior prior to the POST process over the observed period.
出力形式の違いはありますが、同様にグラフをプロットすることができました。また、より丁寧に説明をしているように見えます。
注意点・課題
プロンプト依存性
同じ内容でも指示の仕方や言語によって、正しく意図を汲んだ応答が得られないケースが散見されました。特にAssistantsAPIでは日本語指示では正確な結果が得られず、英語の方が安定しました。
自動化限界
形式が異なるデータや複雑な集計処理については、依然として事前の前処理やプロンプト工夫が必要です。
まとめ
本記事では、LTE-Mデバイスから取得した時系列データを用いて、大規模言語モデル(LLM)による自動分析の現状を検証しました。LangChainやOpenAI AssistantsAPIを活用することで、日次センサーデータのQ&A・可視化が自然言語ベースで一定程度自動化できることが確認できました。
一方で、プロンプトの言語や表現次第で結果が大きく左右されるため、実運用にあたっては運用側の工夫や確認が必須です。今後は、さらに精度・安定性の高い分析や、異常検知・フィードバックの自動化にもチャレンジしていきたいと考えています。