Я не уверен, что название хорошо описывает проблему, но я объясню ее шаг за шагом. src = "https://i.sstatic.net/ebcqlazp.png"/>
Тогда у меня есть стандартные термины с золотом, около 5K Rows, а столбцы-это идентификатор и используется_genes
Что я делаю:
Iteaing каждой сложной строки золота. /> Проверьте эти пары генов сложных строк в парах с уклаженной корреляцией. < /p>
Если они существуют, я положил столбец tp = 1, если не tp = 0. < /p>
На основе количества TP I Рассчитывать точность, напоминание и область под кривой. src = "https://i.sstatic.net/6kchc7bm.png"/>
Я поделюсь своей функцией ниже, со 100 -метровым DF и 5K терминами, которые займет около 25 минут, и я пытаюсь найти способ сократить время.def compute_per_complex_pr(corr_matrix, terms_df):
pairwise_df = binary(corr_matrix)
pairwise_df = quick_sort(pairwise_df).reset_index(drop=True)
# Precompute a mapping from each gene to the row indices in the pairwise DataFrame where it appears.
gene_to_pair_indices = {}
for i, (gene_a, gene_b) in enumerate(zip(pairwise_df["gene1"], pairwise_df["gene2"])):
gene_to_pair_indices.setdefault(gene_a, []).append(i)
gene_to_pair_indices.setdefault(gene_b, []).append(i)
# Initialize AUC scores (one for each complex) with NaNs.
auc_scores = np.full(len(terms_df), np.nan)
# Loop over each gene complex
for idx, row in terms_df.iterrows():
gene_set = set(row.used_genes)
if len(gene_set) < min_complex_size: # Skip small complexes.
continue
# Collect all row indices in the pairwise data where either gene belongs to the complex.
candidate_indices = set()
for gene in gene_set:
candidate_indices.update(gene_to_pair_indices.get(gene, []))
candidate_indices = sorted(candidate_indices)
if not candidate_indices:
continue
# Select only the relevant pairwise comparisons.
sub_df = pairwise_df.loc[candidate_indices]
# A prediction is 1 if both genes in the pair are in the complex; otherwise 0.
predictions = (sub_df["gene1"].isin(gene_set) & sub_df["gene2"].isin(gene_set)).astype(int)
if predictions.sum() == 0:
continue
# Compute cumulative true positives and derive precision and recall.
true_positive_cumsum = predictions.cumsum()
precision = true_positive_cumsum / (np.arange(len(predictions)) + 1)
recall = true_positive_cumsum / true_positive_cumsum.iloc[-1]
if len(recall) < 2 or recall.iloc[-1] == 0:
continue
auc_scores[idx] = metrics.auc(recall, precision)
# Add the computed AUC scores to the terms DataFrame.
terms_df["auc_score"] = auc_scores
return terms_df
Подробнее здесь: https://stackoverflow.com/questions/795 ... -dataframe
Самый быстрый способ искать 5K Rows внутри 100M DataFrame ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Самый быстрый способ искать 5K Rows внутри 100-метровой парной пары DataFrame
Anonymous » » в форуме Python - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Самый быстрый способ искать 5K Rows внутри 100-метровой парной пары DataFrame
Anonymous » » в форуме Python - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Самый быстрый способ искать 5K Rows внутри 100-метровой парной пары DataFrame
Anonymous » » в форуме Python - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Самый быстрый способ искать 5K Rows внутри 100-метровой парной пары DataFrame
Anonymous » » в форуме Python - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Самый быстрый способ искать 5K Rows внутри 100-метровой парной пары DataFrame
Anonymous » » в форуме Python - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-