Pycharm错误,numpy没有属性'loadtext'

时间:2017-09-04 21:54:22

标签: python numpy pycharm

我最初从pycharm下载scipy时遇到错误,所以我按照here找到的步骤下载了numpy + mkl和scipy。我看到我的项目解释器上有pycharm。但现在我收到以下错误:

    Traceback (most recent call last):
  File "C:/Users/Morgan Weiss/PycharmProjects/MachineLearningHW1/HW1.py", line 7, in <module>
    train_data = np.loadtext('C:/Users/Morgan Weiss/Desktop/STA 5635/DataSets/arcene/arcene_train.data')
AttributeError: module 'numpy' has no attribute 'loadtext'

我不知道如何解决这个问题,为了完整起见,这是我的整个代码:

from sklearn import tree
import numpy as np


# Load Data
train_data = np.loadtext('C:/Users/Morgan Weiss/Desktop/STA 5635/DataSets/arcene/arcene_train.data')
train_labels = np.loadtext('C:/Users/Morgan Weiss/Desktop/STA 5635/DataSets/arcene/arcene_train.labels')
test_data = np.loadtext('C:/Users/Morgan Weiss/Desktop/STA 5635/DataSets/arcene/arcene_test.data')
test_labels = np.loadtext('C:/Users/Morgan Weiss/Desktop/STA 5635/DataSets/arcene/arcene_test.labels')

# Error
error_train = []
error_test = []

# Make decision tree
for i in range(1,13):
    DT = tree.DecisionTreeClassifier(max_depth = i)
    DT = DT.fit(train_data,train_labels)
    error_train.append(1 - DT.score(train_data,train_labels))
    error_test.append(1 - DT.score(test_data,test_labels))

# Print out depth, training, and testing error
for i in range(12):
    print(i+1, error_train[i], error_test[i])

1 个答案:

答案 0 :(得分:7)

错误很明确。 numpy没有任何功能loadtext。你肯定打算:

np.loadtxt