Yields 0.0 if the trained classes are evenly distributed. Yields > +1.0 or < -1.0 if the training data is highly skewed.
(self)
| 1730 | |
| 1731 | @property |
| 1732 | def skewness(self): |
| 1733 | """ Yields 0.0 if the trained classes are evenly distributed. |
| 1734 | Yields > +1.0 or < -1.0 if the training data is highly skewed. |
| 1735 | """ |
| 1736 | def moment(a, m, k=1): |
| 1737 | return sum([(x-m)**k for x in a]) / (len(a) or 1) |
| 1738 | # List each training instance by an int that represents its class: |
| 1739 | a = list(chain(*([i] * v for i, (k, v) in enumerate(self._classes.iteritems())))) |
| 1740 | m = float(sum(a)) / len(a) # mean |
| 1741 | return moment(a, m, 3) / (moment(a, m, 2) ** 1.5 or 1) |
| 1742 | |
| 1743 | def train(self, document, type=None): |
| 1744 | """ Trains the classifier with the given document of the given type (i.e., class). |