MCPcopy Index your code
hub / github.com/clips/pattern / skewness

Method skewness

pattern/vector/__init__.py:1732–1741  ·  view source on GitHub ↗

Yields 0.0 if the trained classes are evenly distributed. Yields > +1.0 or < -1.0 if the training data is highly skewed.

(self)

Source from the content-addressed store, hash-verified

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).

Callers 1

test_skewnessMethod · 0.80

Calls 4

sumFunction · 0.85
lenFunction · 0.85
momentFunction · 0.85
iteritemsMethod · 0.80

Tested by 1

test_skewnessMethod · 0.64