python-3.xmachine-learningtpot

Cannot import tpot


I have installed tpot machine learning library after following all the steps given here: http://epistasislab.github.io/tpot/installing/

When i look at pip3 list, i could see the tpot installed. enter image description here

The below is my simple source code [https://github.com/EpistasisLab/tpot]:

from tpot import TPOTClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
digits = load_digits()
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target,
                                                    train_size=0.75, test_size=0.25)

tpot = TPOTClassifier(generations=5, population_size=20, verbosity=2)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('tpot_mnist_pipeline.py')

I get the below error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from tpot import TPOTClassifier
ModuleNotFoundError: No module named 'tpot'

I am not sure what's causing this now. I checked the GitHub issues of the module and followed all solutions given there. I am using Max OS high Sierra and Python installed through Homebrew


Solution

  • I had the same issue, and it appears to be due to the script being named tpot.py. Change it to something else and it should work :)