我正在使用带有python 3的anaconda。在spyder中我运行以下代码
import pandas as pd
import quandl
import math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.leanear_model import LearnRegression
df = quandl.get('WIKI/GOOGL')
df = df[['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume',]]
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Close']) / 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']]
forecast_col='Adj. Close'
df.fillna(-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)
X=X[:-forecast_out+1]
df.drona(inplace=True)
y = np.array(df['label'])
print(len(X),len(y))
但显示以下错误
runfile('C:/Users/jayram/.spyder-py3/temp.py', wdir='C:/Users/jayram/.spyder-py3')
C:\Users\jayram\Anaconda3\lib\site-packages\sklearn\cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "<ipython-input-1-f93a3ccc2710>", line 1, in <module>
runfile('C:/Users/jayram/.spyder-py3/temp.py', wdir='C:/Users/jayram/.spyder-py3')
File "C:\Users\jayram\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\jayram\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/jayram/.spyder-py3/temp.py", line 6, in <module>
from sklearn.leanear_model import LearnRegression
ModuleNotFoundError: No module named 'sklearn.leanear_model'
答案 0 :(得分:0)
它是linear_model,而不是leanear。
http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
此外,您的代码似乎根本不使用该模块中的类,因此您只需删除该行