Import error while importing MLPClassifier - scikit-learn

I'm facing the below error when I try to run :
from sklearn.neural_network import MLPClassifier
Error :
from sklearn.neural_network import MLPClassifier
Traceback (most recent call last):
File "<ipython-input-77-6113b65dfa44>", line 1, in <module>
from sklearn.neural_network import MLPClassifier
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\neural_network\__init__.py", line 10, in <module>
from .multilayer_perceptron import MLPClassifier
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 18, in <module>
from ..model_selection import train_test_split
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\model_selection\__init__.py", line 23, in <module>
from ._search import GridSearchCV
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py", line 32, in <module>
from ..utils.fixes import rankdata
**ImportError: cannot import name 'rankdata'**

If you already have a working installation of numpy and scipy:
pip install -U scikit-learn
otherwise:
conda install scikit-learn
finally check for updates:
conda update pip

Related

no module named "tensorflow.python.platform" when importing tensorflow || tflearn on python shell

I am running python 3.7 on a windows 10 pc
i have been having trouble importing tensorflow or tflearn in my python project
every time after running
import tflearn
import tensorflow
i always end up getting the same error
import tflearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python37\lib\site-packages\tflearn\__init__.py", line 4, in <module>
from . import config
File "C:\Program Files\Python37\lib\site-packages\tflearn\config.py", line 3, in <module>
import tensorflow as tf
File "C:\Users\genes\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\genes\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\genes\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\pywrap_tensorflow.py", line 25, in <module>
from tensorflow.python.platform import self_check
ModuleNotFoundError: No module named 'tensorflow.python.platform'
any idea on how to solve this for both tflearn && tensorflow import..
You can try this:
pip install tflearn
After this try importing tflearn again

Error while importing load_model from keras.model

I am trying to import my keras model which I have saved as .h5 file. But the very first line of my import gives me error. This is the line which gives error
from keras.models import load_model
I checked all the dependencies and that is ok. I have Keras 2.2.4. Error that I am getting:
Using TensorFlow backend.
Traceback (most recent call last):
File "drive1.py", line 1, in <module>
from keras.models import load_model
File "E:\python3.6.6\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "E:\python3.6.6\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "E:\python3.6.6\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "E:\python3.6.6\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "E:\python3.6.6\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import * # pylint: disable=redefined-builtin
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "E:\python3.6.6\lib\site-packages\google\protobuf\__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "E:\python3.6.6\lib\site-packages\pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
I feel like there is some package versions mismatch but not sure what should I check further. I am using pip for installing packages.
Finally from some reference I found that there was some version mismatch between my python and pip. Actually I was should have focused on following error message:
__import__('pkg_resources').declare_namespace(__name__)
And the thing which helped was
python -m ensurepip --upgrade

I am getting this error "No module named 'darkflow.cython_utils.cy_yolo_findboxes'" When I am using darknet

When I try to use Pycharm to play with YOLO, I got the error.
Here is what I got, Any help will be appreciated.
Node: I have done python3 setup.py build_ext --inplace. All the file like cy_yolo_findboxes.c and cy_yolo2_findboxes are all inside the cython_utils folder. But it does not work.
import cv2
import sys
sys.path.append('/Users/hantaoliu/darkflow-master')
import tensorflow as tf
from darkflow.net.build import TFNet
import numpy as np
import time
option = {
'model': 'cfg/yolo.cfg',
'load': 'bin/yolo.weights',
'threshold': 0.15,
'gpu': 1.0
}
capture = cv2.VideoCapture('videofile1.mp4')
colors =[tuple(255 * np.random(3)) for i in range(5)]
for color in colors:
print(color)
Here are the error message
Traceback (most recent call last):
File "/Users/hantaoliu/PycharmProjects/YOLO/sample.py", line 5, in <module>
from darkflow.net.build import TFNet
File "/Users/hantaoliu/darkflow-master/darkflow/net/build.py", line 7, in <module>
from .framework import create_framework
File "/Users/hantaoliu/darkflow-master/darkflow/net/framework.py", line 1, in <module>
from . import yolo
File "/Users/hantaoliu/darkflow-master/darkflow/net/yolo/__init__.py", line 2, in <module>
from . import predict
File "/Users/hantaoliu/darkflow-master/darkflow/net/yolo/predict.py", line 7, in <module>
from ...cython_utils.cy_yolo_findboxes import yolo_box_constructor
ImportError: No module named 'darkflow.cython_utils.cy_yolo_findboxes'
Build the cython module
cd ./cython_utils
python3 setup.py build_ext --inplace

Python Sklearn import error

I'm new to machine learning libraries in python. I've installed 'python 3.4'.
I've also installed scikit-learn , numpy and scipy from wheel files.
scikit_learn-0.18.1-cp34-none-win_amd64
scipy-0.16.0-cp34-none-win_amd64
numpy-1.9.2-cp34-none-win_amd64.whl
import scipy
import numpy
above statements are working fine. but when i try to execute import sklearn
i get below error
Traceback (most recent call last):
File "C:\Users\Usman\Desktop\hello_python.py", line 1, in <module>
import sklearn
File "C:\Python34\Lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Python34\Lib\site-packages\sklearn\base.py", line 12, in <module>
from .utils.fixes import signature
File "C:\Python34\Lib\site-packages\sklearn\utils\__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "__init__.pxd", line 155, in init sklearn.utils.murmurhash (sklearn\utils\murmurhash.c:6319)
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96
--edit
when i execute import sklearn from python shell i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\Lib\site-packages\sklearn\__init__.py", line 56, in <module>
from . import __check_build
ImportError: cannot import name '__check_build'
I've searched but couldn't find anything helpful. Kindly help me remove this error.

Cython with Numpy / AttributeError: 'module' object has no attribute 'Handler'

I want to use Numpy in Cython, but encountered the following error. This error happens even if I run the simple code, so it should be an issue related to importing Numpy.
My environment:
OS X Yosemite
Python 3.4.3
setup.py:
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'my_code',
ext_modules = cythonize('my_code.pyx'),
include_path = [numpy.get_include()]
)
my_code.pyx:
cimport numpy as np
cdef int a
Execute in Terminal:
$ python3 setup.py build_ext --inplace
Traceback (most recent call last):
File "/Users/***/setup.py", line 1, in <module>
import numpy as np
File "/usr/local/lib/python3.4/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python3.4/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python3.4/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python3.4/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python3.4/site-packages/numpy/core/__init__.py", line 58, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python3.4/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py", line 253, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: 'module' object has no attribute 'Handler'
Old question but I ran into this because I had a very similar issue with numpy.
It turns out I had a directory named logging as a sibling of the script I was trying to run. So the problem was a simple naming collision between my local project folder and the logging module numpy expected to find. Renaming the project logging folder solved the issue for me.
Looking at OP's error message, I suspect this was the case for them as well.

Resources