Note
Click here to download the full example code
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)
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)
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)
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)
Total running time of the script: ( 0 minutes 0.010 seconds)