def testBestReRank(k,bestModel=None):
    if bestModel is None:
        model=CascadingModel(tasktype=modeltype,digtype=datatype)
    else:
        model=bestModel
    mymetric=model.mymetric
    mymetric.verbose=0
    taskids=data.taskids[:data.testPoint]
    Y_label=data.testLabel[:data.testPoint]

    print("tuning re-rank weight\n")
    best_param={3:0,5:0,10:0}
    rw=[w/10 for w in range(0,11)]
    rw.reverse()


    model.topK=k
    maxAcc=[0,0]
    model.loadConf()
    model.loadModel()
    Y_predict2=model.predict(data.testX,taskids)

    for w in rw:
            acc=mymetric.topKPDIGUsers(Y_predict2,Y_label,taskids,k,w)
            acc=np.mean(acc)
            if acc>maxAcc[0]:
                maxAcc=[acc,w]
                #print(data.tasktype,"top %d"%k,acc,"weight=%f"%(w/10))
    best_param[k]=maxAcc[1]
    print("\n",data.tasktype,"top %d"%k,maxAcc[0],"weight=%f"%maxAcc[1])
    print()
def testCascadingModel():
    model=CascadingModel(tasktype=modeltype)
    taskids=data.taskids[:data.testPoint]
    Y_label=data.testLabel[:data.testPoint]
    Y_sublabel=data.submitLabelClassification[:data.testPoint]
    Y_reglabel=data.registerLabelClassification[:data.testPoint]
    mymetric=model.mymetric
    mymetric.callall=False

    print()

    print("\n meta-learning model top k acc")
    for k in (3,5,10):
        model.topK=k
        model.loadConf()
        model.loadModel()
        Y_predict2=model.predict(data.testX,taskids)
        #metrics
        acc=mymetric.topKPossibleUsers(Y_predict2,Y_label,k)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        acc=mymetric.topKRUsers(Y_predict2,Y_label,Y_reglabel,k,)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        acc=mymetric.topKSUsers(Y_predict2,Y_label,Y_sublabel,k,)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        print()