SONUB 首页

只有我们的团队会阅读。请不要填写密码或卡号。

谢谢!每条意见我们都会阅读,并用来决定下一步改进什么。

关闭 发送
ZH 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。

可预约时间已过