-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaximumLikelihoodModel.py
53 lines (37 loc) · 1.52 KB
/
MaximumLikelihoodModel.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numbers
import numpy as np
import sklearn
from sklearn.utils import check_X_y, check_array, column_or_1d
from sklearn.utils.multiclass import check_classification_targets
from sklearn.externals.joblib import Parallel, \
delayed # For parallel computing TODO: check if we need to be parallel or not
from sklearn.utils.validation import has_fit_parameter, check_is_fitted
class MLHClassifier():
"""Base class for ordinal meta-classifier.
"""
def __init__(self):
return self
def fit(self, X, y, sample_weight=None):
return self
def _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):
return self
def predict(self, X):
X = check_array(X, accept_sparse=['csr', 'csc'])
# ---------------------------------------------Our CODE
n_samples = X.shape[0]
prediction = np.zeros((n_samples, 1))
for i in range(0, n_samples):
if X[i, "Scenario"] == "C":
if X[i, "VoterType"] == "LB":
prediction[i] = 2 # Q' vote
else:
prediction[i] = 1 # Q vote
else:
if X[i, "Scenario"] in ["E", "F"]:
if X[i, "VoterType"] == "TRT":
prediction[i] = 1 # Q vote
else:
prediction[i] = 2 # Q' vote
else:
prediction[i] = 1 # Q vote
return prediction