Scikit Learn import error: 'cross_val_predict' is not defined - scikit-learn

I am trying to run some simple codes of scikit-learn in python, and while executing this, I encountered this error:
from sklearn.cross_validation import cross_val_predict
Traceback (most recent call last):
File "", line 1, in
from sklearn.cross_validation import cross_val_predict
ImportError: cannot import name cross_val_predict
I have downloaded scikit learn from this page: http://sourceforge.net/projects/scikit-learn/?source=typ_redirect and the other modules like sklearn.linear_model works well. It seems that I can also import successfully the module cross_validation.. I cannot understand!

Yes ! It seems works now ! In fact, instead of using the .exe files that I downloaded from internet (which turned out to be perhaps incompatible), I finally successed to install many modules by the standard "pip install". The only thing that I could not use "pip install" is the package "Scipy", so I had to replace it by a .exe file. Thank you for all your help !

Related

cannot import s3fs in pyspark

When i try importing the s3fs library in pyspark using the following code:
import s3fs
I get the following error:
An error was encountered: cannot import name 'maybe_sync' from
'fsspec.asyn' (/usr/local/lib/python3.7/site-packages/fsspec/asyn.py)
Traceback (most recent call last): File
"/usr/local/lib/python3.7/site-packages/s3fs/init.py", line 1, in
from .core import S3FileSystem, S3File File "/usr/local/lib/python3.7/site-packages/s3fs/core.py", line 12, in
from fsspec.asyn import AsyncFileSystem, sync, sync_wrapper, maybe_sync ImportError: cannot import name 'maybe_sync' from
'fsspec.asyn' (/usr/local/lib/python3.7/site-packages/fsspec/asyn.py)
The fsspec package has been installed in my notebook. And I actually had been using it fine for a long time, when this suddenly happened.
I tried googling, but could not find this specific error.
Has anyone come across this before? And if so, do you know how to solve it?
Glad to hear this wasn't just me. It looks like if you pip install versions s3fs==0.5.1 and fsspec==0.8.3, that should fix it.

Scipy install help windows 10

I am trying to get scipy running on my computer and I have been fighting for the last few hours with it. Currently, im running python 3.6 and I am on windows 10. I first tried to install it using pip which failed no matter what I did. Then I went and downloaded the wheel file and installed it manually using pip. Then I used pip to get the rest of the dependencies like the website stated pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose. It installed the rest of the packages just fine.
If I say in IDEL
import scipy
It will give me an error of
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from scipy import special, optimize
File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\__init__.py", line 116, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
if I go in that file to comment out that line, it will import but it after that I get a lot more errors anytime I try and do anything.
Also, I tried installing anaconda as a dependency manager and that seemed to work fine for installing, but if I tried to used Atom or IDLE as my text editor it can't seem to find scipy when its compiling and throws and error. I am kinda at a loss and any advice or help on this would be much appreciated. Thank you in advance.

ImportError: No module named keras.preprocessing

Following the tutorial:
http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/#comment-419896
Using these files:
https://github.com/fchollet/deep-learning-models
I get 2 separate errors depending on how I execute:
Running in PyCharm:
Using TensorFlow backend.
usage: test_imagenet.py [-h] -i IMAGE
test_imagenet.py: error: the following arguments are required: -i/--image
Running in cmd line:
C:\Users\AppData\Local\Programs\Python\Python35\Scripts>python deep-learning-models/test_imagenet.py --image deep-learning-models/images/dog.jpg
Traceback (most recent call last):
File "deep-learning-models/test_imagenet.py", line 2, in <module>
from keras.preprocessing import image as image_utils
ImportError: No module named keras.preprocessing
How do I resolve?
Its best if you solve this problem outside running the above script... Here is what you can try in your command line environment to make sure it works outside your script:
>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'1.2.1'
>>> keras.preprocessing
<module 'keras.preprocessing' from '/usr/local/lib/python2.7/dist-packages/keras/preprocessing/__init__.pyc'>
>>> from keras.preprocessing import image as image_utils
>>>
Make sure you have latest version of keras installed. If you get above working then it could be the environment issue where above script is not able to find the keras package. However if above does not work or work partially you would need to install keras again by removing it first..
$ pip install keras --user
Every dependency in a python project need to be installed using pip or easy_install or from the source code. You will have to install the keras module as mentioned here.
This happened to me. It turned out I was working in a pyvenv which wasn't activated. Just run source bin/activate on Linux/Mac or Scripts\activate.bat on Windows
from keras.models import Sequential
from keras import legacy_tf_layer
from keras.preprocessing import image as image_utils
from keras.preprcessing.text import Toknizer
import pandas as pd
from sklearn.model_selection import train_test_spli

Implementing word2vec in python3 WITHOUT gensim

We're running into a lot of problems installing word2vec within python3. We just keep getting a standard error that python can't find the package it's looking for.
Competition-Repo/agents$ python3
Python 3.4.3 [GCC 4.8.4] on linux
import word2vec
Traceback (most recent call last):
File "", line 1, in ImportError: No module named 'word2vec'
Most everything I've found has either someone else's implementation of word2vec within python3, or is accessed through Gensim. The pip-install for python2 imports flawlessly, now we need to set up the same thing for python3.
Thanks!
-Ben
I just installed the product from Github site without incident on Python 3.4 but Win7Pro. It imports but who knows after that, right?
It comes with a setup.py. Being an inveterate experimenter I tried that, contrary to instructions. It failed.
At least this is easy to try, assuming you haven't already.
How exactly are you importing in python2?
With gensim, you can either import with -
from gensim.models import Word2Vec
or with -
from gensim.models import word2vec
The former is for the class Word2Vec and the latter for the module.
There is a tutorial here for getting started
The way we were able to install it was through:
sudo pip3 install cython
sudo pip3 install word2vec
Turned out to be a lot easier than I had thought..

sklearn.linear_model not found in TensorFlow Udacity course

I'm following the instructions of the Deep Learning course by Google with TensorFlow. Unfortunately I'm stuck with this workbook right now.
I work in the docker vm with all the assignment code loaded as described here.
When I do all the imports everything works except for following line:
from sklearn.linear_model import LogisticRegression
it throws the following error:
>>> from sklearn.linear_model import LogisticRegression
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn.linear_model
This SO answer sounds promising, but I did not find the source directory of sklearn.
Any help greatly aprreciated.
You can install and upgrade sklearn from the shell with pip. That may or may not be the problem - but at least you'll know its installed.
sudo pip install --upgrade scikit-learn
In your Jupyter notebook:
import pip
pip.main(['install', 'sklearn'])
Please take note that when you are writing your code, you'll import the sklearn package using import sklearn, but when installing the package it with, say, conda, you should do the following:
conda install scikit-learn

Resources