SONUB 首頁

只有我們的團隊會閱讀。請不要填寫密碼或卡號。

謝謝!每則意見我們都會閱讀,並用來決定下一步改進什麼。

關閉 送出
ZH-HANT English 한국어 日本語 简体中文 繁體中文 हिन्दी বাংলা اردو Español Português Français Deutsch Русский العربية Bahasa Indonesia Tiếng Việt ไทย Türkçe

如何開啟通知

此瀏覽器或網址無法使用通知。請使用支援通知的瀏覽器,透過安全連線訪問SONUB。

如果通知被遮蔽,請在瀏覽器設定中允許通知。

  1. 開啟位址列旁的站點設定或瀏覽器的站點設定,將此網站的通知設為允許。
  2. 在裝置設定中允許瀏覽器傳送通知,並檢查勿擾模式或專注模式。
  3. 返回SONUB並重新整理頁面。通知開啟後,鈴鐺將不再顯示。

在iPhone或iPad上,將SONUB新增到主螢幕,從主螢幕開啟後允許通知。

用五個步驟做出人工智慧

每個專案都要經過同樣的五個步驟:準備、與視覺化、資料前處理、和模型。在裡做一個小小的垃圾訊息過濾器,把五個步驟全部走一遍。

雜亂的文字碎片進入一台過濾機器,重複的內容和碎屑掉了出來,最後出來一疊整齊乾淨的資料
2

資料分析與視覺化

改動任何東西之前,先看。分析就是回答一些簡單的問題:一共有多少列?有沒有空的文字?每個來源怎麼寫標籤?訊息有多長?同一則訊息有沒有出現兩次?

視覺化把數字變成圖,讓你一眼就能看出問題。這裡的圖表直接在儲存格的輸出裡用方塊字元畫出來:長條越長,數字越大。

這一步的結果不是資料檔案,而是一張簡短的規則清單。每條規則都來自你看到的東西。

一步一步看邏輯

  1. 找出空文字 text == ""
  2. 按來源數標籤 Counter
  3. 畫長條圖 █ bar()
  4. 找出重複 n > 1
  5. 寫下規則 notes.md

Counter 數出每個值出現了多少次。按 source 分組後可以看到,sms 寫 1 和 0,mail 寫 ham 和 spam(有時寫成 SPAM 或 Spam),chat 寫 yes 和 no。

bar 函式畫出「值 / 最大值 × 30」個方塊,所以最長的長條總是 30 個方塊。垃圾訊息比例圖用一條暫時的規則把標籤變成「是不是垃圾訊息」;真正的規則在第 3 步再寫。

找重複時,先把每段文字變成小寫,空格統一成一個,所以 "See you at lunch" 和 "see you at lunch" 算作同一則訊息。

用真實工具做同樣的事

用 pandas 的話,isnull().sum() 找出空值,describe() 給出統計數字,pivot_table() 做出標籤表,seaborn 畫出圖表。

  • df.isnull().sum()
  • df.describe()
  • df.pivot_table()
  • sns.countplot()
  • sns.barplot()

動手輸入並實驗

打開 2-analyze.ipynb,選擇 Run ▸ Run All Cells。然後把你發現的東西當作規則寫進一個新檔案:File ▸ New ▸ File,再把它改名為 notes.md。

2-analyze.ipynb本筆記本的完整程式碼
# Step 2. Data analysis and visualization — look at the data with numbers and bar charts.
import csv
from collections import Counter

with open("data/all.csv", newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))


def bar(name, value, top, width=30):
    """One line of a bar chart drawn with text."""
    print(f"  {name:8} {'█' * round(value / top * width)} {value}")


print("rows:", len(rows))

# 1) Missing values: rows whose text is empty
empty = [r for r in rows if r["text"].strip() == ""]
print("empty text:", len(empty))

# 2) Rows by source (chart)
print("\nrows by source")
by_source = Counter(r["source"] for r in rows)
for source, count in by_source.items():
    bar(source, count, max(by_source.values()))

# 3) Label values by source — every source writes the label differently
print("\nlabel values by source")
for source in by_source:
    labels = Counter(r["label"] for r in rows if r["source"] == source)
    print(f"  {source:5}", dict(labels))

# 4) Spam ratio by source (chart, with a temporary label rule)
print("\nspam ratio by source (%)")
for source in by_source:
    part = [r for r in rows if r["source"] == source]
    spam = sum(1 for r in part if r["label"].lower() in ("1", "spam", "yes"))
    bar(source, round(spam / len(part) * 100), 100)

# 5) Text length (chart)
lengths = [len(r["text"]) for r in rows if r["text"].strip()]
print("\ntext length: min", min(lengths), "avg", round(sum(lengths) / len(lengths)), "max", max(lengths))
groups = Counter(min(n // 20, 4) for n in lengths)
names = ["0-19", "20-39", "40-59", "60-79", "80+"]
for g in range(5):
    bar(names[g], groups[g], max(groups.values()))

# 6) Duplicates: the same text more than once
texts = Counter(" ".join(r["text"].lower().split()) for r in rows if r["text"].strip())
duplicates = {t: n for t, n in texts.items() if n > 1}
print("\nduplicate texts:", len(duplicates))
for text, n in duplicates.items():
    print(f"  {n}x {text}")
Run ▸ Run All Cells你應該看到的結果
rows: 183
empty text: 3

rows by source
  sms      ██████████████████████████████ 65
  mail     ███████████████████████████ 59
  chat     ███████████████████████████ 59

label values by source
  sms   {'1': 28, '0': 37}
  mail  {'ham': 33, 'spam': 24, 'SPAM': 1, 'Spam': 1}
  chat  {'no': 32, 'yes': 27}

spam ratio by source (%)
  sms      █████████████ 43
  mail     █████████████ 44
  chat     ██████████████ 46

text length: min 1 avg 39 max 82
  0-19     ███████ 17
  20-39    ██████████████████████████████ 75
  40-59    ██████████████████████████████ 74
  60-79    █████ 13
  80+       1

duplicate texts: 3
  3x congratulations! you won a free iphone. click the link to claim it now
  3x see you at lunch
  2x call me now

完成標準

你的 notes.md 裡至少有下面四條規則,每條都根據你看到的數字:

  • 去掉空的和很短的文字(有 3 則空文字,最短的文字只有 1 個字元)。
  • 把每個標籤都變成 1(垃圾訊息)或 0(不是垃圾訊息):1、spam、yes 和 0、ham、no,不分大小寫。
  • 重複的文字只留一份,標籤互相矛盾的文字去掉("call me now" 在一個來源裡是垃圾訊息,在另一個來源裡是正常訊息)。
  • 切分資料時讓每一部分的垃圾訊息比例差不多(每個來源都大約是 45%)。
遇到問題時

如果長條圖看起來是亂的,可能是字型裡沒有方塊字元;重要的是每個長條最後的數字。如果沒看到重複,檢查一下數之前有沒有把文字變成小寫。如果 data/all.csv 出現 FileNotFoundError,表示還沒有執行 1-prepare.ipynb。

可預約時間已過