I have sklearn installed and I can import sklearn I can also import comb. I import numpy, import scipy. But when I try:
from sklearn.model_selection import cross_validation
or
from sklearn import svm
I get a traceback:
File "...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 25, in <module>
from scipy.misc import comb
ImportError: cannot import name 'comb'
Something may have gone wrong in your scipy installation. The issue can be solved by uninstalling and reinstalling the 2 libraries (scipy and sklearn).
Refer to this link
Related
I was trying to import :
from aikit.ml_machine import MlMachineLauncher
But I got the error :
from sklearn.metrics import silhouette_score, calinski_harabaz_score, davies_bouldin_score
ImportError: cannot import name 'calinski_harabaz_score' from 'sklearn.metrics'
I tried try/except but without result :
try:
from sklearn.metrics import calinski_harabasz_score
except ImportError:
from sklearn.metrics import calinski_harabaz_score
I have scikit-learn v0.23.2
Because they have changed the name to
calinski_harabasz_score
from
calinski_harabaz_score
just add the following line and your problem is solved
from sklearn.metrics import calinski_harabasz_score
We just released a new version 0.2.2 which fixes the compatibility with sklearn>=0.23.
You can now update both:
pip install scikit-learn==0.23.2
pip install aikit==0.2.2
```
I am using Python 3.7.3 installed from Anaconda. It has installed Ipython: I can invoke Ipython from the command line and running the following code in Jupyter notebooks I can see the ipython as an installed package
import subprocess
import sys
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
installed_packages = [r.decode().split('==')[0] for r in reqs.split()]
print (installed_packages)
However in the same Jupyter notebook when I run the following code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pydotplus
from Ipython.display import Image
from sklearn.linear_model import LogisticRegression
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
from sklearn.decomposition import FactorAnalysis
from sklearn.cluster import KMeans
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,accuracy_score,f1_score
I get the error returned : ModuleNotFoundError: No module named 'Ipython'
It's a Windows 10 machine. I tried reinstalling with conda install and conda update to no avail, and I tried variants of capitalisation.
You have a typo. The P in IPython is meant to be capitalized.
Use:
from IPython.display import Image
I am trying to do Kmeans with sklearn and I am getting weird error that says:
Traceback (most recent call last):
File "kmean_test.py", line 2, in <module>
from sklearn.cluster import KMeans
File "C:\Python\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
ModuleNotFoundError: No module named 'sklearn.cluster.spectral'
Working on Windows, I tried importing in Jupyter and just running a simple script from command.
I have tested my install of Scikit-Learn with the following imports and they work fine.
from sklearn import datasets
from sklearn import naive_bayes
First bit of code that i get the traceback error looks like:
import cv2, numpy as np
from sklearn.cluster import KMeans
def visualize_colors(cluster, centroids):
...
I got this import code
from sklearn.cluster import KMeans
from two tutorial sources but perhaps it is the problem? I have made attempts to import otherways but been unsuccessful
Just in case it was the sklearn install and because of reading through other stackoverflow suggestions I have:
I have tried uninstall and reinstall of numpy (with and without mkl), pandas, scikit-learn, and scipy both from regular command and admin command.
I have tried update as well.
I have downloaded the wheels and run install as administrator.
I am new. Please be kind. I am new to Windows development as well, Ugh! So if it has something to do with some complicated Windows system setup and software install etc etc I may not follow. I have spent 2 days trying to solve this one on my own and finally decided to reach out.
Thanks for any help!
UPDATE:
As per suggested below I have confirmed I do have the most recent version of sklearn 0.21.3
import sklearn
print(sklearn.__version__)
0.21.3
For the record here are my versions of the others:
python --version
Python 3.7.3
import numpy
numpy.version.version
'1.17.2'
import scipy
scipy.version.version
'1.3.1'
import pandas as pd
pd.__version__
'0.24.2'
Finally I would like to mention that I have been able to successfully apply Kmeans to my project without sklearn, however, I am trying to access the % and RGB values of the means. I have found two people showing how to do it and BOTH use sklearn. See here end comment by nathancy on why I am trying to install sklearn to do this specific thing: How to find the average colour of an image in Python with OpenCV?
You have installed an older version of sklearn.
from sklearn.cluster import KMeans with work only if you have the latest sklearn version which is 0.21.3
To check the version use:
import sklearn
print(sklearn.__version__)
Finally install sklearn latest version:
pip install -U scikit-learn
When I do pip freeze I see numpy and sklearn in my virtualenv. When
My runner.py consists of :
from preprocess import Data
def main():
pass
preprocess.py
from sklearn.preprocessing import RobustScaler
import numpy as np
I run jython runner.py I get the error:
from sklearn.preprocessing import RobustScaler
ImportError: No module named sklearn
Not sure why I can't find any of the packages I've installed.
I am learning to work with Tensorflow. I have installed most of the libraries.
# load libs
import torch
import argparse
from torchvision import datasets, transforms
import matplotlib.pyplot as plt
import numpy as np
from data.datasets import MNIST
import torch.utils.data as data_utils
from sklearn.decomposition import PCA
import torch.nn.functional as F
from torch.autograd import Variable
But I am facing an error like this:
ImportError Traceback (most recent call last)
<ipython-input-8-257b7af364e1> in <module>()
5 import matplotlib.pyplot as plt
6 import numpy as np
----> 7 from data.datasets import MNIST
8 import torch.utils.data as data_utils
9 from sklearn.decomposition import PCA
ImportError: No module named data.datasets
I have installed the "dataset" library using the following command:
sudo -H pip install dataset
But I am still seeing this error. I am using python 2.7.
I am pretty new to python. Can anyone help me in identifying the missing thing. Thanks in advance.
The dataset directory is placed next to main.py, so probably when you tried sudo -H pip install dataset you actually installed a irrelevant package.
So uninstall the wrong package and it would work:
sudo -H pip uninstall dataset