Características X y objetivo y
Dar forma a las entradas que espera la biblioteca.
Características X y objetivo y es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Data Science Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Data Science Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. ✅
Preguntas frecuentes
¿La lección «Características X y objetivo y» es gratis?
Sí — el texto completo de «Características X y objetivo y» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Data Science Academy, actualiza a CoddyKit PRO. El curso de Data Science Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Características X y objetivo y»?
Dar forma a las entradas que espera la biblioteca. Practicas Data Science Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Data Science Academy?
No se requiere experiencia previa. Data Science Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Características X y objetivo y»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Data Science Academy?
Sí. Cada lección de Data Science Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- El contrato de fit y predict
- Características X y objetivo y
- Entrenar una regresión lineal
- Evaluar su primer modelo