from numpy import * from pandas import read_csv import matplotlib.pyplot as plt from scipy.sparse import bsr_matrix from preProcess import preProcess from loadSparseData import loadSparseData from PA import PA fname1 = 'pu1' fname2 = 'pu2' fname3 = 'pu3' fname4 = 'pua' X1, Y1 = loadSparseData(fname1) X2, Y2 = loadSparseData(fname2) X3, Y3 = loadSparseData(fname3) X4, Y4 = loadSparseData(fname4) print 'preProcess X' X1 = preProcess(X1) X2 = preProcess(X2) X3 = preProcess(X3) X4 = preProcess(X4) print 'start COML' def update_CM(i, X, Y, w, u): x_t = X[i] f_t = dot(w, x_t) loss_w = max(0, 1 - Y[i] * f_t) if loss_w == 0: tau = 0
idx = ID_list[j][i] if Y_list[j][idx] * (alf * ft_list[j] + beta * fut_list[j]) < 0: errcount_list[j] += 1 misrate_list[j].append(errcount_list[j] / float(count_list[j])) return misrate_list, w_list, u # load data fname1 = 'tfidf_pu1' fname2 = 'tfidf_pu2' fname3 = 'tfidf_pu3' fname4 = 'tfidf_pua' sampleNum = -1 X1, Y1 = loadSparseData(fname1, sampleNum) X2, Y2 = loadSparseData(fname2, sampleNum) X3, Y3 = loadSparseData(fname3, sampleNum) X4, Y4 = loadSparseData(fname4, sampleNum) # preProcess data print 'preProcess X' X1 = mmPreProcess(X1) X2 = mmPreProcess(X2) X3 = mmPreProcess(X3) X4 = mmPreProcess(X4) # X1 = stdPreProcess(X1) # X2 = stdPreProcess(X2) # X3 = stdPreProcess(X3) # X4 = stdPreProcess(X4)
if i < len_list[j]: idx = ID_list[j][i] if Y_list[j][idx] * (alf * ft_list[j] + beta * fut_list[j]) < 0: errcount_list[j] +=1 misrate_list[j].append(errcount_list[j]/float(count_list[j])) return misrate_list, w_list, u # load data fname1 = 'tfidf_pu1' fname2 = 'tfidf_pu2' fname3 = 'tfidf_pu3' fname4 = 'tfidf_pua' sampleNum = -1 X1, Y1 = loadSparseData(fname1, sampleNum) X2, Y2 = loadSparseData(fname2, sampleNum) X3, Y3 = loadSparseData(fname3, sampleNum) X4, Y4 = loadSparseData(fname4, sampleNum) # preProcess data print 'preProcess X' X1 = mmPreProcess(X1) X2 = mmPreProcess(X2) X3 = mmPreProcess(X3) X4 = mmPreProcess(X4) # X1 = stdPreProcess(X1) # X2 = stdPreProcess(X2) # X3 = stdPreProcess(X3) # X4 = stdPreProcess(X4)