Files
bayesian_inference_2025/Project assignments.ipynb

2.6 KiB

Import dependencies

In [ ]:
#!/usr/bin/env python3
import pandas as pd
from scipy.optimize import linear_sum_assignment
import prettytable as pt

Read data

Read the CSV file where I stored Google Form responses. The matrix has been transposed (rows = projects, columns = people) and the Borda count matrix score was evaluated subtracting 1 to poll responses (a score of 0 corresponds to the most desirable assignation).

In [ ]:
df = pd.read_csv("form_responses.csv", index_col=0)
cost = df.values

Solve the assignment problem using scipy

In [ ]:
row_ind, col_ind = linear_sum_assignment(cost)
assignment = pd.DataFrame({
    "Project": df.index[row_ind],
    "Assignee": df.columns[col_ind],
    "Cost": cost[row_ind, col_ind],
})

Show results

In [ ]:
print("These are the best assignments:")
assignment[["Assignee", "Cost", "Project"]].reset_index(drop=True)
In [ ]:
print(f"The total cost of these assignments was {assignment['Cost'].sum()}")