TypeError:"module"对象不可调用,cross_validation Python3



typeError:'模块'对象不是可呼叫

尝试使用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)

名称 cross_validation标识一个模块,该函数的名称为 train_test_split(请参阅Sklearn Documentation)。

使用点符号来调用该函数:

cross_validation.train_test_split(x, y, test_size=0.2)

相关内容

  • 没有找到相关文章

最新更新