[英]Getting an error while executing this python code related to the shape of the matrix
我正在嘗試執行這段pythoncode。但這顯示錯誤。請幫助我解決此錯誤。
import numpy as np
import matplotlib.pyplot as pt
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
data=pd.read_csv('train.csv').as_matrix()
clf=DecisionTreeClassifier()
xtrain=data[0:21000,1:]
train_label=data[0:21000,0]
clf.fit(xtrain,train_label)
xtest=data[21000:,1:]
actual_label=data[21000:,0]
d=xtest[8]
d.shape(28,28)
pt.imshow(255-d,cmap='gray')
print(clf.predict([xtest[8]]))
pt.show()
錯誤顯示如下
TypeError: 'tuple' object is not callable
我猜你想要:
d = d.reshape(28,28)
d.shape
是形狀的元組,顯然不能用兩個參數(28 和 28)調用。 也reshape
返回新數組,它不會就地重新整形。
此行中的錯誤:
d.shape(28,28)
只需運行:
d.shape
Shape 是一個屬性,它返回一個表示 DataFrame 維度的元組。
如果要更改形狀,請使用:
d = d.reshape(28,28)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.