04. ParamGrid

This example shows different configurations of ParamGrid.

 8 # Generic
 9 import pandas as pd
10
11 # Library
12 from sklearn.model_selection import ParameterGrid
13
14 try:
15     __file__
16     TERMINAL = True
17 except:
18     TERMINAL = False
19
20 # -----------------------------
21 # Sample I
22 # -----------------------------
23 # Define params
24 params = {'a': [1, 2], 'b': [True, False]}
25 # Create params grid
26 grid = list(ParameterGrid(params))
27 # Show
28 if TERMINAL:
29     print("\nExample I:")
30     print(pd.DataFrame(grid))
31 pd.DataFrame(grid)
a b
0 1 True
1 1 False
2 2 True
3 2 False


37 # -----------------------------
38 # Sample II
39 # -----------------------------
40 # Define params
41 params = [{'kernel': ['linear']},
42           {'kernel': ['rbf'], 'gamma': [1, 10]}]
43 # Create params grid
44 grid = list(ParameterGrid(params))
45 # Show
46 if TERMINAL:
47     print("\nExample II:")
48     print(pd.DataFrame(grid))
49 pd.DataFrame(grid)
kernel gamma
0 linear NaN
1 rbf 1.0
2 rbf 10.0


54 # -----------------------------
55 # Sample III
56 # -----------------------------
57 # Define params
58 params = {'imp': ['simp', 'iimp'],
59           'scl': ['minmax', 'norm', 'std'],
60           'est': ['PCA', 'AE']}
61 # Create params grid
62 grid = list(ParameterGrid(params))
63 # Show
64 if TERMINAL:
65     print("\nExample III:")
66     print(pd.DataFrame(grid))
67 pd.DataFrame(grid)
est imp scl
0 PCA simp minmax
1 PCA simp norm
2 PCA simp std
3 PCA iimp minmax
4 PCA iimp norm
5 PCA iimp std
6 AE simp minmax
7 AE simp norm
8 AE simp std
9 AE iimp minmax
10 AE iimp norm
11 AE iimp std


73 # -----------------------------
74 # Sample IV
75 # -----------------------------
76 # Define params
77 params = [{'imp': ['simp', 'iimp'], 'scl': ['minmax'], 'est': ['PCA']},
78           {'imp': ['simp', 'iimp'], 'scl': ['std', 'norm'], 'est': ['AE']}]
79 # Create params grid
80 grid = list(ParameterGrid(params))
81 # Show
82 if TERMINAL:
83     print("\nExample IV:")
84     print(pd.DataFrame(grid))
85 pd.DataFrame(grid)
est imp scl
0 PCA simp minmax
1 PCA iimp minmax
2 AE simp std
3 AE simp norm
4 AE iimp std
5 AE iimp norm


Total running time of the script: ( 0 minutes 0.010 seconds)

Gallery generated by Sphinx-Gallery