Ridimensionare e selezionare le feature
Conservare le feature che aiutano davvero
Ridimensionare e selezionare le feature è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Too Many Features Hurt
Text models can explode to tens of thousands of features. Many add only noise, so trimming the list often improves both speed and accuracy.
Why Scale at All
Some models compare feature magnitudes directly. If one feature ranges 0 to 1000, it can drown out the rest unless you scale them first.
Standardizing Numbers
StandardScaler shifts each feature to zero mean and unit variance. Now every numeric feature speaks on the same scale.
from sklearn.preprocessing import StandardScaler
scaled = StandardScaler().fit_transform(numeric_features)Careful With Sparse Data
Centering a sparse TF-IDF matrix fills it with nonzeros and wastes memory. Use MaxAbsScaler, which scales without destroying sparsity.
from sklearn.preprocessing import MaxAbsScaler
scaled = MaxAbsScaler().fit_transform(tfidf_matrix)Drop the Dead Weight
Features that barely vary tell the model nothing. A VarianceThreshold filter removes near-constant columns in one quick pass.
Pick the Most Useful
SelectKBest keeps the top features by a scoring test like chi-squared. You ask for the best k and it drops the rest.
from sklearn.feature_selection import SelectKBest, chi2
best = SelectKBest(chi2, k=2000).fit_transform(X, y)Let the Model Choose
An L1-penalized model pushes useless weights to zero on its own. This built-in selection is often called embedded feature selection.
Fit on Train Only
Always fit scalers and selectors on training data alone, then apply them to test data. Mixing them causes leakage and rosy fake scores.
Keep It in a Pipeline
Putting scaling and selection inside a Pipeline runs them in the right order every time. It also blocks accidental leakage during validation.
from sklearn.pipeline import Pipeline
pipe = Pipeline([("select", SelectKBest(chi2, k=2000)), ("clf", model)])Fewer Features, Faster Model
A leaner feature set trains faster, needs less memory, and is easier to explain. Smaller is often better once noise is gone. ⚡
Measure, Do Not Guess
Try a few values of k and compare validation scores. Let the numbers, not a hunch, decide how many features to keep.
Quick Check
Which scaler keeps a sparse matrix sparse?
Recap
Scale numeric features and select the useful ones with SelectKBest or L1. Use MaxAbsScaler for sparse data, and fit everything inside a pipeline. ✅
Domande Frequenti
La lezione «Ridimensionare e selezionare le feature» è gratuita?
Sì — il testo completo di «Ridimensionare e selezionare le feature» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.
Cosa imparerò in «Ridimensionare e selezionare le feature»?
Conservare le feature che aiutano davvero Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare NLP Academy?
Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Ridimensionare e selezionare le feature»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione NLP Academy?
Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Oltre il bag-of-words
- N-gram di caratteri per una maggiore robustezza
- Combinare più tipi di feature
- Ridimensionare e selezionare le feature