-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathensemble.py
More file actions
34 lines (30 loc) · 1.01 KB
/
ensemble.py
File metadata and controls
34 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""
EnsembleClassider class takes classifier as parameter
and ensemble them together
@return
classification based on majority of votes
@author: Niraj Gautam
"""
from nltk.classify import ClassifierI
from statistics import mode
# Defininig the ensemble model class
class EnsembleClassifier(ClassifierI):
def __init__(self, *classifiers):
self._classifiers = classifiers
# returns the classification based on majority of votes
def classify(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
return mode(votes)
# a simple measurement the degree of confidence in the classification
def confidence(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
choice_votes = votes.count(mode(votes))
conf = choice_votes / len(votes)
return conf