คุณลักษณะ X และเป้าหมาย y
จัดรูปข้อมูลนำเข้าตามที่ไลบรารีคาดหวัง
คุณลักษณะ X และเป้าหมาย y เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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. ✅
คำถามที่พบบ่อย
บทเรียน “คุณลักษณะ X และเป้าหมาย y” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “คุณลักษณะ X และเป้าหมาย y” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “คุณลักษณะ X และเป้าหมาย y”
จัดรูปข้อมูลนำเข้าตามที่ไลบรารีคาดหวัง คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “คุณลักษณะ X และเป้าหมาย y” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม
ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- สัญญาของ fit และ predict
- คุณลักษณะ X และเป้าหมาย y
- ฝึกการถดถอยเชิงเส้น
- ประเมินโมเดลแรกของคุณ