truelearn.learning.NoveltyClassifier#

class truelearn.learning.NoveltyClassifier(*, learner_model: Optional[LearnerModel] = None, threshold: float = 0.5, init_skill: float = 0.0, def_var: float = 0.5, beta: float = 0.35, tau: float = 0.0, positive_only: bool = False, draw_proba_type: str = 'dynamic', draw_proba_static: Optional[float] = None, draw_proba_factor: float = 0.1)[source]#

Bases: InterestNoveltyKnowledgeBaseClassifier

A classifier that models the learner’s knowledge and makes prediction based on the knowledge.

During the training process, the classifier uses the idea of game matching established in TrueSkill. It represents the learning process as a game of two teams. One team consists of all the knowledge components from the learnable unit, and the other consists of all the corresponding knowledge components from the learner. Then, the classifier uses the given label to update the knowledge components of the learner.

The update of knowledge components is based on the assumption that if the learner engages with the learnable unit, it means that the learner has skills similar to the depth of the resource, which means that the game is drawn.

During the prediction process, the classifier uses the TrueSkill quality mechanism to evaluate the quality of the game. The idea is that if the quality of the game is high, it means that neither side can easily win the other. Thus, a high quality game means that learners are likely to engage with learnable units based on our assumption.

Examples

>>> from truelearn.learning import NoveltyClassifier
>>> from truelearn.models import EventModel, Knowledge, KnowledgeComponent
>>> novelty_classifier = NoveltyClassifier()
>>> novelty_classifier
NoveltyClassifier()
>>> # prepare an event model
>>> knowledges = [
...     Knowledge({1: KnowledgeComponent(mean=0.57, variance=1e-9)}),
...     Knowledge({
...         2: KnowledgeComponent(mean=0.37, variance=1e-9),
...         3: KnowledgeComponent(mean=0.41, variance=1e-9),
...     }),
...     Knowledge({
...         1: KnowledgeComponent(mean=0.24, variance=1e-9),
...         3: KnowledgeComponent(mean=0.67, variance=1e-9),
...     }),
... ]
>>> events = [EventModel(knowledge) for knowledge in knowledges]
>>> engage_stats = [False, True, False]
>>> for event, engage_stats in zip(events, engage_stats):
...     novelty_classifier = novelty_classifier.fit(event, engage_stats)
...     print(
...         novelty_classifier.predict(event),
...         novelty_classifier.predict_proba(event)
...     )
...
False 0.36475...
True 0.63319...
False 0.37305...
>>> novelty_classifier.get_params()  
{..., 'learner_model': LearnerModel(knowledge=Knowledge(knowledge={1: KnowledgeComponent(mean=-0.36715..., variance=0.29902..., ...), ...}), ...}

Methods

__init__(*[, learner_model, threshold, ...])

Init NoveltyClassifier 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_model: Optional[LearnerModel] = None, threshold: float = 0.5, init_skill: float = 0.0, def_var: float = 0.5, beta: float = 0.35, tau: float = 0.0, positive_only: bool = False, draw_proba_type: str = 'dynamic', draw_proba_static: Optional[float] = None, draw_proba_factor: float = 0.1) None[source]#

Init NoveltyClassifier object.

Parameters:
  • * – Use to reject positional arguments.

  • learner_model – A representation of the learner.

  • threshold – A float that determines the classification threshold.

  • init_skill – The initial mean of the learner’s knowledge component. It will be used when the learner interacts with knowledge components for the first time.

  • def_var – The initial variance (>0) of the learner’s knowledge component. It will be used when the learner interacts with knowledge components for the first time.

  • beta – The distance which guarantees about 76% chance of winning. The recommended value is sqrt(def_var) / 2.

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

  • positive_only – A bool indicating whether the classifier only updates the learner’s knowledge when encountering a positive label.

  • draw_proba_type – A str specifying the type of the draw probability. It could be either “static” or “dynamic”. The “static” probability type requires an additional parameter draw_proba_static. The “dynamic” probability type calculates the draw probability based on the learner’s previous engagement stats with educational resources.

  • draw_proba_static – The global draw probability (>=0).

  • draw_proba_factor – A factor (>=0) that will be applied to both static and dynamic draw probability.

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() LearnerModel[source]#

Get the learner model associated with this classifier.

Returns:

A learner model associated with 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.