Text Mining

Text mining extracts knowledge from unstructured text such as emails, reviews and news. Steps: tokenisation, removal of stop words, stemming (running to run), then representation as a bag of words and weighting by TF-IDF: TF is how often a term occurs in a document, and IDF = log(N / df) lowers the weight of terms that occur in many documents. Tasks: text classification, sentiment analysis, summarisation and topic modelling.

Web Mining

  • Web content mining: extracts knowledge from page text, images and video (search and classification).
  • Web structure mining: studies the links between pages, as in PageRank and HITS.
  • Web usage mining: analyses server logs and clicks to learn user behaviour, used for personalisation and site design.

Big Data Analytics

Hadoop stores data in the distributed file system HDFS and processes it with MapReduce (map, shuffle, reduce) on clusters. Spark processes data in memory, so it is much faster for repeated work such as machine learning, and has libraries for SQL, streaming and ML. NoSQL databases (key-value, document, column-family and graph, for example MongoDB, Cassandra and Neo4j) store large, varied data with flexible schemas and scale horizontally.

Anomaly Detection

An anomaly (outlier) is an object that differs greatly from the rest. Methods: statistical (a z-score beyond 2 or 3), distance-based (far from neighbours), density-based, clustering-based (small or distant clusters) and classification-based. Use cases: fraud, intrusion detection, fault detection and health monitoring.

Case Study with Weka

Weka is a free Java tool with a graphical interface. A typical session: open an ARFF or CSV file in the Preprocess tab, clean and filter the data, choose a classifier such as J48 (C4.5) or Naive Bayes in the Classify tab with 10-fold cross-validation, read the accuracy and confusion matrix, then try Cluster (SimpleKMeans) and Associate (Apriori).

Definition: Anomaly. A data object that deviates so much from the rest of the data that it appears to have been produced by a different process.

Table 2.5: Web mining types

Type Data used Example use
Content Page text and media Search ranking
Structure Hyperlinks PageRank
Usage Server logs, clicks Recommendation

Example 2.5: Z-score anomaly detection

Problem: Ten sensor readings are 10, 12, 11, 13, 12, 95, 11, 10, 12 and 13. Using a z-score threshold of 2, find the anomaly.

Solution:

  1. Mean = 199 / 10 = 19.9.
  2. The squared deviations sum to 6276.9, so the variance is 627.69 and the standard deviation is 25.05.
  3. For 95: z = (95 - 19.9) / 25.05 = 3.0.
  4. For 10: z = (10 - 19.9) / 25.05 = -0.40, well within the threshold.

Result: Only 95 has |z| above 2 and is reported as the anomaly.

from math import log10, sqrt
vals = [10, 12, 11, 13, 12, 95, 11, 10, 12, 13]
m = sum(vals) / len(vals)
sd = sqrt(sum((v - m) ** 2 for v in vals) / len(vals))
for v in vals:
    if abs((v - m) / sd) > 2:
        print("Anomaly:", v, "z =", round((v - m) / sd, 2))
docs = ["data mining finds patterns", "data warehouse stores data",
        "mining text"]
words = docs[1].split()
tf = words.count("data") / len(words)
df = sum("data" in d.split() for d in docs)
idf = log10(len(docs) / df)
print("TF", tf, "IDF", round(idf, 4), "TF-IDF", round(tf * idf, 4))

Output

Anomaly: 95 z = 3.0
TF 0.5 IDF 0.1761 TF-IDF 0.088

Common mistakes

  • Treating PageRank as content mining; it uses link structure.
  • Keeping stop words, which dominate counts but carry little meaning.
  • Declaring every outlier an error; it may be the most important case, such as fraud.
  • Running Spark or Hadoop for small data that fits one machine.

Key takeaways

  • Text mining: tokenise, remove stop words, stem, weight by TF-IDF.
  • Web mining: content, structure, usage.
  • Hadoop uses HDFS and MapReduce; Spark works in memory.
  • Anomalies are found by z-score, distance, density or clustering.

Practice questions

  1. What are the three types of web mining?
  2. What does IDF do?
  3. Why is Spark faster than Hadoop MapReduce for repeated work?

Answers to the practice questions

  1. Content, structure and usage mining.
  2. Lowers the weight of terms that occur in many documents.
  3. It keeps data in memory instead of writing to disk after each step.

Sources

  • Official BCA syllabus Data Warehousing and Mining, course code 25BCA406DS03, Unit II