Skip to content

"grid_resolution" setting of function "partial_dependence" #5810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
genliu777 opened this issue Nov 13, 2015 · 3 comments
Closed

"grid_resolution" setting of function "partial_dependence" #5810

genliu777 opened this issue Nov 13, 2015 · 3 comments

Comments

@genliu777
Copy link

when i run the project on the webpage: http://scikit-learn.org/stable/auto_examples/ensemble/plot_partial_dependence.html#example-ensemble-plot-partial-dependence-py

i try to change the value of 'grid_resolution', which is the parameter of function 'partial_dependence()',

i find and can not understand the following situation:

the original value of grid_resolution is 50, when changed to values less than 50, then, the shape of x_axis and y_axis are both (50, 50). the project works well,

but do not work while bigger than 50. for example, grid_resolution = 100, the x_axis.shape = (52, ), y_axis = (100, ), and pdp.shape = (1, 5200). it directly cause the value of XX, YY not equal to each other, and the leads to the error"ValueError: shape mismatch: objects cannot be broadcast to a single shape".

why can not set tgrid_resolution to any value( > 0) as i want???
thanks!!

@trevorstephens
Copy link
Contributor

Please provide an example? There are two calls using grid_resolution, do both fail? What line fails? What value of grid_resolution causes a failure?

I'm currently working on enhancing the function in #5653 and could potentially push a fix into that PR if I can trace what the problem is.

@genliu777
Copy link
Author

hi, thanks first!
about the example i should provide is on the webpage:http://scikit-learn.org/stable/auto_examples/ensemble/plot_partial_dependence.html#example-ensemble-plot-partial-dependence-py.

the following is the codes with problem in my pycharm:
target_feature = (1, 5)
pdp, (x_axis, y_axis) = partial_dependence(clf, target_feature,
X = X_train, grid_resolution = 150) # value changed here!!
print(X_train.shape, pdp.shape, x_axis.shape, y_axis.shape)
XX, YY = np.meshgrid(x_axis, y_axis)
Z = pdp.reshape(XX.shape).
ax = Axes3D(figg)
surf = ax.plot_surface(XX, YY, Z, rstride = 1, cstride = 1, cmap = plt.cm.BuPu) #error rises here!!

as mentioned, i change parameter "grid_resolution" to 150(original value in the webpage is 50), and then the "print" function output is "16512, 8) (1, 7800) (52,) (150,)" .

by the way, i update sklearn to 0.17, and my OS is win7 64bit

@trevorstephens
Copy link
Contributor

@genliu777 .. Check #5847 and it should work. Basic problem was when the number of unique values is less than the resolution you specify, the shape of Z is incorrect.

@ogrisel ogrisel closed this as completed Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants