logo
Loading...

TypeError: 'NoneType' object is not subscriptable - Cupoy

class Record_tp_tn(Callback): ""&quo...

TypeError: 'NoneType' object is not subscriptable

2020/10/08 09:34 下午
機器學習新手論壇
Shih Cheng Chen
觀看數:0
回答數:3
收藏數:0

``` class Record_tp_tn(Callback): """Code Here 撰寫一個紀錄 ture positive 與 true negative 數量的 callbacks """ def on_train_begin(self, epoch, logs = {}): logs = logs or {} record_items = ["val_auc", "val_f1sc", "val_fp", "val_fn", "val_tp", "val_tn"] for i in record_items: try: if i not in self.params['metrics']: self.params['metrics'].append(i) except: self.params['metrics'] = i def on_epoch_end(self, epoch, logs = {}, thres=0.5): logs = logs or {} y_true = self.validation_data[1].argmax(axis = 1) y_pred = self.model.predict(self.validation_data[0]) y_pred = (y_pred[:, 1] >= thres) * 1 logs["val_tp"] = sum(y_true*y_pred) logs["val_tn"] = sum((y_true==0) & (y_pred==0)) ``` 以上是Day88 homework,要求出TruePositive & TrueNegitive 執行到y_true = self.validation_data[1].argmax(axis = 1) 會出現TypeError: 'NoneType' object is not subscriptable 看不懂這個錯誤,網路上找不到解法。 請求大神幫忙。感謝。