SONUB home

Only our team reads this. Don't include passwords or card numbers.

Thank you! We read every message and use it to decide what to improve next.

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

How to enable notifications

Notifications are unavailable in this browser or on this address. Try a supported browser on the secure SONUB site.

If notifications are blocked, allow them in your browser settings.

  1. Open the site controls beside the address bar, or your browser’s site settings. Set Notifications for this site to Allow.
  2. In your device settings, allow notifications for your browser and check Do Not Disturb or Focus.
  3. Return to SONUB and reload the page. Once notifications are on, the bell disappears.

On iPhone or iPad, add SONUB to your Home Screen, open it there, then allow notifications.

Build AI in five steps

Every project goes through the same five steps: preparation, & visualization, data , and model evaluation. Build a small spam filter in your and walk through all five.

Messy pieces of writing go into a filter machine, duplicates and scraps fall out, and a neat stack of clean data comes out
2

Data analysis & visualization

Before you change anything, look. Analysis answers simple questions: How many rows are there? Is any text empty? How does each source write its labels? How long are the messages? Is the same message there twice?

Visualization turns the numbers into a picture so you can see a problem at a glance. Here the charts are drawn with block characters right in the cell output: the longer the bar, the bigger the number.

The result of this step is not a file of data but a short of rules. Each rule comes from something you saw.

The logic, step by step

  1. Find empty text text == ""
  2. Count labels per source Counter
  3. Draw bar charts █ bar()
  4. Find duplicates n > 1
  5. Write the rules notes.md

Counter counts how often each value appears. Grouping by source shows that sms writes 1 and 0, mail writes ham and spam (and sometimes SPAM or Spam), and chat writes yes and no.

The bar draws value / largest value × 30 blocks, so the largest bar is always 30 blocks long. The spam ratio chart uses a temporary rule to turn the labels into spam or not; the real rule is written in step 3.

For duplicates, each text is first made lower case with single spaces, so "See you at lunch" and "see you at lunch" count as the same message.

The same job with real-world tools

With pandas, isnull().sum() finds empty values, describe() gives the statistics, pivot_table() makes the label table, and seaborn draws the charts.

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

Type and try

Open 2-analyze.ipynb and choose Run ▸ Run All Cells. Then write what you found as rules in a new file: File ▸ New ▸ File, renamed to notes.md.

2-analyze.ipynbThe full code of this notebook
# 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 CellsWhat you should see
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

Done when

Your notes.md has at least these four rules, each based on a number you saw:

  • Drop empty and very short texts (3 empty texts, the shortest text is 1 character).
  • Turn every label into 1 (spam) or 0 (not spam): 1, spam, yes and 0, ham, no, ignoring upper and lower case.
  • Keep one copy of a duplicated text, and drop a text that has different labels ("call me now" is spam in one source and normal in another).
  • Split the data so that each part has about the same spam ratio (it is about 45% in every source).
If you get stuck

If the bars look broken, the font may be missing the block character; the numbers at the end of each bar are what count. If you see no duplicates, check that you lower-cased the text before counting. FileNotFoundError for data/all.csv means 1-prepare.ipynb has not been run yet.

Booking time has passed