name: 資料分析 slug: "data-analysis" version: "1.0.0" displayName: "資料分析" summary: "通過統計方法、趨勢識別、假設檢驗和相關性分析來分析資料集以提取洞察。" description: 通過統計方法、趨勢識別、假設檢驗和相關性分析來分析資料集以提取洞察。 license: MIT metadata: author: awesome-ai-agent-skills version: 1.0.0
此技能使AI代理能夠對結構化資料集執行嚴格的統計分析。該代理載入資料,計算描述性和推斷性統計量,識別趨勢和相關性,進行假設檢驗,並生成可操作的見解。它支援CSV、Excel、Parquet和JSON輸入,並利用pandas、scipy和statsmodels進行分析。
載入並分析資料。 將資料集讀入pandas DataFrame並檢查其形狀、列型別和記憶體使用情況。顯示前幾行和後幾行以確認資料正確載入。檢查明顯的結構問題,如列偏移或編碼問題。
計算描述性統計。 為所有數值列生成摘要統計資訊,包括均值、中位數、標準差、偏度和峰度。對於分類列,計算值計數和眾數。此步驟建立對每個變數分佈的基礎理解。
識別趨勢和模式。 對時間索引資料應用滾動平均值、百分比變化和季節性分解。對於非時間資料,使用group-by聚合和透視表來揭示類別間的模式。標記任何單調趨勢或週期性行為。
執行相關性和假設檢驗。 計算皮爾遜和斯皮爾曼相關矩陣以量化變數間的關係。在適當情況下進行假設檢驗(t檢驗、卡方檢驗、ANOVA)以確定統計顯著性。報告p值和置信區間以及效應量。
檢測異常值和離群點。 使用IQR方法和z-score識別顯著偏離常態的資料點。將離群點與領域背景交叉參考,判斷它們是否代表錯誤、罕見事件或有意義的訊號。
將發現綜合成報告。 用通俗語言總結關鍵見解,並輔以具體數字。根據業務影響或統計顯著性對發現進行排序。包括限制和注意事項,如樣本量限制或混淆變數。
7w4.net小蔥技能站收錄全網優質技能,值得收藏。
向代理提供資料集的檔案路徑和分析目標描述。可選擇指定關注的列、假設檢驗的顯著性水平(預設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.
這個資料分析技能質量良好,內容全面且易於理解。優點是工作流程完整,從資料載入到報告生成都有詳細說明,程式碼示例實用,還專門處理了缺失值、偏態分佈、小樣本等常見問題。不足是目前只有文件介紹,沒有可直接執行的程式碼工具,實際使用需要自己編寫程式碼實現。