0

I am a beginner in python and data mining. I am encountering an import error while trying to implement a simple classification using test and split method of sklearn. My python version is 3.6 and all pertaining packages are latest. Can anyone suggest me the possible reasons for the problem and if possible, the possible solution? Thanks in advance.

[N.T.: I have attached the code segment and generated errors below]

Code Segment:

import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import neighbors
import pandas as pd

df = pd.read_csv('breast-cancer-wisconsin.data')
df.replace('?', -9999, inplace=True)
df.drop(['id'], 1, inplace=True)

X = np.array(df.drop(['class'], 1))
y = np.array(df['class'])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

clf = neighbors.KNeighborsClassifier()
clf.fit(X_train, y_train)

accuracy = clf.score(X_test, y_test)

print(accuracy) 

Error Segment:

Traceback (most recent call last):
  File "C:/Users/Mahin/Google Drive/Workspace/Local Accuracy of Classifiers/Learning/LearningRegression.py", line 2, in <module>
    from sklearn.model_selection import train_test_split
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\sklearn\__init__.py", line 134, in <module>
    from .base import clone
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\sklearn\base.py", line 13, in <module>
    from .utils.fixes import signature
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
    from .validation import (as_float_array,
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
    from ..utils.fixes import signature
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\sklearn\utils\fixes.py", line 144, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr  # noqa
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\scipy\sparse\linalg\__init__.py", line 118, in <module>
    from .matfuncs import *
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\scipy\sparse\linalg\matfuncs.py", line 19, in <module>
    import scipy.special
  File "C:\Users\Mahin\Google Drive\Workspace\Local Accuracy of Classifiers\venv\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
    from ._ufuncs import *
ImportError: DLL load failed: The specified procedure could not be found.
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Mahin
  • 449
  • 2
  • 14
  • 25

1 Answers1

1

One or more of the dependent packages were not properly installed.

If you are using Anaconda or virtualenv, you should try creating a new environment and install the necessary packages from scratch.

If not, I would try re-installing sklearn:

  • Uninstall sklearn and re-install it according to the official instructions (e.g. use Anaconda)
  • If that doesn't work, try running pip uninstall scipy and then pip install scipy or some of the other sklearn dependencies
R.F. Nelson
  • 2,254
  • 2
  • 12
  • 24
  • Tried uninstalling and reinstalling sklearn and scipy manually, from PyCharms-->Settings-->Project Interpreter. Unfortunately, none works. – Mahin May 16 '18 at 18:15
  • 1
    Are you using Anaconda or virtualenv? If not, [you should be](https://stackoverflow.com/questions/41972261/what-is-a-virtualenv-and-why-should-i-use-one). If you are, you should try creating a new environment and install the necessary packages from scratch. – R.F. Nelson May 16 '18 at 21:37
  • Yeah, Installing Anaconda and creating new environment worked. – Mahin May 17 '18 at 03:01