scikit-learn/scikit-learn — pull request #3147 by mjbommar (2014-05-13 00:58:38+00:00)
Title: Censor out-of-bounds x values for isotonic regression

`predict` and `transform` in IsotonicRegression rely on interp1d, which fails if an element of X is outside of [x_min, x_max] for the vector that the model was fit on.

For example, this block below will fail with the following exception:
```
# Load boston house price data
boston_data = sklearn.datasets.load_boston()

# Load features/targets
features = boston_data.data
target = boston_data.target
indus_index = boston_data.feature_names.tolist().index('INDUS')

# Fit the model
reg = sklearn.isotonic.IsotonicRegression(x_censor=False, increasing=False)
reg.fit(features[:, indus_index], target)

# Now shift X up and down
y_all_up = reg.predict(features[:, indus_index] + 1)
y_all_down = reg.predict(features[:, indus_index] + 1)
```

```
ValueError: A value in x_new is above the interpolation range.
```

To make this more convenient for usage in real-world scenarios, I added a simple `x_censor` argument to the `IsotonicRegression` constructor. If set to True, the `predict` and `transform` methods will map out-of-bounds x values to the nearest bound. Test included.