熊猫运行时间长



我正在为手动混淆矩阵编写一个程序。我不得不循环 10K 迭代。

df_a=df_a.sort_values('proba')
tpr_lst=[]
fpr_lst=[]
for i in tqdm(df_a['proba']): #df_a['proba'] contains 10K points, each point will be taken a new threshold to determine y_pred is 0 or 1, all this is too plot an ROC.
def y_pred_auc(x):
if x<i:
return 0
else:
return 1
df_a['y_pred_auc']=df_a['proba'].map(y_pred_auc)
df_a['con_mat_label_auc']=df_a[['y','y_pred']].apply(confusion_matrix,axis=1)
tp_count=len(df_a['con_mat_label_auc']=='TP')
fp_count=len(df_a['con_mat_label_auc']=='FP')
tn_count=len(df_a['con_mat_label_auc']=='TN')
fn_count=len(df_a['con_mat_label_auc']=='FN')
tpr_auc=tp_count/(tp_count+fn_count)
fpr_auc=fp_count/(tn_count+fp_count)
tpr_lst.append(tpr_auc)
fpr_lst.append(fpr_auc)

即使在 c4 AWS Sagemaker 实例上,此代码也需要大约一个小时。无论如何可以优化此代码,或者任何人都可以建议一个快速的AWS Sagemaker实例,我已经尝试过Colab,在那里它更糟。

Sagemaker ml.p2.xlarge 或使用 p2.xlarge。

使用后停止实例,避免多付费用。

https://course.fast.ai/start_sagemaker.html

最新更新