Feature X e target y
Dare agli input la forma attesa dalla libreria.
Feature X e target y è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 2 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 Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Inputs and Outputs
Supervised models learn a mapping from inputs to an output. The inputs are your features, and the output is what you want to predict. 🎯
Meet X and y
By convention, features go in a capital X and the target goes in a lowercase y. This naming shows up in nearly every example you read.
X Is Two-Dimensional
Capital X is a 2D table: one row per sample, one column per feature. scikit-learn always expects this rows-by-columns shape.
X.shape # (n_samples, n_features)y Is One-Dimensional
The target y is usually a single column: one value per sample. Its length must match the number of rows in X exactly.
y.shape # (n_samples,)Split a DataFrame
From a pandas table, you carve out X and y by selecting columns. The target column becomes y; everything else becomes X.
X = df.drop(columns=['price'])
y = df['price']Features Should Be Numeric
Most estimators expect numeric features. Text and category columns need encoding into numbers before they can enter X.
Keep the Target Out of X
Never leave the answer inside your features. A target hiding in X is leakage, and it makes a model look perfect but useless.
Rows Must Line Up
Row one of X must correspond to value one of y. This alignment is how the model connects each sample to its correct answer.
Regression vs Classification
If y holds continuous numbers it is regression; if y holds categories it is classification. The target's type decides the model family.
Feed Both Into fit
Once X and y are ready, you hand both to fit together. The model reads features and answers side by side to learn.
model.fit(X, y)predict Takes X Only
When predicting, you pass new features with the same columns as training X. You never pass y, since that is what you want back.
model.predict(X_new)Quick Check
Make sure you have the shapes of X and y straight.
Recap
Split your data into X, a 2D feature table, and y, the 1D target. Keep them aligned and leak-free, and fit is ready to learn. ✅
Domande Frequenti
La lezione «Feature X e target y» è gratuita?
Sì — il testo completo di «Feature X e target y» è 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 Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Feature X e target y»?
Dare agli input la forma attesa dalla libreria. Eserciti Data Science 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 Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science 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 2 di 4.
Quanto tempo richiede la lezione «Feature X e target y»?
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 Data Science Academy?
Sì. Ogni lezione Data Science 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
- Il contratto di fit e predict
- Feature X e target y
- Addestrare una regressione lineare
- Valutare il primo modello