A dictionary of (feature, weight)-items of the features (terms, words) in a Document. A vector can be used to compare the document to another document with a distance metric. For example, vectors with 2 features (x, y) can be compared using 2D Euclidean distance.
(self, *args, **kwargs)
| 614 | id = 1 |
| 615 | |
| 616 | def __init__(self, *args, **kwargs): |
| 617 | """ A dictionary of (feature, weight)-items of the features (terms, words) in a Document. |
| 618 | A vector can be used to compare the document to another document with a distance metric. |
| 619 | For example, vectors with 2 features (x, y) can be compared using 2D Euclidean distance. |
| 620 | Vectors that represent text documents can be compared using cosine similarity. |
| 621 | """ |
| 622 | self.id = Vector.id; Vector.id+=1 # Unique ID. |
| 623 | self.weight = kwargs.pop("weight", TF) # Vector weights based on tf, tf-idf, binary? |
| 624 | self._norm = None |
| 625 | readonlydict.__init__(self, *args, **kwargs) |
| 626 | |
| 627 | @property |
| 628 | def features(self): |