diff --git a/sklearn/ensemble/partial_dependence.py b/sklearn/ensemble/partial_dependence.py index 0f0fcd9cab552..b7e7f6ccccfe7 100644 --- a/sklearn/ensemble/partial_dependence.py +++ b/sklearn/ensemble/partial_dependence.py @@ -183,10 +183,14 @@ def plot_partial_dependence(gbrt, X, features, feature_names=None, A fitted gradient boosting model. X : array-like, shape=(n_samples, n_features) The data on which ``gbrt`` was trained. - features : seq of tuples or ints + features : seq of ints, strings, or tuples of ints or strings If seq[i] is an int or a tuple with one int value, a one-way PDP is created; if seq[i] is a tuple of two ints, a two-way PDP is created. + If feature_names is specified and seq[i] is an int, seq[i] + must be < len(feature_names). + If seq[i] is a string, feature_names must be specified, and + seq[i] must be in feature_names. feature_names : seq of str Name of each feature; feature_names[i] holds the name of the feature with index i. @@ -306,8 +310,9 @@ def convert_feature(fx): l.append(feature_names[i]) names.append(l) except IndexError: - raise ValueError('features[i] must be in [0, n_features) ' - 'but was %d' % i) + raise ValueError('All entries of features must be less than ' + 'len(feature_names) = {0}, got {1}.' + .format(len(feature_names), i)) # compute PD functions pd_result = Parallel(n_jobs=n_jobs, verbose=verbose)(