def prepareMusk2(path, name): print("Prepare Musk2:") fname = prepareLoading(name, path) # Create MIL problem from Musk2 data musk2_raw = np.array(pd.read_csv(fname, usecols=range(0,169), skip_blank_lines=True, header=None)) # Scale data by z-score normalization features = musk2_raw[:, 2:-1].astype(np.float64) features = scale(features) keys = musk2_raw[:, 0] labels = musk2_raw[:, -1] musk2 = milData('musk2') for i, row in enumerate(features): key = keys[i] x = features[i] z = labels[i] musk2.add_x(key, x, z, UPDATE=False ) musk2.save(path) print("Bags: ", musk2.N_B, "(+: {p}, -: {n})".format(p=np.sum(musk2.z==1), n=np.sum(musk2.z==0))) print("Instances: ", musk2.N_X, "(+: {p}, -: {n})".format(p=np.sum(musk2.y==1), n=np.sum(musk2.y==0))) print ("Features: ", musk2.N_D) print("\n") return musk2
def prepareFox(path, name): print("Prepare Fox:") fname = prepareLoading(name, path) # Create MIL problem from Fox data features = loadmat(fname)["Data"] features = scale(features) keys = loadmat(fname)['bags'] labels = loadmat(fname)['labels'] b = 0 fox = milData('fox') for i, row in enumerate(features): x = row key = keys[i][0] z = labels[b][0] fox.add_x(key, x, z, UPDATE=False) if i < len(features) - 1 and key != keys[ i + 1]: # will the next key belong to the next bag? b += 1 fox.save(path) print( "Bags: ", fox.N_B, "(+: {p}, -: {n})".format(p=np.sum(fox.z == 1), n=np.sum(fox.z == 0))) print( "Instances: ", fox.N_X, "(+: {p}, -: {n})".format(p=np.sum(fox.y == 1), n=np.sum(fox.y == 0))) print("Features: ", fox.N_D) print("\n") return fox