我最初得到一個錯誤從pycharm下載scipy,所以我按照here找到了下載numpy + mkl和scipy的步驟。我看到在我的項目解釋器上有pycharm。但現在我收到以下錯誤:Pycharm錯誤,numpy沒有屬性'loadtext'
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])
在'txt'中省略'e'--它叫'loadtxt'。 :) – MSeifert