train_test_split İşlemini Doğru Yapma
Stratify, random_state ve oranlar
train_test_split İşlemini Doğru Yapma, CoddyKit'te ücretsiz bir Data Science Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Data Science Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Data Science Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
One Helper, Two Sets
The function train_test_split takes your features and target and hands back train and test pieces in one tidy call.
from sklearn.model_selection import train_test_splitFour Things Come Back
It returns four objects in a fixed order: train features, test features, train target, test target. Unpack them carefully so each lands in the right name.
X_train, X_test, y_train, y_test = train_test_split(X, y)Set the Test Size
Use test_size to choose how much data to reserve. A value of 0.2 means 20% goes to the test set.
train_test_split(X, y, test_size=0.2)Shuffling by Default
By default the rows are shuffled before splitting. That mixing prevents any hidden order in your file from biasing either set.
Make It Reproducible
Pass random_state to lock the shuffle. The same number gives the same split every run, so your results are repeatable. 🔁
train_test_split(X, y, test_size=0.2, random_state=42)Why Reproducibility Matters
Without a fixed seed, every run reshuffles and your scores wobble. A locked random_state lets teammates reproduce your exact numbers.
The Imbalance Problem
If a class is rare, a plain random split might dump most of it into one set. Now train and test no longer reflect the same class balance.
Stratify to the Rescue
Pass stratify equal to your target so both sets keep the same class proportions. Essential for classification with uneven classes.
train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)Keep X and y Aligned
The split keeps each row's features and label together. Row 7's features always travel with row 7's label, never scrambled apart.
Choosing the Ratio
Common splits are 80/20 or 70/30. With lots of data you can spare a smaller test slice; with little data, give the test set a bit more.
Split Before You Touch
Run the split first, before scaling or filling values. Doing prep on the full set leaks test information back into training.
Quick Check
Your target classes are very imbalanced. Which argument helps?
Recap
Unpack four sets, set test_size, fix random_state for repeatability, and use stratify when classes are uneven. Split first, prep later. 🔁
Sıkça Sorulan Sorular
“train_test_split İşlemini Doğru Yapma” dersi ücretsiz mi?
Evet — “train_test_split İşlemini Doğru Yapma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Data Science Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Data Science Academy kursu toplamda 4 dersten oluşur.
“train_test_split İşlemini Doğru Yapma” dersinde ne öğreneceğim?
Stratify, random_state ve oranlar Data Science Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Data Science Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Data Science Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“train_test_split İşlemini Doğru Yapma” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Data Science Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Data Science Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Test Kümesini Neden Ayırırsınız
- train_test_split İşlemini Doğru Yapma
- K-Katlı Çapraz Doğrulama
- Veri Sızıntısını Başlamadan Önleme