📊

data-analysis

👤 肖俊偉 ✓ 已認證 📦 v1.0.0 ⭐ 4.4 ⬇️ 197 下載
📊 資料分析 免費

📖 技能介紹


name: data-analysis description: 通過統計方法、趨勢識別、假設檢驗和相關分析,分析資料集以提取洞察。 license: MIT metadata: author: awesome-ai-agent-skills version: 1.0.0


資料分析

本技能讓 AI Agent 對結構化資料集執行嚴謹的統計分析。Agent 載入資料,計算描述性與推斷性統計量,識別趨勢與相關,檢驗假設,併產出可執行的洞察。支援 CSV、Excel、Parquet 和 JSON 輸入,利用 pandas、scipy 和 statsmodels 進行分析。

工作流

  1. 載入並探查資料。 將資料集讀入 pandas DataFrame,檢查其形狀、列型別和記憶體佔用。顯示首行與末行以確認資料正確載入。檢查明顯的結構問題,如列錯位或編碼問題。

  2. 計算描述性統計量。 為所有數值列生成彙總統計,包括均值、中位數、標準差、偏度和峰度。對類別列,計算取值計數和眾數。此步驟建立對每個變數分佈的基礎理解。

  3. 識別趨勢與模式。 對帶時間索引的資料應用滾動平均、百分比變化和季節性分解。對非時序資料,使用 group-by 聚合和透視表來浮現跨類別的模式。標記任何單調趨勢或週期性行為。

  4. 執行相關與假設檢驗。 計算 Pearson 和 Spearman 相關矩陣,量化變數間關係。在適當時執行假設檢驗(t 檢驗、卡方檢驗、ANOVA)以確定統計顯著性。在報告 p 值與置信區間的同時一併報告效應量。

  5. 檢測異常與離群值。 使用 IQR 法和 z 分數識別顯著偏離常態的資料點。將離群值與領域上下文交叉核對,判斷其代表錯誤、罕見事件,還是有意義的訊號。

  6. 將發現綜合為報告。 用平實語言總結關鍵洞察,並輔以具體數字。按業務影響或統計顯著性對發現排序。包含限制與注意事項,如樣本量約束或混雜變數。

支援技術

  • pandas — 資料載入、操作與聚合
  • scipy.stats — 假設檢驗、統計分佈
  • statsmodels — 時間序列分解、迴歸分析
  • numpy — 數值計算

使用方式

為 Agent 提供資料集的檔案路徑和分析目標的說明。可選擇指定要關注的列、假設檢驗的顯著性水平(預設 alpha=0.05),以及是否應用時間序列方法。

示例

示例 1:用 pandas 分析銷售 CSV

import pandas as pd
from scipy import stats

# Load the dataset
df = pd.read_csv("sales_2024.csv", parse_dates=["order_date"])

# Descriptive statistics
print(df[["revenue", "units_sold", "discount"]].describe())
#          revenue  units_sold  discount
# count   8450.00     8450.00   8450.00
# mean     312.45       4.12      0.08
# std      189.73       2.87      0.05
# min       12.00       1.00      0.00
# max     2450.00      47.00      0.35

# Correlation analysis
corr = df[["revenue", "units_sold", "discount"]].corr(method="pearson")
print(corr)
#             revenue  units_sold  discount
# revenue       1.000       0.847    -0.213
# units_sold    0.847       1.000    -0.089
# discount     -0.213      -0.089     1.000

# Hypothesis test: do discounted orders produce higher revenue?
discounted = df[df["discount"] > 0]["revenue"]
full_price = df[df["discount"] == 0]["revenue"]
t_stat, p_value = stats.ttest_ind(discounted, full_price)
print(f"t={t_stat:.3f}, p={p_value:.4f}")
# t=-3.217, p=0.0013 — discounted orders have significantly lower revenue per order

示例 2:帶季節性分解的時間序列分析

import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose

# Load monthly revenue data
df = pd.read_csv("monthly_revenue.csv", parse_dates=["month"], index_col="month")

# Decompose into trend, seasonal, and residual components
result = seasonal_decompose(df["revenue"], model="additive", period=12)

print("Trend (last 6 months):")
print(result.trend.dropna().tail(6))
# 2024-07    48230.12
# 2024-08    49012.45
# 2024-09    49780.33
# 2024-10    50234.10
# 2024-11    51002.88
# 2024-12    51890.67

print("\nSeasonal peaks:")
seasonal = result.seasonal.groupby(result.seasonal.index.month).mean()
print(seasonal.nlargest(3))
# month
# 11    8923.40   (November — holiday pre-orders)
# 12    7654.20   (December — holiday sales)
# 3     3210.15   (March — spring promotions)

# The upward trend of ~$600/month suggests 14.5% annualized growth.
# Strong Q4 seasonality accounts for roughly 18% of total annual revenue.

最佳實踐

  • 計算統計前始終先檢查原始資料——靜默的解析錯誤(錯誤分隔符、編碼問題)會使所有下游結果失效。
  • 在 p 值之外同時報告效應量;僅統計顯著性並不意味實際重要性。

    7w4.net有更好的技能外掛。

  • 當資料分佈嚴重偏斜或樣本量較小時,使用非引數檢驗(Mann-Whitney、Kruskal-Wallis)。
  • 按有意義的類別(地區、產品線、客戶層級)做細分分析,以避免辛普森悖論。
  • 明確記錄假設——時間序列的平穩性、引數檢驗的正態性、觀測的獨立性。
  • 在將驚人發現作為結論呈現前,用保留樣本或替代方法學進行驗證。

邊緣情況

  • 關鍵列中的缺失值。 如果目標列超過 30% 為空,警告使用者插補可能引入顯著偏差。改為建議分析完整案例子集。
  • 極度偏斜的分佈。 當偏度超過 |2.0| 時,使用對數變換或基於中位數的統計,以避免誤導性的均值。
  • 多重共線性。 當兩個預測變數相關性高於 0.9 時,標記此問題並建議刪除其中一個或使用正則化模型,以避免係數膨脹。
  • 小樣本量(n < 30)。 切換到精確檢驗或 bootstrap 方法,並相應放寬置信區間。
  • 單列中混合的資料型別。 謹慎強制轉換並報告無法轉換的值數量,而非靜默丟棄。

🤖 AI 評測

這個 Skill 質量中上,內容專業且覆蓋面廣,包含完整的資料分析流程指引和實用的程式碼示例,能幫助你瞭解如何做資料質量檢查、趨勢分析和統計檢驗。優點是考慮周全,有專門章節講解常見問題怎麼處理。不足之處是缺少示例資料檔案,實際使用前需要自己準備資料素材,對新手不太友好。總體來說,這是一個偏理論指導型的技能文件,適合作為資料分析 Agent 的知識庫。.

📊 多維度評分

適應性4.2
規範性4.6
有效性4.4
可靠性4
可信度5

📁 包含檔案 (2 個)

📄 README.md 918 B
📄 SKILL.md 5.8 KB