我不知道如何解决这个问题,有人能给我解释一下吗?
我正在努力通过更改 DecisionTreeClassifier 的参数来在循环中获得最佳 precision_score
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import precision_score
from sklearn.model_selection import train_test_split
df = pd.read_csv('songs.csv')
X = df.drop(['song','artist','genre','lyrics'],axis=1)
y = df.artist
X_train,X_test,y_train,y_test = train_test_split(X,y)
scores_data = pd.DataFrame()
for depth in range(1,100):
clf = DecisionTreeClassifier(max_depth=depth,criterion='entropy').fit(X_train,y_train)
train_score = clf.score(X_train,y_train)
test_score = clf.score(X_test,y_test)
preds = clf.predict(X_test)
precision_score = precision_score(y_test,preds,average='micro')
temp_scores = pd.DataFrame({'depth':[depth],
'test_score':[test_score],
'train_score':[train_score],
'precision_score:':[precision_score]})
scores_data = scores_data.append(temp_scores)
这是我的错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-50-f4a4eaa48ce6> in <module>
17 test_score = clf.score(X_test,y_test)
18 preds = clf.predict(X_test)
---> 19 precision_score = precision_score(y_test,preds,average='micro')
20
21 temp_scores = pd.DataFrame({'depth':[depth],
**TypeError: 'numpy.float64' object is not callable**
这是数据集
https://i.stack.imgur.com/QJXSY.png
MMTTMM
相关分类