Considering the example:
train = pd.DataFrame(
{
"color": ["red", "red", "blue", "blue", "green", "green"],
"y": [0, 0, 1, 1, 0, 0],
}
)
clf = RuleClassifier(minsupp_new=1, enable_pruning=False)
clf.fit(train[["color"]], train["y"])
the train mapping is {'red': 0, 'green': 1, 'blue': 2}. Rules induced are:
IF color = {green} THEN y = {0}
IF color = {red} THEN y = {0}
IF color = {blue} THEN y = {1}
Then - when we define a test dataset:
test = pd.DataFrame({"color": ["blue", "blue"]})
and call clf.get_coverage_matrix(test) and clf.predict(test) we get incorrect values, in order: [[0 1 0], [0 1 0]] and [0. 0.] - mapping for test dataset is {'blue': 0} - and it is not updated during either call. Both predict and get_coverage_matrix create an example set with ExampleSetFactory.make method - which passes raw values (except NaN - replaced with None) to java DataTable constructor.
After example set creation, the get_coverage_matrix doesn't update mapping of the example set based on self.model._java_object - coverage is calculated for each rule with rule._java_object.coversUnlabelled method.
The predict method calls self.model._java_object.apply (java object is an object of ClassificationRuleSet in this case) - which internally calls exampleSet.updateMapping - however this one updates only DataTable metadata - but doesn't update encoded indices stored in the DataTable.
So in the discussed case, the encoded test table for both predict and get_coverage_matrix still stays [[0.0], [0.0]] - which hits 2nd rule instead of the 3rd (cause in train - red was encoded as 0).
Considering the example:
the train mapping is
{'red': 0, 'green': 1, 'blue': 2}. Rules induced are:Then - when we define a test dataset:
and call
clf.get_coverage_matrix(test)andclf.predict(test)we get incorrect values, in order:[[0 1 0], [0 1 0]]and[0. 0.]- mapping for test dataset is{'blue': 0}- and it is not updated during either call. Both predict and get_coverage_matrix create an example set with ExampleSetFactory.make method - which passes raw values (except NaN - replaced with None) to java DataTable constructor.After example set creation, the
get_coverage_matrixdoesn't update mapping of the example set based on self.model._java_object - coverage is calculated for each rule withrule._java_object.coversUnlabelledmethod.The
predictmethod callsself.model._java_object.apply(java object is an object of ClassificationRuleSet in this case) - which internally callsexampleSet.updateMapping- however this one updates only DataTable metadata - but doesn't update encoded indices stored in the DataTable.So in the discussed case, the encoded test table for both
predictandget_coverage_matrixstill stays[[0.0], [0.0]]- which hits 2nd rule instead of the 3rd (cause in train - red was encoded as 0).