autora.experimentalist.model_disagreement
sample(conditions, models, num_samples=1)
A experimentalist that returns selected samples for independent variables for which the models disagree the most in terms of their predictions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Union[DataFrame, ndarray]
|
pool of IV conditions to evaluate in terms of model disagreement |
required |
models
|
List
|
List of Scikit-learn (regression or classification) models to compare |
required |
num_samples
|
int
|
number of samples to select |
1
|
Returns: Sampled pool
Source code in temp_dir/disagreement/src/autora/experimentalist/model_disagreement/__init__.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
sample_custom_distance(conditions, models, distance_fct=lambda x, y: x - y ** 2, aggregate_fct=lambda x: np.sum(x, axis=0), num_samples=1)
An experimentalist that returns selected samples for independent variables for which the models disagree the most in terms of their predictions. The disagreement measurement is customizable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Union[DataFrame, ndarray]
|
pool of IV conditions to evaluate in terms of model disagreement |
required |
models
|
List
|
List of Scikit-learn (regression or classification) models to compare |
required |
distance_fct
|
Callable
|
distance function to use on the predictions |
lambda x, y: x - y ** 2
|
aggregate_fct
|
Callable
|
aggregate function to use on the pairwise distances of the models |
lambda x: sum(x, axis=0)
|
num_samples
|
Optional[int]
|
number of samples to select |
1
|
Returns: Sampled pool
Source code in temp_dir/disagreement/src/autora/experimentalist/model_disagreement/__init__.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
score_sample(conditions, models, num_samples=None)
A experimentalist that returns selected samples for independent variables for which the models disagree the most in terms of their predictions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Union[DataFrame, ndarray]
|
pool of IV conditions to evaluate in terms of model disagreement |
required |
models
|
List
|
List of Scikit-learn (regression or classification) models to compare |
required |
num_samples
|
Optional[int]
|
number of samples to select |
None
|
Returns: Sampled pool
Examples:
If a model is undefined at a certain condition, the disagreement on that point is set to 0:
>>> class ModelUndefined:
... def predict(self, X):
... return np.log(X)
>>> class ModelDefinined:
... def predict(self, X):
... return X
>>> modelUndefined = ModelUndefined()
>>> modelDefined = ModelDefinined()
>>> conditions_defined = np.array([1, 2, 3])
>>> score_sample(conditions_defined, [modelUndefined, modelDefined], 3)
0 score
2 3 1.364948
1 2 -0.362023
0 1 -1.002924
>>> conditions_undefined = np.array([-1, 0, 1, 2, 3])
>>> score_sample(conditions_undefined, [modelUndefined, modelDefined], 5)
0 score
4 3 1.752985
3 2 0.330542
2 1 -0.197345
0 -1 -0.943091
1 0 -0.943091
Source code in temp_dir/disagreement/src/autora/experimentalist/model_disagreement/__init__.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
score_sample_custom_distance(conditions, models, distance_fct=lambda x, y: x - y ** 2, aggregate_fct=lambda x: np.sum(x, axis=0), num_samples=None)
An experimentalist that returns selected samples for independent variables for which the models disagree the most in terms of their predictions. The disagreement measurement is customizable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Union[DataFrame, ndarray]
|
pool of IV conditions to evaluate in terms of model disagreement |
required |
models
|
List
|
List of Scikit-learn (regression or classification) models to compare |
required |
distance_fct
|
Callable
|
distance function to use on the predictions |
lambda x, y: x - y ** 2
|
aggregate_fct
|
Callable
|
aggregate function to use on the pairwise distances of the models |
lambda x: sum(x, axis=0)
|
num_samples
|
Optional[int]
|
number of samples to select |
None
|
Returns:
Type | Description |
---|---|
Sampled pool with score |
Examples:
We can use this without passing in a distance function (squared distance as default) ...
>>> class IdentityModel:
... def predict(self, X):
... return X
>>> class SquareModel:
... def predict(self, X):
... return X**2
>>> id_model = IdentityModel()
>>> sq_model = SquareModel()
>>> _conditions = np.array([1, 2, 3])
>>> id_model.predict(_conditions)
array([1, 2, 3])
>>> sq_model.predict(_conditions)
array([1, 4, 9])
>>> score_sample_custom_distance(_conditions, [id_model, sq_model])
0 score
2 3 36
1 2 4
0 1 0
... we can use our own distance function (for example binary 1 and 0 for different or equal)
>>> score_sample_custom_distance(_conditions, [id_model, sq_model], lambda x,y : x != y)
0 score
1 2 1
2 3 1
0 1 0
... this is mostly usefull if the predict function of the model doesn't return a standard one-dimensional array:
>>> _conditions = np.array([[0, 1], [1, 0], [1, 1], [.5, .5]])
>>> id_model.predict(_conditions)
array([[0. , 1. ],
[1. , 0. ],
[1. , 1. ],
[0.5, 0.5]])
>>> sq_model.predict(_conditions)
array([[0. , 1. ],
[1. , 0. ],
[1. , 1. ],
[0.25, 0.25]])
>>> def distance(x, y):
... return np.sqrt((x[0] - y[0])**2 + (x[1] - y[1])**2)
>>> score_sample_custom_distance(_conditions, [id_model, sq_model], distance)
0 1 score
3 0.5 0.5 0.353553
0 0.0 1.0 0.000000
1 1.0 0.0 0.000000
2 1.0 1.0 0.000000
Source code in temp_dir/disagreement/src/autora/experimentalist/model_disagreement/__init__.py
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|