Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clustering allows match weight args not just match probability #2454

Merged
merged 18 commits into from
Nov 26, 2024

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Oct 7, 2024

This PR allows all clustering functions to take a match weight threshold argument instead of a match probability threshold.

You can now provide either (but not both), which makes the behaviour consistent with e.g. inference.predict()

@RobinL
Copy link
Member Author

RobinL commented Nov 25, 2024

Possible chart showing how num clusters varies with mw

import altair as alt
import pandas as pd

cc = cluster_pairwise_predictions_at_multiple_thresholds(
    nodes,
    edges,
    node_id_column_name="my_id",
    db_api=db_api,
    # match_probability_thresholds=thresholds,
    match_weight_thresholds=thresholds_weights,
    output_cluster_summary_stats=True,
)


dc_df = cc.as_duckdbpyrelation().df()

# Define the options for the x-axis
x_axis_options = ['threshold_match_probability', 'threshold_match_weight']

# Create a selection parameter with radio buttons
x_axis_param = alt.param(
    name='x_field',
    bind=alt.binding_radio(options=x_axis_options, name='X-axis: '),
    value='threshold_match_probability'
)

# Base chart with dynamic x-axis based on the parameter
base_chart = (
    alt.Chart(dc_df)
    .transform_fold(
        fold=['threshold_match_probability', 'threshold_match_weight'],
        as_=['variable', 'x_value']
    )
    .transform_filter(
        alt.datum.variable == x_axis_param
    )
    .add_params(x_axis_param)
    .encode(
        x=alt.X('x_value:Q', title='X-axis')
    )
    .properties(width=400, height=150)
)

# Define the subcharts
num_clusters = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("num_clusters:Q", title="Number of Clusters")
    )
    .properties(title="Number of Clusters vs X-axis")
)

max_cluster_size = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("max_cluster_size:Q", title="Max Cluster Size")
    )
    .properties(title="Maximum Cluster Size vs X-axis")
)

avg_cluster_size = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("avg_cluster_size:Q", title="Average Cluster Size")
    )
    .properties(title="Average Cluster Size vs X-axis")
)

# Combine the charts
combined_chart = alt.vconcat(
    num_clusters, max_cluster_size, avg_cluster_size
).resolve_scale(y="independent")

@RobinL RobinL changed the title (WIP) Clustering allows mw (WIP) Clustering allows match weight args not just match probability Nov 25, 2024
@RobinL RobinL changed the title (WIP) Clustering allows match weight args not just match probability Clustering allows match weight args not just match probability Nov 25, 2024
@RobinL RobinL merged commit 2aa78da into master Nov 26, 2024
25 checks passed
@RobinL RobinL deleted the clustering_allows_mw branch November 26, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant