DEV Community

StagingBench Team
StagingBench Team

Posted on AI-assisted

Count Virtual Staging Ratings with Python's Standard Library

A realism mean compresses five editor ratings into one number. To see how much of the rating scale the editor actually used, start by counting the scores in each column. Python's standard library can do that with collections.Counter and calculate the overall average with statistics.mean. The ratings come from the public StagingBench data. The example runs on Python 3.10 or later and includes all 36 rated records, so you can paste it into a script and run it as written.

Each tuple holds the scores for furniture, scale, light, artifacts, and fit, in that order. The scores are integers from 1 to 5, where 5 is best. For artifacts specifically, 5 means the editor saw none. Each tuple represents a record, so repeated tuples stay in the data. Dropping repeated tuples would give frequently observed combinations less weight and change the counts.

zip(*rows, strict=True) transposes the tuples. Its first result contains all the furniture scores, and each subsequent result contains the scores for the next criterion. The second zip pairs each of those columns with its label. The strict option catches mismatched lengths, such as a tuple missing a score or a set of labels that omits a criterion.

Inside the loop, Counter builds a frequency count for the column. The loop over range(1, 6) prints all five possible scores in order. A Counter returns zero for a missing key, so even a score the editor never used gets a table cell. len(counts) counts only the distinct scores that appeared. The width specifiers keep the cells aligned as the counts change from one digit to two.

from collections import Counter
from statistics import mean

labels = ("Furniture", "Scale", "Light", "Artifacts", "Fit")
rows = (
    (4, 4, 4, 4, 4),
    (4, 3, 4, 3, 4),
    (4, 4, 4, 4, 4),
    (4, 4, 4, 3, 4),
    (4, 3, 4, 3, 2),
    (4, 4, 3, 4, 3),
    (4, 4, 3, 4, 4),
    (4, 4, 4, 4, 5),
    (4, 4, 4, 3, 4),
    (4, 4, 4, 4, 4),
    (4, 3, 4, 3, 5),
    (4, 3, 3, 1, 4),
    (4, 3, 4, 2, 4),
    (4, 4, 3, 3, 5),
    (4, 4, 3, 4, 4),
    (4, 4, 3, 4, 4),
    (4, 4, 3, 4, 5),
    (4, 4, 3, 4, 5),
    (4, 4, 3, 5, 5),
    (4, 4, 4, 4, 4),
    (4, 3, 4, 3, 3),
    (4, 4, 4, 4, 4),
    (4, 3, 4, 3, 3),
    (4, 4, 4, 4, 4),
    (4, 4, 4, 3, 3),
    (4, 4, 4, 4, 4),
    (4, 4, 4, 4, 4),
    (4, 4, 4, 4, 4),
    (4, 4, 4, 5, 4),
    (4, 4, 4, 5, 5),
    (4, 4, 4, 5, 4),
    (4, 4, 3, 5, 5),
    (4, 4, 3, 5, 5),
    (3, 4, 4, 5, 3),
    (4, 3, 4, 4, 2),
    (4, 3, 4, 5, 4),
)

columns = zip(*rows, strict=True)
print(f"{'Criterion':<10}  1  2  3  4  5  Distinct")
for label, column in zip(labels, columns, strict=True):
    counts = Counter(column)
    frequency_cells = " ".join(f"{counts[score]:2}" for score in range(1, 6))
    print(f"{label:<10} {frequency_cells} {len(counts):9}")

row_means = [mean(row) for row in rows]
print(f"Rated records: {len(rows)}")
print(f"Mean of the record means: {mean(row_means):.2f}")
Enter fullscreen mode Exit fullscreen mode

The final calculation takes the average of the five scores within each record, then averages those record means. Because every row has five scores, this gives each record the same weight and yields the same result as averaging all 180 scores together. The last format specifier displays the mean to two decimal places.

The script prints the following output.

Criterion   1  2  3  4  5  Distinct
Furniture   0  0  1 35  0         2
Scale       0  0  9 27  0         2
Light       0  0 11 25  0         2
Artifacts   1  1  9 17  8         5
Fit         0  2  5 20  9         4
Rated records: 36
Mean of the record means: 3.85
Enter fullscreen mode Exit fullscreen mode

Read across the furniture row and you can see that all but one score was a 4. Artifacts used the full scale, and fit used four values. The single average of 3.85 compresses both patterns. The counts preserve the difference between a column where nearly every record received the same score and a column where the editor used every available score.

The embedded rows cover 27.9 percent of the 129 benchmark records. One editor scored them without blinding. The script reproduces the distribution of that editor's scores for the rated subset.

Top comments (0)