Python Code for Text Classification
1 import gzip 2 import numpy as np 3 for (x1, _) in test_set: 4 Cx1 = len(gzip.compress(x1.encode())) 5 distance_from_x1 = [] 6 for (x2, _) in training_set: 7 Cx2 = len(gzip.compress(x2.encode())) 8 x1x2 = " ".join([x1, x2]) 9 Cx1x2 = len(gzip.compress(x1x2.encode())) 10 ncd = (Cx1x2 - min(Cx1, Cx2)) / max( Cx1, Cx2) 11 distance_from_x1.append(ncd) 12 sorted_idx = np.argsort(np.array( distance_from_x1)) 13 top_k_class = training_set[sorted_idx [:k], 1] 14 predict_class = max(set(top_k_class), key=top_k_class.count) Listing 1: Python Code for Text Classification with gzip.
The image shows a monospaced Python code listing that classifies text by comparing gzip compression distances between test and training examples, then choosing the most common class among the nearest matches. The joke is the absurdly technical appearance of the code and its use as a reaction to overly complicated machine-learning or programming discussions. EN: The image shows a monospaced Python code listing that classifies text by comparing gzip compression distances between test and training examples, then choosing the most common class among the nearest matches. The joke is the absurdly technical appearance of the code and its use as a reaction to overly complicated machine-learning or programming discussions.
code listing / листинг кодаPython code / код Pythonline numbers / номера строкcomputer text / компьютерный текстgzip compression / сжатие gzipnumpy library / библиотека numpymathematical formula / математическая формулаbrackets / скобкиwhite background / белый фонmonospaced font / моноширинный шрифт
- @ithueti / 9805 2023-07-13
- Type
- image
- Size
- 732×800 · 102.1 KiB
- Mood
- технический абсурд
- Language
- en
- Added