ClimbsRocks / auto_ml

[UNMAINTAINED] Automated machine learning for analytics & production
http://auto-ml.readthedocs.io
MIT License
1.64k stars 310 forks source link

ImportError: cannot import name Predictor #148

Closed jeregrine closed 7 years ago

jeregrine commented 7 years ago

When importing using the example from the readme get the error in the title :-/

ClimbsRocks commented 7 years ago

Thanks for filing! I'll check that out right now. I'd actually been meaning to have tests for that- thanks for the excuse :)

@jeregrine: How did you install the module? Did you pip install, or git clone?

ClimbsRocks commented 7 years ago

Hmm, @jeregrine I'm having trouble reproducing. I've definitely run into that error in the past though, so I'd like to make sure it's thoroughly squashed.

Could you copy/paste the full stack trace when you get this error message?

And then afterwards, could you uninstall/reinstall auto_ml, just to make sure you're working with version 1.9?

I tried both git cloning and pip installing on two different machines, running python 2.7 and 3.5, so this use case is one I'm blind to right now. Would love to fix it and build it into the test suite!

mglowacki100 commented 7 years ago

I have the same issue with following code:

from sklearn import datasets
from auto_ml import Predictor

iris = datasets.load_iris()
col_desc_dictionary = X = iris.data[:, :2]  # we only take the first two features.
col_to_predict = Y = iris.target
col_desc_dictionary = {col_to_predict: 'output'}
ml_predictor = Predictor(type_of_estimator='classifier', column_descriptions=col_desc_dictionary)
# Can pass in type_of_estimator='regressor' as well
ml_predictor.train(training_dataframe)
# Wait for the machine to learn all the complex and beautiful patterns in your data...
# ml_predictor.predict(new_data)
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> runfile('/home/mglo/Desktop/auto_ml.py', wdir='/home/mglo/Desktop')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/home/mglo/Desktop/auto_ml.py", line 8, in <module>
    from auto_ml import Predictor
  File "auto_ml.py", line 8, in <module>
    from auto_ml import Predictor
ImportError: cannot import name Predictor

I've installed by pip an hour ago ;)

Btw. I've seen on the list of features:

jeregrine commented 7 years ago

Installed via pip and the same stack trace roughly

On Tue, Dec 13, 2016 at 3:05 PM, mglowacki100 notifications@github.com wrote:

I have the same issue with following code:

from sklearn import datasets from auto_ml import Predictor

iris = datasets.load_iris() col_desc_dictionary = X = iris.data[:, :2] # we only take the first two features. col_to_predict = Y = iris.target col_desc_dictionary = {col_to_predict: 'output'} ml_predictor = Predictor(type_of_estimator='classifier', column_descriptions=col_desc_dictionary)

Can pass in type_of_estimator='regressor' as well

ml_predictor.train(training_dataframe)

Wait for the machine to learn all the complex and beautiful patterns in your data...

ml_predictor.predict(new_data)

Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information.

runfile('/home/mglo/Desktop/auto_ml.py', wdir='/home/mglo/Desktop') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile execfile(filename, namespace) File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile builtins.execfile(filename, *where) File "/home/mglowacki/Desktop/auto_ml.py", line 8, in from auto_ml import Predictor File "auto_ml.py", line 8, in from auto_ml import Predictor ImportError: cannot import name Predictor

I've installed by pip an hour ago ;)

Btw. I've seen on the list of features:

  • predict_proba
  • other metrics (e.g. log-loss) When do you plan to add it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ClimbsRocks/auto_ml/issues/148#issuecomment-266861822, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGKFlYRYVm1jAKpLEvWZ2PjdiFI1LwWks5rHwizgaJpZM4LLN_6 .

ClimbsRocks commented 7 years ago

weird. let me keep digging. @jeregrine are you on linux as well?

@mglowacki100 Both of those are already implemented, actually! predict_proba has been around since the beginning (pretty sure it's in the API docs), but custom scoring metrics was just added this week!

Try passing in ml_predictor.train(blah_blah_blah, scoring='log_loss'). I'm pretty sure 'log_loss' is one of the out-of-the-box supported types, but we also take in any scoring function that aligns with sklearn's API. I haven't built out too many tests for this yet, so it's not documented at the moment, but I'd love any feedback you have on that feature!

ClimbsRocks commented 7 years ago

Hm, tested on Linux and seems to be working there too.

@mglowacki100 : It looks like the error is coming from a file called "Desktop/auto_ml.py". If so, python might be self-referentially trying to import Predictor from "Desktop/auto_ml.py", before going out to the list of modules installed by pip.

Do you mind renaming that file, and then if that doesn't fix it, copy/pasting the contents of that file into this thread?

@jeregrine : did you also name a file or folder "auto_ml"? If so, we might be onto a fix! If not, I'd love a stack trace from you too just in case it holds any clues.

Thanks for working with me on this, y'all!

mglowacki100 commented 7 years ago

I've renamed the file to auto_machine.py , but result is the same.

>>> runfile('/home/mglowacki/Desktop/auto_machine.py', wdir='/home/mglowacki/Desktop')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/home/mglowacki/Desktop/auto_machine.py", line 8, in <module>
    from auto_ml import Predictor
  File "auto_ml.py", line 8, in <module>
    from auto_ml import Predictor
ImportError: cannot import name Predictor

I've also tried to run from terminal instead of spyder, but result is the same. Thanks for info regarding logloss and predict_proba :)

Here is result of pip install:

mglowacki@mglowacki:~/Desktop$ sudo -H pip install auto_ml
Requirement already satisfied: auto_ml in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: scikit-learn in /usr/local/lib/python2.7/dist-packages (from auto_ml)
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages/scipy-0.18.0rc2-py2.7-linux-x86_64.egg (from auto_ml)
Requirement already satisfied: pandas in /usr/local/lib/python2.7/dist-packages/pandas-0.18.1-py2.7-linux-x86_64.egg (from auto_ml)
Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages/python_dateutil-2.5.3-py2.7.egg (from auto_ml)
Requirement already satisfied: pathos in /usr/local/lib/python2.7/dist-packages (from auto_ml)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages/pytz-2016.6.1-py2.7.egg (from pandas->auto_ml)
Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python2.7/dist-packages (from pandas->auto_ml)
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil->auto_ml)
Requirement already satisfied: multiprocess>=0.70.4 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml)
Requirement already satisfied: pox>=0.2.2 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml)
Requirement already satisfied: ppft>=1.6.4.5 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml)
Requirement already satisfied: dill>=0.2.5 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml)

Maybe there is a problem in a way I use iris dataset. Could you paste code that for sure works with sklearn datasets? Btw. full example in documentation for iris and/or dataset in csv file would be great.

jeregrine commented 7 years ago

I am using OSX. I installed through pip.

On Tue, Dec 13, 2016 at 6:02 PM mglowacki100 notifications@github.com wrote:

I've renamed the file to auto_machine.py , but result is the same.

runfile('/home/mglowacki/Desktop/auto_machine.py', wdir='/home/mglowacki/Desktop') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile execfile(filename, namespace) File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile builtins.execfile(filename, *where) File "/home/mglowacki/Desktop/auto_machine.py", line 8, in from auto_ml import Predictor File "auto_ml.py", line 8, in from auto_ml import Predictor ImportError: cannot import name Predictor

I've also tried to run from terminal instead of spyder, but result is the same. Thanks for info regarding logloss and predict_proba :)

Here is result of pip install:

mglowacki@mglowacki:~/Desktop$ sudo -H pip install auto_ml Requirement already satisfied: auto_ml in /usr/local/lib/python2.7/dist-packages Requirement already satisfied: scikit-learn in /usr/local/lib/python2.7/dist-packages (from auto_ml) Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages/scipy-0.18.0rc2-py2.7-linux-x86_64.egg (from auto_ml) Requirement already satisfied: pandas in /usr/local/lib/python2.7/dist-packages/pandas-0.18.1-py2.7-linux-x86_64.egg (from auto_ml) Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages/python_dateutil-2.5.3-py2.7.egg (from auto_ml) Requirement already satisfied: pathos in /usr/local/lib/python2.7/dist-packages (from auto_ml) Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages/pytz-2016.6.1-py2.7.egg (from pandas->auto_ml) Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python2.7/dist-packages (from pandas->auto_ml) Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil->auto_ml) Requirement already satisfied: multiprocess>=0.70.4 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml) Requirement already satisfied: pox>=0.2.2 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml) Requirement already satisfied: ppft>=1.6.4.5 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml) Requirement already satisfied: dill>=0.2.5 in /usr/local/lib/python2.7/dist-packages (from pathos->auto_ml)

Maybe there is a problem in a way I use iris dataset. Could you paste code that for sure works with sklearn datasets? Btw. full example in documentation for iris and/or dataset in csv file would be great.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ClimbsRocks/auto_ml/issues/148#issuecomment-266901418, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGKFhzSDAQ1UQiLCCVOoKnIm876lsdRks5rHzImgaJpZM4LLN_6 .

ClimbsRocks commented 7 years ago

@mglowacki100 @jeregrine : thanks for working with me on this!

  1. self-contained working code (great idea- I'll be adding this to the README and docs).
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split

from auto_ml import Predictor

boston = load_boston()
df_boston = pd.DataFrame(boston.data)
df_boston.columns = boston.feature_names
df_boston['MEDV'] = boston['target']
df_boston_train, df_boston_test = train_test_split(df_boston, test_size=0.33, random_state=42)

column_descriptions = {
    'MEDV': 'output'
    , 'CHAS': 'categorical'
}

ml_predictor = Predictor(type_of_estimator='regressor', column_descriptions=column_descriptions)
ml_predictor.train(df_boston_train)

test_score = ml_predictor.score(df_boston_test, df_boston_test.MEDV)
  1. The stack trace above contains this elusive line
    File "auto_ml.py", line 8, in <module>
    from auto_ml import Predictor

    This isn't a file that's in the auto_ml source code anywhere. Maybe pip makes this file. Regardless, the issue seems to come from trying to import Predictor from this file, and not being able to.

Could you locate this auto_ml.py file, and copy/paste it's contents here? I think that'll get us the next step we need in debugging this!

mglowacki100 commented 7 years ago
  1. Thanks for example! Sample code works fine. It is strange.

My old example gives now different error, but it is not related to auto_ml directly. So your example is really handy to start :)

>>> runfile('/home/mglowacki/Desktop/auto_machine.py', wdir='/home/mglowacki/Desktop')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/home/mglowacki/Desktop/auto_machine.py", line 15, in <module>
    col_desc_dictionary = {col_to_predict: 'output'}
TypeError: unhashable type: 'numpy.ndarray'
>>> 
  1. I've tried to open auto_ml.py from stack trace, but I can't open it. I suppose that problem is that both files auto_ml.py and auto_machine.py are in the same directory (Desktop), so python gets confused.

Thank you for your help!

ClimbsRocks commented 7 years ago

awesome, glad you got the example working!

@jeregrine : do you mind running the example code, and if it fails, sending me the exact stack trace you ran into? And if you have any files/folders called "auto_ml", make sure those are renamed to something else, otherwise Python will try to import this library from the code you wrote :)

jeregrine commented 7 years ago

That was it! the file name was auto_ml.py man I feel dumb .

On Wed, Dec 14, 2016 at 1:06 PM, Preston Parry notifications@github.com wrote:

awesome, glad you got the example working!

@jeregrine https://github.com/jeregrine : do you mind running the example code, and if it fails, sending me the exact stack trace you ran into? And if you have any files/folders called "auto_ml", make sure those are renamed to something else, otherwise Python will try to import this library from the code you wrote :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ClimbsRocks/auto_ml/issues/148#issuecomment-267125445, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGKFtVC_5_ZdMb-blRybuZkGBlEcQnCks5rID5KgaJpZM4LLN_6 .

ClimbsRocks commented 7 years ago

ha- no worries. we've all been there. thanks for following up, and for filing the issue in the first place! let me know if you have any ideas for improving things, or what parts of the documentation are most unclear.