python/methylnet/model_interpretability.py
def shapley_jaccard(shapley_data,class_names, output_dir, overall, include_individuals, cooccurrence, optimize_n_cpgs):
    """Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes/groupings of individuals."""
    os.makedirs(output_dir,exist_ok=True)
    shapley_data=ShapleyData.from_pickle(shapley_data)
    shapley_data_explorer=ShapleyDataExplorer(shapley_data)
    outfilename=join(output_dir,'{}_jaccard.csv'.format('_'.join(class_names)))
    shapley_data_explorer.jaccard_similarity_top_cpgs(class_names,include_individuals,overall, cooccurrence).to_csv(outfilename)
    if optimize_n_cpgs:
        from skopt import gp_minimize
        shapley_data_explorer2 = ShapleyDataExplorer(shapley_data)
        def f(x):
            shapley_data_explorer2.shapley_data = shapley_data_explorer.limit_number_top_cpgs(n_top_cpgs=x[0])
            jaccard_matrix = shapley_data_explorer2.jaccard_similarity_top_cpgs(class_names,include_individuals,overall, cooccurrence).values
            jaccard_mean=jaccard_matrix.mean()
            print(x[0],jaccard_mean)
            return -jaccard_mean
        results=gp_minimize(f,[(100,shapley_data_explorer.shapley_data.top_cpgs['overall'].shape[0])],n_calls=25,n_jobs=8)
        print("{} number CpGs produces most similar jaccard similarity matrix.".format(results.x))
        print(dict(zip(results.x_iters.flatten().tolist(), (results.func_vals*-1).tolist())))
Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes/groupings of individuals.
Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes/groupings of individuals.
Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes / groupings of individuals .
def shapley_jaccard(shapley_data,class_names, output_dir, overall, include_individuals, cooccurrence, optimize_n_cpgs):
    os.makedirs(output_dir,exist_ok=True)
    shapley_data=ShapleyData.from_pickle(shapley_data)
    shapley_data_explorer=ShapleyDataExplorer(shapley_data)
    outfilename=join(output_dir,'{}_jaccard.csv'.format('_'.join(class_names)))
    shapley_data_explorer.jaccard_similarity_top_cpgs(class_names,include_individuals,overall, cooccurrence).to_csv(outfilename)
    if optimize_n_cpgs:
        from skopt import gp_minimize
        shapley_data_explorer2 = ShapleyDataExplorer(shapley_data)
        def f(x):
            shapley_data_explorer2.shapley_data = shapley_data_explorer.limit_number_top_cpgs(n_top_cpgs=x[0])
            jaccard_matrix = shapley_data_explorer2.jaccard_similarity_top_cpgs(class_names,include_individuals,overall, cooccurrence).values
            jaccard_mean=jaccard_matrix.mean()
            print(x[0],jaccard_mean)
            return -jaccard_mean
        results=gp_minimize(f,[(100,shapley_data_explorer.shapley_data.top_cpgs['overall'].shape[0])],n_calls=25,n_jobs=8)
        print("{} number CpGs produces most similar jaccard similarity matrix.".format(results.x))
        print(dict(zip(results.x_iters.flatten().tolist(), (results.func_vals*-1).tolist())))
def shapley_jaccard ( shapley_data , class_names , output_dir , overall , include_individuals , cooccurrence , optimize_n_cpgs ) : os . makedirs ( output_dir , exist_ok = True ) shapley_data = ShapleyData . from_pickle ( shapley_data ) shapley_data_explorer = ShapleyDataExplorer ( shapley_data ) outfilename = join ( output_dir , '{}_jaccard.csv' . format ( '_' . join ( class_names ) ) ) shapley_data_explorer . jaccard_similarity_top_cpgs ( class_names , include_individuals , overall , cooccurrence ) . to_csv ( outfilename ) if optimize_n_cpgs : from skopt import gp_minimize shapley_data_explorer2 = ShapleyDataExplorer ( shapley_data ) def f ( x ) : shapley_data_explorer2 . shapley_data = shapley_data_explorer . limit_number_top_cpgs ( n_top_cpgs = x [ 0 ] ) jaccard_matrix = shapley_data_explorer2 . jaccard_similarity_top_cpgs ( class_names , include_individuals , overall , cooccurrence ) . values jaccard_mean = jaccard_matrix . mean ( ) print ( x [ 0 ] , jaccard_mean ) return - jaccard_mean results = gp_minimize ( f , [ ( 100 , shapley_data_explorer . shapley_data . top_cpgs [ 'overall' ] . shape [ 0 ] ) ] , n_calls = 25 , n_jobs = 8 ) print ( "{} number CpGs produces most similar jaccard similarity matrix." . format ( results . x ) ) print ( dict ( zip ( results . x_iters . flatten ( ) . tolist ( ) , ( results . func_vals * - 1 ) . tolist ( ) ) ) )
Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes/groupings of individuals.
Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes / groupings of individuals .
"""Plot Shapley Jaccard Similarity Matrix to demonstrate sharing of Top CpGs between classes/groupings of individuals."""
shapley_data
class_names
output_dir
overall
include_individuals
cooccurrence
optimize_n_cpgs