truelearn.learning.INKClassifier#

class truelearn.learning.INKClassifier(*, learner_meta_weights: Optional[LearnerMetaWeights] = None, novelty_classifier: Optional[Union[NoveltyClassifier, Dict]] = None, interest_classifier: Optional[Union[InterestClassifier, Dict]] = None, threshold: float = 0.5, tau: float = 0.0, greedy: bool = False)[source]#

Bases: BaseClassifier

A meta-classifier that combines KnowledgeClassifier and InterestClassifier.

During the training process, the meta-classifier individually trains the KnowledgeClassifier and the InterestClassifier. After that, the meta-classifier trains a set of weights by again using the ideas of team matching. One team consists of the weights of the knowledge, interest and bias, and the other team consists of the threshold. Then, the meta-classifier uses the given label to adjust the weights accordingly.

During the prediction process, the meta-classifier individually uses the predict function of the KnowledgeClassifier and InterestClassifier. Then, it combines them by using the weights.

Examples

>>> from truelearn.learning import INKClassifier
>>> from truelearn.models import EventModel, Knowledge
>>> from truelearn.models import KnowledgeComponent, LearnerMetaWeights
>>> ink_classifier = INKClassifier()
>>> ink_classifier
INKClassifier()
>>>
>>> # use custom weights
>>> weights = LearnerMetaWeights.Weights(mean=0.0, variance=0.5)
>>> meta_weights = LearnerMetaWeights(novelty_weights=weights)
>>> ink_classifier = INKClassifier(learner_meta_weights=meta_weights)
>>>
>>> # prepare an event model
>>> knowledges = [
...     Knowledge({1: KnowledgeComponent(mean=0.15, variance=1e-9)}),
...     Knowledge({
...         2: KnowledgeComponent(mean=0.87, variance=1e-9),
...         3: KnowledgeComponent(mean=0.18, variance=1e-9),
...     }),
...     Knowledge({
...         1: KnowledgeComponent(mean=0.34, variance=1e-9),
...         3: KnowledgeComponent(mean=0.15, variance=1e-9),
...     }),
... ]
>>> times = [0, 10514, 53621]
>>> events = [
...     EventModel(knowledge, time)
...     for knowledge, time in zip(knowledges, times)
... ]
>>> engage_stats = [True, False, True]
>>> for event, engage_stats in zip(events, engage_stats):
...     ink_classifier = ink_classifier.fit(event, engage_stats)
...     print(
...         ink_classifier.predict(event),
...         ink_classifier.predict_proba(event)
...     )
...
True 0.64387...
False 0.42658...
True 0.65406...
>>> ink_classifier.get_params(deep=False)  
{...'learner_meta_weights': LearnerMetaWeights(novelty_weights=Weights(mean=0.20787..., variance=0.45787...), interest_weights=Weights(mean=0.66924..., variance=0.42672...), bias_weights=Weights(mean=0.13029..., variance=0.39582...))...}

Methods

__init__(*[, learner_meta_weights, ...])

Init INKClassifier object.

fit(x, y)

Train the model.

get_learner_model()

Get the learner model associated with this classifier.

get_params([deep])

Get parameters for this Classifier.

predict(x)

Predict whether the learner will engage in the learning event.

predict_proba(x)

Predict the probability that the learner will engage in the learning event.

set_params(**args)

Set the parameters of this Classifier.

__init__(*, learner_meta_weights: Optional[LearnerMetaWeights] = None, novelty_classifier: Optional[Union[NoveltyClassifier, Dict]] = None, interest_classifier: Optional[Union[InterestClassifier, Dict]] = None, threshold: float = 0.5, tau: float = 0.0, greedy: bool = False) None[source]#

Init INKClassifier object.

Parameters:
  • * – Use to reject positional arguments.

  • learner_meta_weights – The novelty/interest/bias weights.

  • novelty_classifier – The NoveltyClassifier. It can be a NoveltyClassifier object or a dictionary of parameters that can be used to instantiate a NoveltyClassifier object.

  • interest_classifier – The InterestClassifier. It can be an InterestClassifier object or a dictionary of parameters that can be used to instantiate an InterestClassifier object.

  • threshold – A float that determines the classification threshold.

  • tau – The dynamic factor of learner’s learning process. It’s used to avoid the halting of the learning process.

  • greedy – A bool indicating whether meta-learning should take the greedy approach. In the greedy approach, only incorrect predictions lead to the update of the weights.

Raises:
  • TrueLearnTypeError – Types of parameters do not satisfy their constraints.

  • TrueLearnValueError – Values of parameters do not satisfy their constraints.

fit(x: EventModel, y: bool) Self[source]#

Train the model.

Parameters:
  • x – A representation of a learning event.

  • y – A bool indicating whether the learner engages in the learning event.

Returns:

The updated classifier object.

get_learner_model() Tuple[LearnerModel, LearnerModel, LearnerMetaWeights][source]#

Get the learner model associated with this classifier.

Returns:

A tuple (novelty_learner, interest_learner, meta_weights) where novelty_learner is the learner model associated with the NoveltyClassifier, interest_learner is the learner model associated with the interestClassifier, meta_weights is the weights used in this classifier.

get_params(deep: bool = True) Dict[str, Any][source]#

Get parameters for this Classifier.

Parameters:

deep – If True, will return the parameters for this Classifier and contained sub-objects that inherit BaseClassifier class.

Returns:

A dict mapping variable names to the corresponding objects.

predict(x: EventModel) bool[source]#

Predict whether the learner will engage in the learning event.

Parameters:

x – A representation of a learning event.

Returns:

A bool indicating whether the learner will engage in the learning event.

predict_proba(x: EventModel) float[source]#

Predict the probability that the learner will engage in the learning event.

Parameters:

x – A representation of a learning event.

Returns:

A float indicating the probability that the learner will engage in the learning event.

set_params(**args) Self[source]#

Set the parameters of this Classifier.

A value can be reset only if the given parameter has the same type as the original value.

Parameters:

**args – Keyword arguments. The key should match the parameter names of the classifier. The arguments should have the correct type.

Returns:

The updated classifier.

Raises:
  • TrueLearnTypeError – Types of parameters do not satisfy their constraints.

  • TrueLearnValueError – Values of parameters do not satisfy their constraints.

  • InvalidArgumentError – If the given argument name is not in the class.