コード例 #1
0
ファイル: multi_label.py プロジェクト: jdnc/ml-project
def main():
    feature_dict, col_names = pp.set_targets('data/features.txt', threshold=-1)
    # consider only the terms of interest
    with open('data/terms.json', 'rb') as f:
       	terms = json.load(f)
    for key in list(feature_dict):
	feature_dict[key] = [x for x in terms if feature_dict[key][x] > THRESH]
	if not feature_dict[key]:
	    del(feature_dict[key])
    # filter coordinates based on voxels
    coord_dict = ex.filter_studies_active_voxels('data/docdict.txt', 'data/MNI152_T1_2mm_brain.nii.gz',
                                                threshold=500, radius=6)
    # ensure that the keys are ints
    for key in list(coord_dict):
        if not isinstance(key, int):
            coord_dict[int(key)] = coord_dict[key]
            del(coord_dict[key])
    # find intersecting dicts
    coord_dict, feature_dict = ex.get_intersecting_dicts(coord_dict, feature_dict)
    # get the respective vectors
    X, y = pp.get_features_targets(coord_dict, feature_dict, labels=terms, mask='data/MNI152_T1_2mm_brain.nii.gz')
    score_per_class, score_per_label = classify(X, y)
    with open('class_scores.json', 'wb') as f:
        json.dump(score_per_class, f)
    with open('label_scores.json', 'wb') as f:
        json.dump(score_per_label, f)
    return
コード例 #2
0
def get_X_y(coordinate_file, feature_file, filter=True):
    if filter:
        coordinate_dict = ex.filter_studies_active_voxels(coordinate_file)
    else:
    	with open(coordinate_file) as f:
    		coordinate_dict = json.load(f)
    target_dict = ex.filter_studies_terms(feature_file, set_unique_label=True)
    coordinate_dict, target_dict = ex.get_intersecting_dicts(coordinate_dict,
                                                          target_dict)
    X, y = pp.get_features_targets(coordinate_dict, target_dict)
    return X, y
コード例 #3
0
ファイル: single_label.py プロジェクト: jdnc/ml-project
def main():
    with open('data/docdict.txt') as f:
    	coordinates = json.load(f)
    study_dict = ex.filter_studies_active_voxels(coordinates, 'data/MNI152_T1_2mm_brain.nii.gz', radius=6, threshold=500)
    # ensure that study dict has int as keys
    for key in list(study_dict):
        study_dict[int(key)] = study_dict[key]
        if not isinstance(key, int):
            del(study_dict[key])
    with open('data/terms.json', 'rb') as f:
        terms = json.load(f)
    feature_dict = ex.filter_studies_terms('data/features.txt', terms=terms, set_unique_label=True)
    for i in range(len(terms)):
        for j in range(i+1, len(terms)):
            sub_dict = {}
            for key in feature_dict:
                if feature_dict[key] in [terms[i], terms[j]]:
                    sub_dict[key] = feature_dict[key]
            study, feat  = ex.get_intersecting_dicts(study_dict, sub_dict)
            x, y = pp.get_features_targets(study, feat, mask='data/MNI152_T1_2mm_brain.nii.gz')
            cf = classify(x, y)
            save_name = terms[i] + '_vs_' + terms[j] + '.npy'
            with open(save_name, 'wb') as f:
                np.save(f, cf)