2017-09-09 57 views
0

TypeError: 'module' object is not callableTypeError:'模塊'對象不可調用,cross_validation Python3

當試圖使用cross_validation我得到上面的錯誤。我不確定如何解決這個問題。由於我對此很新,所以我非常感謝任何幫助。

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

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. Open'])/df['Adj. Open'] * 100 
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open'])/df['Adj. Open'] * 100 

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) 
y = np.array(df['label']) 

x_train, x_test, y_train, y_test = cross_validation(x, y, test_size=0.2) 

clf = LinearRegression 
clf.fit(x_train, y_train) 

accuracy = clf.score(x_test, y_test) 

print(accuracy) 

回答

0

名稱cross_validation標識模塊,函數的名稱是train_test_split(見sklearn documentation)。

使用點符號來調用函數:

cross_validation.train_test_split(x, y, test_size=0.2) 
相關問題