def kappa_reg(y, y_pred): from helperFunctions import quadratic_weighted_kappa, histogram, confusion_matrix, convert_reg return quadratic_weighted_kappa(y, convert_reg(y_pred))
def kappa_reg(y,y_pred): from helperFunctions import quadratic_weighted_kappa, histogram, confusion_matrix,convert_reg return quadratic_weighted_kappa(y,convert_reg(y_pred))
############ train = pd.read_csv("../data/train.csv") train_train, valid_train, train_target, valid_target = train_test_split(train,train.median_relevance,test_size=0.20,random_state=2) test_set = pd.read_csv("../data/test.csv") files = [x for x in listdir("../data/") if x.startswith("pred_")] valid = zeros((2032,len(files)),dtype="float") test = zeros((22513,len(files)),dtype="float") for i in range(len(files)): valid[:,i] = pd.read_csv("../data/"+files[i].replace('pred','valid'))['pred'].values test[:,i] = pd.read_csv("../data/"+files[i])['prediction'].values valid_train['var'] = var(valid,axis=1) valid_train['pred_raw'] = mean(valid,axis=1) valid_train['pred'] = valid_train['pred_raw'].copy() tmp = valid_train['var'] > args.variance valid_train['pred'][tmp] = valid_train[tmp].pred_raw.apply(lambda x: 1 if x < args.lower else 4 if x > args.upper else x).values valid_train['pred'] = roundCut(valid_train['pred'],args.cut) print "Mean:", quadratic_weighted_kappa(valid_train.pred.astype(int),valid_target) test_set['var'] = var(test,axis=1) test_set['pred_raw'] = mean(test,axis=1) test_set['pred'] = test_set['pred_raw'].copy() tmp = test_set['var'] > args.variance test_set['pred'][tmp] = test_set[tmp].pred_raw.apply(lambda x: 1 if x < args.lower else 4 if x > args.upper else x).values test_set['pred'] = roundCut(test_set['pred'],args.cut) pd.DataFrame({'id':test_set.id,'prediction':test_set['pred'].astype(int)}).to_csv("../data/pred.csv",index=False)