TypeError: 'module' object is not callable
When trying to use cross_validation
I get the error above. I'm not really sure how to solve this. Since I'm pretty new to this so I'd really appreciate any help.
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)
The name cross_validation
identifies a module, the name of the function is train_test_split
(see sklearn documentation ).
Use the dot notation to call the function instead:
cross_validation.train_test_split(x, y, test_size=0.2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.