Skip to content

Commit 4ddb744

Browse files
kgilliam125NelleV
authored andcommitted
[MRG + 1] Clarified error msg in plot_partial_dependence (scikit-learn#7673)
* Clarified error msg in plot_partial_dependence * Changed err msg for feature[i] out of range. Updated docs. * Error message shows invalid value.
1 parent 8f4ebb5 commit 4ddb744

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sklearn/ensemble/partial_dependence.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ def plot_partial_dependence(gbrt, X, features, feature_names=None,
183183
A fitted gradient boosting model.
184184
X : array-like, shape=(n_samples, n_features)
185185
The data on which ``gbrt`` was trained.
186-
features : seq of tuples or ints
186+
features : seq of ints, strings, or tuples of ints or strings
187187
If seq[i] is an int or a tuple with one int value, a one-way
188188
PDP is created; if seq[i] is a tuple of two ints, a two-way
189189
PDP is created.
190+
If feature_names is specified and seq[i] is an int, seq[i]
191+
must be < len(feature_names).
192+
If seq[i] is a string, feature_names must be specified, and
193+
seq[i] must be in feature_names.
190194
feature_names : seq of str
191195
Name of each feature; feature_names[i] holds
192196
the name of the feature with index i.
@@ -306,8 +310,9 @@ def convert_feature(fx):
306310
l.append(feature_names[i])
307311
names.append(l)
308312
except IndexError:
309-
raise ValueError('features[i] must be in [0, n_features) '
310-
'but was %d' % i)
313+
raise ValueError('All entries of features must be less than '
314+
'len(feature_names) = {0}, got {1}.'
315+
.format(len(feature_names), i))
311316

312317
# compute PD functions
313318
pd_result = Parallel(n_jobs=n_jobs, verbose=verbose)(

0 commit comments

Comments
 (0)