truelearn.learning.InterestClassifier#

class truelearn.learning.InterestClassifier(*, learner_model: Optional[LearnerModel] = None, threshold: float = 0.5, init_skill: float = 0.0, def_var: float = 0.5, beta: float = 0.0, tau: float = 0.0, draw_proba_type: str = 'dynamic', draw_proba_static: Optional[float] = None, draw_proba_factor: float = 0.1, decay_func_type: str = 'short', decay_func_factor: float = 0.0)[source]#

Bases: InterestNoveltyKnowledgeBaseClassifier

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

Note, the knowledge component in this context means the interest of the learner/learnable unit.

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 a higher skill than the depth of the resource, which means that the learner wins the game.

During the prediction process, the classifier uses cumulative density function of normal distribution to calculate the probability that the learner engages in the learning event. It calculates the probability of getting x in a Normal Distribution N(0, std) where x is the difference between the learner’s skill (mean) and the learnable unit’s skill (mean) and std is the standard deviation of the new normal distribution as a result of subtracting the two old normal distribution (learner and learnable unit). In TrueSkill’s terminology, this calculates the win probability that the learner will win the content.

Examples

>>> from truelearn.learning import InterestClassifier
>>> from truelearn.models import EventModel, Knowledge, KnowledgeComponent
>>> interest_classifier = InterestClassifier()
>>> interest_classifier
InterestClassifier()
>>> # prepare an event model
>>> knowledges = [
...     Knowledge({1: KnowledgeComponent(mean=0.57, variance=1e-9)}),
...     Knowledge({
...         2: KnowledgeComponent(mean=0.07, 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, 1024, 5381]
>>> events = [
...     EventModel(knowledge, time)
...     for knowledge, time in zip(knowledges, times)
... ]
>>> engage_stats = [False, True, False]
>>> for event, engage_stats in zip(events, engage_stats):
...     interest_classifier = interest_classifier.fit(event, engage_stats)
...     print(
...         interest_classifier.predict(event),
...         interest_classifier.predict_proba(event)
...     )
...
True 0.87299...
True 0.69146...
True 0.91941...
>>> interest_classifier.get_params()  
{..., 'learner_model': LearnerModel(knowledge=Knowledge(knowledge={1: KnowledgeComponent(mean=1.3651..., variance=0.07128..., ...), ...}), ...}

Methods

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

Init InterestClassifier 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.0, tau: float = 0.0, draw_proba_type: str = 'dynamic', draw_proba_static: Optional[float] = None, draw_proba_factor: float = 0.1, decay_func_type: str = 'short', decay_func_factor: float = 0.0) None[source]#

Init InterestClassifier 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.

  • 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.

  • decay_func_type – A str specifying the type of the interest decay function. The allowed values are “short” and “long”.

  • decay_func_factor – A factor (>=0) that will be used in both short and long interest decay function. Defaults to 0, which disables the interest decay function.

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.