forked from stefan-jansen/machine-learning-for-trading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_cross_validation.py
39 lines (30 loc) · 1.06 KB
/
04_cross_validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Stefan Jansen'
from sklearn.model_selection import (train_test_split,
KFold,
LeaveOneOut,
LeavePOut,
ShuffleSplit,
TimeSeriesSplit)
data = list(range(1, 11))
print(data)
print(train_test_split(data, train_size=.8))
kf = KFold(n_splits=5)
for train, validate in kf.split(data):
print(train, validate)
kf = KFold(n_splits=5, shuffle=True, random_state=42)
for train, validate in kf.split(data):
print(train, validate)
loo = LeaveOneOut()
for train, validate in loo.split(data):
print(train, validate)
lpo = LeavePOut(p=2)
for train, validate in lpo.split(data):
print(train, validate)
ss = ShuffleSplit(n_splits=3, test_size=2, random_state=0)
for train, validate in ss.split(data):
print(train, validate)
tscv = TimeSeriesSplit(n_splits=5)
for train, validate in tscv.split(data):
print(train, validate)