Features X and Target y
Shaping inputs the library expects.
Features X and Target y is a free Data Science Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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. ✅
Frequently asked questions
Is the “Features X and Target y” lesson free?
Yes — the full text of “Features X and Target y” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.
What will I learn in “Features X and Target y”?
Shaping inputs the library expects. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Data Science Academy?
No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Features X and Target y” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Data Science Academy lesson?
Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The fit and predict Contract
- Features X and Target y
- Train a Linear Regression
- Score Your First Model