क्रॉस-वैलिडेशन

Python में Model Validation

Kasey Jones

Data Scientist

क्रॉस-वैलिडेशन

Train, validation, और test डेटासेट बनाना कुल डेटा को 3 सबसेट में बाँटकर किया जाता है. उदाहरण: 60% training, और 20%–20% validation व testing.

Python में Model Validation

क्रॉस-वैलिडेशन

क्रॉस-वैलिडेशन में हम डेटा को कई बार training व validation में बाँटते हैं, न कि केवल एक 80:20 split. जैसे, 5 अलग 80:20 splits.

Python में Model Validation

n_splits: क्रॉस-वैलिडेशन splits की संख्या

shuffle: split से पहले डेटा shuffle करना है या नहीं (boolean)

random_state: random seed

from sklearn.model_selection import KFold

X = np.array(range(40))
y = np.array([0] * 20 + [1] * 20)

kf = KFold(n_splits=5)

splits = kf.split(X)
Python में Model Validation
kf = KFold(n_splits=5)
splits = kf.split(X)

for train_index, test_index in splits: print(len(train_index), len(test_index))
32 8 32 8 32 8 32 8 32 8
# किसी एक index सेट को प्रिंट करें:
print(train_index, test_index)
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 ...]
[32 33 34 35 36 37 38 39]
Python में Model Validation
rfr = RandomForestRegressor(n_estimators=25, random_state=1111)

errors = [] for train_index, val_index in splits: X_train, y_train = X[train_index], y[train_index] X_val, y_val = X[val_index], y[val_index] rfr.fit(X_train, y_train) predictions = rfr.predict(X_val) errors.append(<some_accuracy_metric>)
print(np.mean(errors))
4.25
Python में Model Validation

Practice time

Python में Model Validation

Preparing Video For Download...