Skip to content

Commit

Permalink
Adding guess prediction when an instance is not covered for any rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vauxgomes committed Nov 29, 2020
1 parent ea6321f commit d427565
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lad/rulegenerator/eager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,31 @@ def predict(self, X):
predictions = []
for i in range(X.shape[0]):
if i not in weights:
predictions.append(2)
predictions.append(self.__most_frequent_label)
else:
predictions.append(max(weights[i], key=weights[i].get))

return np.array(predictions)

def predict_proba(self, X):
predictions = self.predict(X)
output = np.zeros((len(X), self.__nunique_y))
output = np.zeros((len(X), self.__labels))

for i in range(len(X)):
output[i][predictions[i]] = 1

return output

def fit(self, Xbin, y):
#
unique, counts = np.unique(y, return_counts=True)

#
self.__rules.clear()
self.__nunique_y = len(np.unique(y))
self.__labels = len(np.unique(y))
self.__most_frequent_label = unique[np.argmax(counts)]

#
rules_weights = []
labels_weights = {}

Expand Down

0 comments on commit d427565

Please sign in to comment.