Skip to content

Weighted deterministic

matchlab.models.linkers.weighteddeterministic

A linking methodology that applies different weights to field comparisons.

Classes:

WeightedComparison

Bases: BaseModel


              flowchart TD
              matchlab.models.linkers.weighteddeterministic.WeightedComparison[WeightedComparison]

              

              click matchlab.models.linkers.weighteddeterministic.WeightedComparison href "" "matchlab.models.linkers.weighteddeterministic.WeightedComparison"
            

A comparison condition, and the weight it contributes to a pair's score.

Methods:

Attributes:

comparison class-attribute instance-attribute

comparison: SQLCondition = Field(description='\n            A valid ON clause comparing fields between the left and the right data.\n\n            Qualify every column with `l` or `r`. For example:\n\n            "l.company_name = r.company_name"\n        ')

weight class-attribute instance-attribute

weight: float = Field(description='\n            A weight to give this comparison. Use 1 for all comparisons to give\n            uniform weight to each.\n        ')

validate_comparison classmethod

validate_comparison(v: SQLCondition) -> SQLCondition

Validate the comparison string.

WeightedDeterministicLinker

Bases: Linker


              flowchart TD
              matchlab.models.linkers.weighteddeterministic.WeightedDeterministicLinker[WeightedDeterministicLinker]
              matchlab.models.linkers.base.Linker[Linker]

                              matchlab.models.linkers.base.Linker --> matchlab.models.linkers.weighteddeterministic.WeightedDeterministicLinker
                


              click matchlab.models.linkers.weighteddeterministic.WeightedDeterministicLinker href "" "matchlab.models.linkers.weighteddeterministic.WeightedDeterministicLinker"
              click matchlab.models.linkers.base.Linker href "" "matchlab.models.linkers.base.Linker"
            

Scores a pair by the weighted share of comparisons it matches on.

Methods:

  • prepare

    No preparation needed.

  • link

    Score each pair by summed matching weight over total weight.

Attributes:

version class-attribute

version: int = 1

weighted_comparisons class-attribute instance-attribute

weighted_comparisons: list[WeightedComparison] = Field(description='A list of tuples in the form of a comparison, and a weight.')

threshold class-attribute instance-attribute

threshold: float = Field(description='\n            The score above which matches will be kept. \n            \n            Inclusive, so a value of 1 will keep only exact matches across all \n            comparisons.\n        ', ge=0, le=1)

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='forbid', frozen=True)

left_id class-attribute instance-attribute

left_id: Literal['id'] = Field(default='id', description='The unique ID field in the left data')

right_id class-attribute instance-attribute

right_id: Literal['id'] = Field(default='id', description='The unique ID field in the right data')

prepare

prepare(left: DataFrame, right: DataFrame) -> None

No preparation needed.

link(left: DataFrame, right: DataFrame) -> DataFrame

Score each pair by summed matching weight over total weight.

Keeps only pairs scoring at or above settings.threshold.