econ
econ

Reputation: 525

Sklearn syntax error?

I am learning by this site(https://pythonprogramming.net/training-testing-machine-learning-tutorial/), part 4. This is my code(copied, with Quandl having lowercase q as is correct in newer version and model_selection instead of cross_validation for same reason).

import quandl, math
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn import model_selection
from sklearn import svm
from sklearn.linear_model import LinearRegression

df = quandl.get("WIKI/GOOGL")
print(df.head())
print(df.tail())
df = df[['Adj. Open',  'Adj. High',  'Adj. Low',  'Adj.                             
             Close', 'Adj. Volume']]

df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) /         
df['Adj. Close'] * 100.0
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) /         
    df['Adj. Open'] * 100.0
df = df[['Adj. Close', 'HL_PCT', 'PCT_change', 'Adj. 
   Volume']]
print(df.head())
forecast_col = 'Adj. Close'
df.fillna(value=-99999, inplace=True)
forecast_out = int(math.ceil(0.01 * len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)
df.dropna(inplace=True)
X = np.array(df.drop(['label'], 1))
y = np.array(df['label'])
X = preprocessing.scale(X)
y = np.array(df['label'])
X_train, X_test, y_train, y_test =         
    model_selection.train_test_split(X, y, test_size=0.2)

clf = svm.SVR()
clf.fit(X_train, y_train)
confidence = clf.score(X_test, y_test)
print(confidence)

Error is:

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/learn_python_the_hard_way/LEARN.py", line 4, in <module>
    from sklearn import preprocessing
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\__init__.py", line 57, in <module>
    from .base import clone
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\base.py", line 10, in <module>
    from scipy import sparse
  File "C:\Users\PycharmProjects\learn_python_the_hard_way\scipy.py", line 1
    from scip
            ^
SyntaxError: invalid syntax

I don't have any idea how to solve this, any help will be greatly appreciated!

UPDATE: I had scipy.py file created for doing scipy exercises in same file as is the one I'm practicing right now and now deleted it. Error is:

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/learn_python_the_hard_way/LEARN.py", line 4, in <module>
    from sklearn import preprocessing
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\__init__.py", line 57, in <module>
    from .base import clone
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\base.py", line 10, in <module>
    from scipy import sparse
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\__init__.py", line 61, in <module>
    from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'

I checked, numpy is installed and working!

Upvotes: 0

Views: 4962

Answers (2)

econ
econ

Reputation: 525

SOLVED: altought numpy was install I had to specificaly install wheel for numpy+mkl

Upvotes: 0

jasonharper
jasonharper

Reputation: 9597

You have a file named scipy.py (in C:\Users\PycharmProjects\learn_python_the_hard_way) that is being found before the actual SciPy installation (presumably in your Python lib directory). You need to rename it.

Upvotes: 1

Related Questions