2017-09-04 183 views
-1

我最初得到一個錯誤從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]) 
+3

在'txt'中省略'e'--它叫'loadtxt'。 :) – MSeifert

回答

4

的錯誤是很明確的。 numpy沒有任何功能loadtext。你當然打算:

np.loadtxt 
+0

但我加載導入numpy爲np? – Wolfy

+0

@Wolfy它應該是np.loadtxt而不是np.loadtext – deaspo

相關問題