PeptideVectorizer.transform returns zeros after fitting with training_already_reduced=True

Aperta
#69 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, scikit-learn
Ambito
data

Direzione di ricerca

Start by reading PeptideVectorizer.make_count_vectorizer and the fit_transform and transform paths in the implementation, then reproduce the example with training_already_reduced=True. Check how each vectorizer handles letter case and how changing it affects pickled vocabularies. Done means transform(seqs) returns the expected nonzero counts and the compatibility choice is addressed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

With training_already_reduced=True, PeptideVectorizer.transform returns all zeros.

from pepdata import PeptideVectorizer
from pepdata.reduced_alphabet import hp2

seqs = ["SIINFEKL", "GILGFVFTL"]
reduced = ["".join(hp2[r] for r in s) for s in seqs]   # ['ACCACAAC', 'ACCACCCAC']
v = PeptideVectorizer(reduced_alphabet=hp2, training_already_reduced=True, normalize_row=False)
v.fit_transform(reduced)         # [[4, 4], [3, 6]]; vocabulary_ == {'a': 0, 'c': 1}
v.transform(seqs)                # [[0, 0], [0, 0]]

fit_transform fits a second CountVectorizer without a preprocessor, which lowercases by default (lowercase=True), so the copied vocabulary is lowercase ({'a', 'c'}). transform then uses self.count_vectorizer, whose custom preprocessor maps residues to the uppercase group letters, and scikit-learn skips lowercasing when a preprocessor is given. No n-gram matches. Without training_already_reduced, the vocabulary is uppercase ({'A', 'C'}) and transform works.

Checked with scikit-learn 1.9.1 on the branch of #68 (which fixes #62; the same happens on master with normalize_row=False).

Possible fix

Build both vectorizers with lowercase=False in make_count_vectorizer (sequences are uppercase amino acids), or lowercase inside the reduced-alphabet preprocessor. Either changes the vocabulary's letter case, which pickled vectorizers keep, so it needs a decision on compatibility; it was left out of #68.

https://claude.ai/code/session_01JHJhwj29oDqoeu7TYd34Pi

Lingua principale
Python
Stelle
58
Fork
16
Merge medio
1g 8h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openvax/pepdata

Tutte le issue di openvax/pepdata

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.