日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ML/DL常用评估方法

發(fā)布時(shí)間:2024/7/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ML/DL常用评估方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import bisect from sklearn import metrics from sklearn.metrics import precision_recall_curve# 創(chuàng)建一個(gè)單獨(dú)的Metircs.py文件 def calc_auc(y_true, y_pred): # y_pred:[0,1]之間任何數(shù)return metrics.roc_auc_score(y_true, y_pred)def calc_ks(y_true, y_pred): # y_pred:[0,1]之間任何數(shù)fpr, tpr, thresholds = metrics.roc_curve(y_true, y_pred)return max(tpr - fpr)def calc_acc(y_true, y_pred): # y_pred:{0,1} 必須事先通過(guò)閾值轉(zhuǎn)變?yōu)?,1return metrics.accuracy_score(y_true, y_pred)def calc_f1(y_true, y_pred): # y_pred:{0,1} 必須事先通過(guò)閾值轉(zhuǎn)變?yōu)?,1return metrics.recall_score(y_true, y_pred), metrics.precision_score(y_true, y_pred), metrics.f1_score(y_true, y_pred)# 召回率大于0.9時(shí)的準(zhǔn)確率 def precision_at_r9(y_true, y_pred):p, r, tresholds = precision_recall_curve(y_true, y_pred)ind = bisect.bisect(r, 0.9)if ind >= len(p)-1:return r[-2], p[-2], tresholds[-1]else:return r[ind], p[ind], tresholds[ind]# 準(zhǔn)確率大于0.9時(shí)的召回率 def recall_at_p9(y_true, y_pred):p, r, tresholds = precision_recall_curve(y_true, y_pred)ind = bisect.bisect(p, 0.9)if ind >= len(p)-1:return r[-2], p[-2], tresholds[-1]else:return r[ind], p[ind], tresholds[ind]

NDCG@K

def get_dcg(y_pred, y_true, k):# 注意y_pred與y_true必須是一一對(duì)應(yīng)的,而且y_pred越大越接近label=1(用相關(guān)性的說(shuō)法就是,與label=1越相關(guān))df = pd.DataFrame({"y_pred": y_pred, "y_true": y_true})df = df.sort_values(by="y_pred", ascending=False) # 對(duì)y_pred進(jìn)行降序排列,越排在前面的,越接近label=1df = df.iloc[0:k, :] # 取前K個(gè)dcg = (2 ** df["y_true"] - 1) / np.log2(np.arange(1, df["y_true"].count() + 1) + 1) # 位置從1開(kāi)始計(jì)數(shù)dcg = np.sum(dcg)return dcgdef calc_ndcg(y_true, y_pred, k):dcg = get_dcg(y_pred, y_true, k)idcg = get_dcg(y_true, y_true, k)ndcg = dcg / idcgreturn ndcg

Recall@K,Precision@K

def calc_f1(y_true, y_pred, k): df = pd.DataFrame({"y_pred": y_pred, "y_true": y_true})df = df.sort_values(by="y_pred", ascending=False) # 對(duì)y_pred進(jìn)行降序排列,越排在前面的,越接近label=1df = df.iloc[0:k, :] # 取前K個(gè)y_true = np.array(df["y_true"])y_pred = np.round(np.array(df["y_pred"])) # y_pred:{0,1} 必須事先通過(guò)閾值轉(zhuǎn)變?yōu)?,1return recall_score(y_true, y_pred), precision_score(y_true, y_pred), f1_score(y_true, y_pred)

總結(jié)

以上是生活随笔為你收集整理的ML/DL常用评估方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。