開發指南

快速上手、API 文件與最佳實踐

快速開始

# 透過 API 獲取資料
import requests

response = requests.get('https://ais3.org/hackathon/2025/api/ads?limit=100')
ads = response.json()['data']

# 瀏覽資料
for ad in ads:
    print(f"廣告 ID: {ad['ad_id']}")
    print(f"內容: {ad['ad_context'][:100]}...")
    print(f"類型: {'影片' if ad['ad_is_video'] else '圖片'}")
    print("---")

API 端點

GET /hackathon/2025/api/stats

取得資料集統計資訊

GET /hackathon/2025/api/ads

取得廣告列表

參數:limit (預設: 50), offset (預設: 0), search, is_video

GET /hackathon/2025/dataset/{ad_id}/{file_type}

取得廣告相關檔案

file_type: ad_screenshot | profile_screenshot | profile_picture | ad_media

程式碼範例

Python 資料載入

import requests
import pandas as pd

# 載入資料
response = requests.get('https://ais3.org/hackathon/2025/api/ads?limit=1000')
ads = response.json()['data']

# 轉換為 DataFrame
df = pd.DataFrame(ads)

# 基本分析
print(f"總廣告數: {len(df)}")
print(f"影片廣告比例: {df['ad_is_video'].mean():.2%}")
print(f"平均按讚數: {df['ad_like_count'].astype(int).mean():.0f}")

JavaScript 前端展示

// 使用 Fetch API 載入資料
fetch('/hackathon/2025/api/ads?limit=10')
  .then(response => response.json())
  .then(data => {
    data.data.forEach(ad => {
      console.log(ad.ad_profile_name, ad.ad_context);
    });
  });

最佳實踐

  • 資料前處理:建議先清理文字內容,移除特殊字元和 URL
  • 特徵工程:可結合文字、視覺和元資料進行多模態特徵提取
  • 模型訓練:建議使用交叉驗證,避免過擬合
  • 評估指標:除了準確率,也要考慮 Precision、Recall 和 F1 Score