measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_initial'].append( mapk(all_old, all_correct[f], metrics_sizes[0])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_rerank'].append( mapk(all_new[l], all_correct[f], metrics_sizes[0])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[1]}_initial'].append( mapk(all_old, all_correct[f], metrics_sizes[1])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[1]}_rerank'].append( mapk(all_new[l], all_correct[f], metrics_sizes[1])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[2]}_initial'].append( mapk(all_old, all_correct[f], test_item_amount)) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[2]}_rerank'].append( mapk(all_new[l], all_correct[f], test_item_amount)) elif metric_to_use == 'NDCG': for l in lambdas: measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_initial'].append( ndcg_at(all_old, all_correct[f], metrics_sizes[0])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_rerank'].append( ndcg_at(all_new[l], all_correct[f], metrics_sizes[0])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[1]}_initial'].append( ndcg_at(all_old, all_correct[f], metrics_sizes[1])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[1]}_rerank'].append( ndcg_at(all_new[l], all_correct[f], metrics_sizes[1])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[2]}_initial'].append( ndcg_at(all_old, all_correct[f], test_item_amount)) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[2]}_rerank'].append( ndcg_at(all_new[l], all_correct[f], test_item_amount)) elif metric_to_use == 'Prec': for l in lambdas: measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_initial'].append( precision_at(all_old, all_correct[f], metrics_sizes[0])) measures_lambda[l][f'{metric_to_use}_{metrics_sizes[0]}_rerank'].append(
metrics_sizes[1])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[1]}_rerank'].append( mapk(all_new[l], all_correct[f], metrics_sizes[1])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[2]}_initial'].append( mapk(all_old, all_correct[f], rerank_size)) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[2]}_rerank'].append( mapk(all_new[l], all_correct[f], rerank_size)) elif metric_to_use == 'NDCG': for l in lambdas: measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[0]}_initial'].append( ndcg_at(all_old, all_correct[f], metrics_sizes[0])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[0]}_rerank'].append( ndcg_at(all_new[l], all_correct[f], metrics_sizes[0])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[1]}_initial'].append( ndcg_at(all_old, all_correct[f], metrics_sizes[1])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[1]}_rerank'].append( ndcg_at(all_new[l], all_correct[f], metrics_sizes[1])) measures_lambda[l][ f'{metric_to_use}_{metrics_sizes[2]}_initial'].append( ndcg_at(all_old, all_correct[f], rerank_size))
predictions = [] for index, row in initial_pred.iterrows(): cntr = 1 pred = [] while cntr <= test_item_amount: if type(row[f'p{cntr}']) is str: pred.append(int(row[f'p{cntr}'].split(';')[0])) cntr = cntr + 1 predictions.append(pred) map_10.append(mapk(predictions, correct_items, 10)) map_25.append(mapk(predictions, correct_items, 25)) prec_10.append(precision_at(predictions, correct_items, 10)) prec_25.append(precision_at(predictions, correct_items, 25)) ndcg_10.append(ndcg_at(predictions, correct_items, 10)) ndcg_25.append(ndcg_at(predictions, correct_items, 25)) final_df['test_amount'].append(test_item_amount) final_df['MAP_10'].append(mean(map_10)) final_df['MAP_25'].append(mean(map_25)) final_df['Prec_10'].append(mean(prec_10)) final_df['Prec_25'].append(mean(prec_25)) final_df['NDCG_10'].append(mean(ndcg_10)) final_df['NDCG_25'].append(mean(ndcg_25)) pd.DataFrame.from_dict(final_df).to_csv( f'res\\{d_set}\\{algoName}-baseline.csv', index=False, float_format='%.5f')