-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Need better error when n_components is float (was: TypeError when fitting GridSearchCV) #10034
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
Comments
I can't see at a glance what's going on... but you or someone should at
least help us by identifying which version this did work in...
|
I cant seem to figure out exactly what version it was, but the directory wast last updated 9 months ago if thats any help. Is any of the procedures used outdated? I tried digging into the documentation but all guidelines seems to be followed as far as I can see. |
@petmo Below are my observations, please kindly confirm them :) import numpy as np
from sklearn.decomposition import PCA
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
# correct version: pca = PCA(n_components=1)
pca = PCA(n_components=1.0)
pca.fit(X) (2)Your code work in Python2, but not in Python3, the core reason is below: np.around(36 / 5)
# python2.X output:7
# python3.X output:7.0
np.arange(5, 36, np.around(36 / 5))
# python2.X output:array([ 5, 12, 19, 26, 33])
# python3.X output:array([ 5., 12., 19., 26., 33.]) So simply change |
good diagnosis work. yes I suppose it's worth fixing in this sort of case,
but being an easy issue and low priority, I'd rather open it to a beginner
contrib
|
Yes, that did indeed fix it! Thanks a lot 👍 |
I can handle this one if no one has started |
I think just _fit. Thanks!
|
@CoderPat Thanks for the contribution :) |
Ye although it saves some code, i agree it may be more legible to put it in the two separate methods since most verifications are made there (althought I'm still quite new here so it might make more sense to leave it as it is since it works like this in other classes around scikit). Will fix it in the morning if @jnothman agrees. |
Description
Hello! I'm trying to run some code written a year ago or so, but I seem to run into an error when I run try to fit the data provided to GridSearchCV. I tried running the same data through a randomized parameter optimizer, and got the same error. Changing the entries in ytest to integers instead of strings doesn't seem to helper either.
Steps/Code to Reproduce
Expected Results
Actual Results
Versions
Darwin-14.5.0-x86_64-i386-64bit
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
NumPy 1.13.3
SciPy 0.19.1
Scikit-Learn 0.19.1
The text was updated successfully, but these errors were encountered: