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 進行分析。
載入並探查資料。 將資料集讀入 pandas DataFrame,檢查其形狀、列型別和記憶體佔用。顯示首行與末行以確認資料正確載入。檢查明顯的結構問題,如列錯位或編碼問題。
計算描述性統計量。 為所有數值列生成彙總統計,包括均值、中位數、標準差、偏度和峰度。對類別列,計算取值計數和眾數。此步驟建立對每個變數分佈的基礎理解。
識別趨勢與模式。 對帶時間索引的資料應用滾動平均、百分比變化和季節性分解。對非時序資料,使用 group-by 聚合和透視表來浮現跨類別的模式。標記任何單調趨勢或週期性行為。
執行相關與假設檢驗。 計算 Pearson 和 Spearman 相關矩陣,量化變數間關係。在適當時執行假設檢驗(t 檢驗、卡方檢驗、ANOVA)以確定統計顯著性。在報告 p 值與置信區間的同時一併報告效應量。
檢測異常與離群值。 使用 IQR 法和 z 分數識別顯著偏離常態的資料點。將離群值與領域上下文交叉核對,判斷其代表錯誤、罕見事件,還是有意義的訊號。
將發現綜合為報告。 用平實語言總結關鍵洞察,並輔以具體數字。按業務影響或統計顯著性對發現排序。包含限制與注意事項,如樣本量約束或混雜變數。
為 Agent 提供資料集的檔案路徑和分析目標的說明。可選擇指定要關注的列、假設檢驗的顯著性水平(預設 alpha=0.05),以及是否應用時間序列方法。
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
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.
7w4.net有更好的技能外掛。
這個 Skill 質量中上,內容專業且覆蓋面廣,包含完整的資料分析流程指引和實用的程式碼示例,能幫助你瞭解如何做資料質量檢查、趨勢分析和統計檢驗。優點是考慮周全,有專門章節講解常見問題怎麼處理。不足之處是缺少示例資料檔案,實際使用前需要自己準備資料素材,對新手不太友好。總體來說,這是一個偏理論指導型的技能文件,適合作為資料分析 Agent 的知識庫。.