text_plain_output_1.png
import numpy as np

import pandas as pd

train_csv = pd.read_csv('../input/recursion-cellular-image-classification/train.csv')
test_csv = pd.read_csv('../input/recursion-cellular-image-classification/test.csv')
sub = pd.read_csv('../input/recursion-cellular-keras-densenet/submission.csv')

np.stack([train_csv.plate.values[train_csv.sirna == i] for i in range(10)]).transpose()

plate_groups = np.zeros((1108, 4), int)
for sirna in range(1108):
    grp = train_csv.loc[train_csv.sirna == sirna, :].plate.value_counts().index.values
    assert len(grp) == 3
    plate_groups[sirna, 0:3] = grp
    plate_groups[sirna, 3] = 10 - grp.sum()
plate_groups[:10, :]

all_test_exp = test_csv.experiment.unique()

group_plate_probs = np.zeros((len(all_test_exp), 4))
for idx in range(len(all_test_exp)):
    print('Experiment', idx)
    preds = sub.loc[test_csv.experiment == all_test_exp[idx], 'sirna'].values
    pp_mult = np.zeros((len(preds), 1108))
    pp_mult[range(len(preds)), preds] = 1
    sub_test = test_csv.loc[test_csv.experiment == all_test_exp[idx], :]
    assert len(pp_mult) == len(sub_test)
    for j in range(4):
        mask = np.repeat(plate_groups[np.newaxis, :, j], len(pp_mult), axis=0) == np.repeat(sub_test.plate.values[:, np.newaxis], 1108, axis=1)
        group_plate_probs[idx, j] = np.array(pp_mult)[mask].sum() / len(pp_mult)