<jupyter_start><jupyter_text>Simulate Data  41 AD and 36 LMCI with 35 ROIs<jupyter_code>#* * (1) Some variables are described.
mu1 = 0.9 #Mean value of the first Gaussian distribution
sigma1 = 0.4 #Standard deviation value of the first Gaussian distribution
mu2 = 0.7 #Mean value of the second Gaussian distribution
sigma2 = 0.6 #Standard deviation value of the first Gaussian distribution
#Nf = 5 #number of selected features
Featurematrix,Subjects,Labels=simulate_data(mu1,sigma1,mu2,sigma2)
X=Featurematrix
y=Labels
y=y[:, 0]
n_samples, n_features = X.shape
y
X.shape
# Number of selected features (top k ranked features)
#top K selected features varying from 10 to 100 (with a step size of 10 features)
num_fea = [i for i in range(10,110,10)]
clf = svm.LinearSVC()    # linear SVM
correct=0
accuracy=[]<jupyter_output><empty_output><jupyter_text>Feature selection methods  Vizualize classification results<jupyter_code>#   X_train, X_test = X[train_index], X[test_index]
k=10
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
     #   y_train, y_test = y[train_index], y[test_index]
#if FS_method==reliefF:
idx,score=relief_FS(X_train,y_train)

selected_features_train = X_train[:, idx]
selected_features_test = X_test[:, idx]
    # train a classification model with the selected features on the training dataset
clf.fit(selected_features_train, y_train)  # predict the class labels of test data
y_predict = clf.predict(selected_features_test)
    # obtain the classification accuracy on the test data
acc = accuracy_score(y_test, y_predict)

print(confusion_matrix(y_test,y_predict))
print(classification_report(y_test,y_predict))
pca = PCA(n_components=2).fit(selected_features_train)
pca_2d = pca.transform(selected_features_train)
pca_2d[:,1]
from sklearn.decomposition import PCA

pca = PCA(n_components=2).fit(selected_features_train)
pca_2d = pca.transform(selected_features_train)
import pylab as pl
for i in range(0, pca_2d.shape[0]):
    if y_train[i] == -1:
        c1 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r',    marker='+')
    elif y_train[i] == 1:
        c2 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='b',    marker='o')

pl.legend([c1, c2], ['AD', 'MCI'])
pl.title('Linear SVM classifier without Feature selection')
pl.show()

pca = PCA(n_components=2).fit(selected_features_train)
pca_2d = pca.transform(selected_features_train)
import pylab as pl
for i in range(0, pca_2d.shape[0]):
    if y_train[i] == -1:
        c1 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r',    marker='+')
    elif y_train[i] == 1:
        c2 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='b',    marker='o')

pl.legend([c1, c2], ['AD', 'MCI'])
pl.title('Linear SVM classifier with Feature selection evaluated with 5 fold cv')
pl.show()<jupyter_output><empty_output><jupyter_text>____________________________________________________________________________________  Training<jupyter_code>from helpers.training import *
ranks,accs,weights=training(kf5,10,reliefF,X,y)
ranks
pool_FS=[reliefF,lap_score,ll_l21,ls_l21,UDFS,fisher_score,chi_square,gini_index,SPEC]#,BorutaPy]#,MCFS]#trace_ratio,<jupyter_output><empty_output><jupyter_text>Training  Using 9 FS methods and  3 Cross-validation (5-fold, 10-fold, LOO)<jupyter_code>from helpers.training import *
from helpers.fs_methods import *
dataframe_ranking_5fold,dataframe_accuracies_5fold,dataframe_weights_5fold=fs_training(kf5,X,y,num_fea)
dataframe_ranking_10fold,dataframe_accuracies_10fold,dataframe_weights_10fold=fs_training(kf10,X,y,num_fea)
dataframe_ranking_loo,dataframe_accuracies_loo,dataframe_weights_loo=fs_training(LOO,X,y,num_fea)<jupyter_output><empty_output><jupyter_text>Overlapping matrices<jupyter_code>from helpers.similarities import *
dataframe_ranking_5fold['overlapping']=dataframe_ranking_5fold.apply(
    lambda row:FS_to_FS_similarity(row),axis=1)
dataframe_ranking_10fold['overlapping']=dataframe_ranking_10fold.apply(
    lambda row:FS_to_FS_similarity(row),axis=1)
dataframe_ranking_loo['overlapping']=dataframe_ranking_loo.apply(
    lambda row:FS_to_FS_similarity(row),axis=1)
def check_symmetric(a, rtol=1e-05, atol=1e-08):
    return np.allclose(a, a.T, rtol=rtol, atol=atol)
check_symmetric(dataframe_ranking_5fold.overlapping[10])<jupyter_output><empty_output><jupyter_text>5-fold<jupyter_code>import matplotlib.pyplot as plt

plt.figure(figsize=(20,10))
plt.suptitle('Overlapping matrices', fontsize=16)

plt.subplot(2, 5, 1)
plt.imshow(dataframe_ranking_5fold.overlapping[10],cmap=plt.cm.prism_r)
plt.title('num_fea=10')
plt.subplot(2, 5, 2)
plt.imshow(dataframe_ranking_5fold.overlapping[20],cmap=plt.cm.prism_r)
plt.title('num_fea=20')
plt.subplot(2, 5, 3)
plt.imshow(dataframe_ranking_5fold.overlapping[30],cmap=plt.cm.prism_r)
plt.title('num_fea=30')
plt.subplot(2, 5, 4)
plt.imshow(dataframe_ranking_5fold.overlapping[40],cmap=plt.cm.prism_r)
plt.title('num_fea=40')
plt.subplot(2, 5, 5)
plt.imshow(dataframe_ranking_5fold.overlapping[50],cmap=plt.cm.prism_r)
plt.title('num_fea=50')
plt.subplot(2, 5, 6)
plt.imshow(dataframe_ranking_5fold.overlapping[60],cmap=plt.cm.prism_r)
plt.title('num_fea=60')
plt.subplot(2, 5, 7)
plt.imshow(dataframe_ranking_5fold.overlapping[70],cmap=plt.cm.prism_r)
plt.title('num_fea=70')
plt.subplot(2, 5, 8)
plt.imshow(dataframe_ranking_5fold.overlapping[80],cmap=plt.cm.prism_r)
plt.title('num_fea=80')
plt.subplot(2, 5, 9)
plt.imshow(dataframe_ranking_5fold.overlapping[90],cmap=plt.cm.prism_r)
plt.title('num_fea=90')
plt.subplot(2, 5, 10)
plt.imshow(dataframe_ranking_5fold.overlapping[100],cmap=plt.cm.prism_r)
plt.title('num_fea=100')<jupyter_output><empty_output><jupyter_text>10-fold<jupyter_code>plt.figure(figsize=(20,10))
plt.suptitle('Overlapping matrices', fontsize=16)
plt.subplot(2, 5, 1)
plt.imshow(dataframe_ranking_10fold.overlapping[10],cmap=plt.cm.prism_r)
plt.title('num_fea=10')
plt.subplot(2, 5, 2)
plt.imshow(dataframe_ranking_10fold.overlapping[20],cmap=plt.cm.prism_r)
plt.title('num_fea=20')
plt.subplot(2, 5, 3)
plt.imshow(dataframe_ranking_10fold.overlapping[30],cmap=plt.cm.prism_r)
plt.title('num_fea=30')
plt.subplot(2, 5, 4)
plt.imshow(dataframe_ranking_10fold.overlapping[40],cmap=plt.cm.prism_r)
plt.title('num_fea=40')
plt.subplot(2, 5, 5)
plt.imshow(dataframe_ranking_10fold.overlapping[50],cmap=plt.cm.prism_r)
plt.title('num_fea=50')
plt.subplot(2, 5, 6)
plt.imshow(dataframe_ranking_10fold.overlapping[60],cmap=plt.cm.prism_r)
plt.title('num_fea=60')
plt.subplot(2, 5, 7)
plt.imshow(dataframe_ranking_10fold.overlapping[70],cmap=plt.cm.prism_r)
plt.title('num_fea=70')
plt.subplot(2, 5, 8)
plt.imshow(dataframe_ranking_10fold.overlapping[80],cmap=plt.cm.prism_r)
plt.title('num_fea=80')
plt.subplot(2, 5, 9)
plt.imshow(dataframe_ranking_10fold.overlapping[90],cmap=plt.cm.prism_r)
plt.title('num_fea=90')
plt.subplot(2, 5, 10)
plt.imshow(dataframe_ranking_10fold.overlapping[100],cmap=plt.cm.prism_r)
plt.title('num_fea=100')<jupyter_output><empty_output><jupyter_text>LOO<jupyter_code>plt.figure(figsize=(20,10))
plt.suptitle('Overlapping matrices', fontsize=16)
plt.subplot(2, 5, 1)
plt.imshow(dataframe_ranking_loo.overlapping[10],cmap=plt.cm.prism_r)
plt.title('num_fea=10')
plt.subplot(2, 5, 2)
plt.imshow(dataframe_ranking_loo.overlapping[20],cmap=plt.cm.prism_r)
plt.title('num_fea=20')
plt.subplot(2, 5, 3)
plt.imshow(dataframe_ranking_loo.overlapping[30],cmap=plt.cm.prism_r)
plt.title('num_fea=30')
plt.subplot(2, 5, 4)
plt.imshow(dataframe_ranking_loo.overlapping[40],cmap=plt.cm.prism_r)
plt.title('num_fea=40')
plt.subplot(2, 5, 5)
plt.imshow(dataframe_ranking_loo.overlapping[50],cmap=plt.cm.prism_r)
plt.title('num_fea=50')
plt.subplot(2, 5, 6)
plt.imshow(dataframe_ranking_loo.overlapping[60],cmap=plt.cm.prism_r)
plt.title('num_fea=60')
plt.subplot(2, 5, 7)
plt.imshow(dataframe_ranking_loo.overlapping[70],cmap=plt.cm.prism_r)
plt.title('num_fea=70')
plt.subplot(2, 5, 8)
plt.imshow(dataframe_ranking_loo.overlapping[80],cmap=plt.cm.prism_r)
plt.title('num_fea=80')
plt.subplot(2, 5, 9)
plt.imshow(dataframe_ranking_loo.overlapping[90],cmap=plt.cm.prism_r)
plt.title('num_fea=90')
plt.subplot(2, 5, 10)
plt.imshow(dataframe_ranking_loo.overlapping[100],cmap=plt.cm.prism_r)
plt.title('num_fea=100')<jupyter_output><empty_output><jupyter_text>Average similarity matrix<jupyter_code>average_similarity_5fold=dataframe_ranking_5fold.overlapping.mean()
average_similarity_10fold=dataframe_ranking_10fold.overlapping.mean()
average_similarity_loo=dataframe_ranking_loo.overlapping.mean()
#sns.heatmap(dataframe_ranking_5fold.overlapping.mean())
plt.imshow(average_similarity_5fold,cmap=plt.cm.prism_r)
plt.title('Average similarity case 5 fold CV')
plt.imshow(average_similarity_10fold,cmap=plt.cm.prism_r)
plt.title('Average similarity case 10 fold CV')
plt.imshow(average_similarity_loo,cmap=plt.cm.prism_r)
plt.title('Average similarity case LOO CV')<jupyter_output><empty_output><jupyter_text>Accuracy similarity matrix<jupyter_code>df_5fold_acc=dataframe_accuracies_5fold.copy()
df_10fold_acc=dataframe_accuracies_10fold.copy()
df_loo_acc=dataframe_accuracies_loo.copy()
df_5fold_acc.loc['mean'] =df_5fold_acc.mean()
df_10fold_acc.loc['mean'] =df_10fold_acc.mean()
df_loo_acc.loc['mean'] =df_loo_acc.mean()
acc_sim_matrix_5fold=matrix_acc(list(df_5fold_acc.loc['mean']))
acc_sim_matrix_10fold=matrix_acc(list(df_10fold_acc.loc['mean']))
acc_sim_matrix_loo=matrix_acc(list(df_loo_acc.loc['mean']))
plt.imshow(acc_sim_matrix_5fold,cmap=plt.cm.prism_r)
plt.title('Average accuracy similarity matrix case 5-fold CV')
plt.imshow(acc_sim_matrix_10fold,cmap=plt.cm.prism_r)
plt.title('Average accuracy similarity matrix case 10-fold CV')
plt.imshow(acc_sim_matrix_loo,cmap=plt.cm.prism_r)
plt.title('Average accuracy similarity matrix case loo CV')<jupyter_output><empty_output><jupyter_text>Final similarity without stability<jupyter_code>Final_sim_5fold=np.multiply(average_similarity_5fold,acc_sim_matrix_5fold)
plt.imshow(Final_sim_5fold,cmap=plt.cm.prism_r)
plt.title('Final similarity matrix without stability: 5-fold cv')
Final_sim_10fold=np.multiply(average_similarity_10fold,acc_sim_matrix_10fold)
plt.imshow(Final_sim_10fold,cmap=plt.cm.prism_r)
plt.title('Final similarity matrix without stability: 10-fold cv')
Final_sim_loo=np.multiply(average_similarity_loo,acc_sim_matrix_loo)
plt.imshow(Final_sim_loo,cmap=plt.cm.prism_r)
plt.title('Final similarity matrix without stability: LOO cv')<jupyter_output><empty_output><jupyter_text>Binary overlapping for FS reliefF and k =10 (5-fold,10fold and LOO)<jupyter_code>from helpers.reproducibility import *
def binary_intersection(a,b,k):
    ''' A function that return the percentage of common elements to both a and b'''
    sum_=0
    for x in range(a.shape[0]):
        for y in range(a.shape[1]):
            sum_+=np.sum((a[x,y]==b[x,y]))
    #percentage=(sum_*100)/k
    percentage=(sum_*100)/b.size
    return(percentage)
def binary_matrice(FS_k,k):
    n=len(FS_k)
    m=np.ones((n,n))
    for i in range(n):
        for j in range(i+1,n):
            m[i,j]=binary_intersection(FS_k[i],FS_k[j],k)
            m[j,i]=m[i,j]
   # for i in range(n):
    #    m[i,i]=intersection(FS_k[i],FS_k[i])/100
    return(m)
FS_k=[dataframe_ranking_5fold.overlapping[10],dataframe_ranking_10fold.overlapping[10],
      dataframe_ranking_loo.overlapping[10]]
k=10
labels=['5fold','10fold','LOO']
dataframe=pd.DataFrame(binary_matrice(FS_k,k),columns=labels,index=labels)
#sns.heatmap(dataframe)
plt.imshow(dataframe)
plt.title('The overlap in % between top 10 features discovered using a pair of CV methods')
pool_FS<jupyter_output><empty_output><jupyter_text>Without stability  Identify the most reproducible feature selection method<jupyter_code># Centrality measure 
import networkx as nx
G_5fold=nx.from_numpy_matrix(Final_sim_5fold)
#centrality_5fold=nx.degree_centrality(G_5fold)<jupyter_output><empty_output><jupyter_text>centrality_5fold import networkx as nxnormalized_G=nx.from_numpy_matrix(Final_sim_5fold)<jupyter_code>G_10fold=nx.from_numpy_matrix(Final_sim_10fold)
#centrality_10fold=nx.degree_centrality(G_10fold)
G_loo=nx.from_numpy_matrix(Final_sim_loo)
#centrality_loo=nx.degree_centrality(G_loo)<jupyter_output><empty_output><jupyter_text>centrality_loo<jupyter_code>#### Calculate betweenness and closeness centrality<jupyter_output><empty_output><jupyter_text>bc_5fold=nx.betweenness_centrality(G_5fold)cc_5fold=nx.closeness_centrality(G_5fold) bc_10fold=nx.betweenness_centrality(G_10fold)cc_10fold=nx.closeness_centrality(G_10fold) bc_loo=nx.betweenness_centrality(G_loo)cc_loo=nx.closeness_centrality(G_loo) bc_5fold cc_5fold plt.hist(bc_5fold.values())plt.title('Betweeness centrality 5-fold') plt.hist(cc_5fold.values())plt.title('closeness centrality 5-fold') bc_10fold cc_10fold bc_loo cc_loo plt.hist(bc_10fold.values())plt.title('Betweeness centrality 10-fold') plt.hist(cc_10fold.values())plt.title('Closeness centrality 10-fold') plt.hist(bc_loo.values())plt.title('Betweeness centrality loo') plt.hist(cc_loo.values())plt.title('Closeness centrality loo') import networkx as nximport matplotlib.pyplot as pltG=nx.path_graph(4)print("Nodes of graph: ")print(G_5fold.nodes())print("Edges of graph: ")print(G_5fold.edges())nx.draw(G_5fold)plt.savefig("path_graph1.png")plt.show() import matplotlib.pyplot as pltimport networkx as nxG=G_looG=nx.from_numpy_matrix(final_sim_kf5)pos=nx.spring_layout(G)  positions for all nodes nodesnx.draw_networkx_nodes(G,pos,                       nodelist=[0,1,2,3,4,5,6,7,8],                       node_color='r',                       node_size=500,                   alpha=0.8)nx.draw_networkx_nodes(G,pos,                       nodelist=[4,5,6,7],                       node_color='b',                       node_size=500,                   alpha=0.8) edgesnx.draw_networkx_edges(G,pos,width=1.0,alpha=0.5)nx.draw_networkx_edges(G,pos,                       width=2,alpha=0.5,edge_color='b')nx.draw_networkx_edges(G,pos,                       edgelist=[(4,5),(5,6),(6,7),(7,4)],                       width=8,alpha=0.5,edge_color='b')reliefF,lap_score,ll_l21,UDFS,fisher_score,chi_square,gini_index some math labelslabels={}labels[0]=r'reliefF'labels[1]=r'lap_score'labels[2]=r'll_l21'labels[3]=r'ls_l21'labels[4]=r'UDFS'labels[5]=r'fisher_score'labels[6]=r'chi_square'labels[7]=r'gini_index'labels[8]=r'SPEC'nx.draw_networkx_labels(G,pos,labels,font_size=12)plt.axis('off')plt.rcParams["figure.figsize"] = (5,5)plt.savefig("5fold_graph.png")  save as pngplt.figure(figsize=(10,10))plt.title('RH: loo graph')plt.show()  display<jupyter_code># Stability construction<jupyter_output><empty_output><jupyter_text>from helpers.similarities import * def kuncheva_stability(featidx,d):    q,k = featidx.shape    q = size(featidx,1);    q=num_methods    r = np.zeros((q,q))    for n in range(1,q-1):        for m in range(n,q-1):            r[n,m] = len(np.intersect1d(featidx[n,0],featidx[n,1])) + len(np.intersect1d(featidx[n,0],featidx[n + 1,1])) + len(np.intersect1d(featidx[n,0],featidx[n-1,1]))    A = np.true_divide(np.subtract(r, (k**2/d)),(k-(k**2/d)))    S = 2*sum(sum(A))/(q*(q-1))    return(S)def get_ranking_matrix(a,k):    The columns are the respective rankings of pool_FS    a=dataframe_ranking_5fold.loc[10]    a=a.as_matrix(columns=None)    a=np.array(a)    b=np.zeros((k,len(pool_FS)))    for i in range(len(a)):        b[:,i]=a[i]    return(b)def normalize_stability(matrix):    n,m=matrix.shape    norm_mat = np.zeros((n,m))    for i in range(n):        for j in range(m):            norm_mat[i,j] = 100*(matrix[i,j] - np.min(matrix)) / (np.max(matrix) - np.min(matrix))    return(norm_mat)def get_stability(ranking_matrix):        stab_mat=np.zeros((len(pool_FS),len(pool_FS)))    for i in range(len(pool_FS)):        for j in range(len(pool_FS)):            if i!=j:                stab_mat[i,j] = kuncheva_stability(np.transpose(np.vstack((ranking_matrix[:,i],ranking_matrix[:,j]))),595)    stab_mat=np.abs(stab_mat)    stab_mat=normalize_stability(stab_mat)    return(stab_mat)def rowStability(row):    matrix=get_ranking_matrix(row,row.name)    return(get_stability(matrix)) pool_FS=[reliefF,lap_score,ll_l21,ls_l21,UDFS,fisher_score,chi_square,gini_index,SPEC] df_ranking_5fold=dataframe_ranking_5fold.copy() df_ranking_10fold=dataframe_ranking_10fold.copy() df_ranking_loo=dataframe_ranking_loo.copy() df_ranking_5fold.drop(['overlapping'],axis=1,inplace=True) df_ranking_10fold.drop(['overlapping'],axis=1,inplace=True) df_ranking_loo.drop(['overlapping'],axis=1,inplace=True) df_ranking_5fold.columns df_ranking_5fold['stability']=df_ranking_5fold.apply(rowStability,axis=1) df_ranking_10fold['stability']=df_ranking_10fold.apply(rowStability,axis=1) df_ranking_loo['stability']=df_ranking_loo.apply(rowStability,axis=1)<jupyter_code>#### Mean stability K<jupyter_output><empty_output><jupyter_text>average_5fold_stability=df_ranking_5fold.stability.mean()average_10fold_stability=df_ranking_10fold.stability.mean()average_loo_stability=df_ranking_loo.stability.mean()<jupyter_code>### Store similarities for later use on Hypergraph Learning framework<jupyter_output><empty_output><jupyter_text>import picklewith open('RH_metrics/similarities/average_stability_5fold','wb') as f: pickle.dump(average_5fold_stability, f)with open('RH_metrics/similarities/average_stability_10fold','wb') as f: pickle.dump(average_10fold_stability, f)with open('RH_metrics/similarities/average_stability_loo','wb') as f: pickle.dump(average_loo_stability, f)<jupyter_code>### Uncomment this to read similarities<jupyter_output><empty_output><jupyter_text>import pandas as pd average_5fold_stability=pd.read_pickle('RH_metrics/similarities/average_stability_5fold')average_10fold_stability=pd.read_pickle('RH_metrics/similarities/average_stability_10fold')average_loo_stability=pd.read_pickle('RH_metrics/similarities/average_stability_loo')<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams["figure.figsize"] = (10,10)
plt.hist(average_5fold_stability)
plt.title('Distribution of mean stability')
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
print(scaler.fit(average_5fold_stability))
normalized_stability=scaler.transform(average_5fold_stability)
plt.rcParams["figure.figsize"] = (10,10)
plt.hist(normalized_stability)
plt.title('Distribution of mean stability')
plt.imshow(average_5fold_stability,cmap=plt.cm.prism_r)
plt.title('RH: Average 5-fold stability')
plt.imshow(average_10fold_stability,cmap=plt.cm.prism_r)
plt.title('RH: Average 10-fold stability')
plt.imshow(average_loo_stability,cmap=plt.cm.prism_r)
plt.title('RH: Average loo stability')<jupyter_output><empty_output><jupyter_text>Similarity with stability<jupyter_code>acc_sim_matrix_5fold
Final_sim_5fold_stability=np.multiply(acc_sim_matrix_5fold,average_similarity_5fold,average_5fold_stability)
Final_sim_10fold_stability=np.multiply(acc_sim_matrix_10fold,average_similarity_10fold,average_10fold_stability)
Final_sim_loo_stability=np.multiply(acc_sim_matrix_loo,average_similarity_loo,average_loo_stability)
plt.imshow(Final_sim_5fold_stability,cmap=plt.cm.prism_r)
plt.title('RH: Final similarity matrice with stability 5fold')
plt.imshow(Final_sim_10fold_stability,cmap=plt.cm.prism_r)
plt.title('RH:Final similarity matrice with stability 10-fold')
plt.imshow(Final_sim_loo_stability,cmap=plt.cm.prism_r)
plt.title('RH:Final similarity matrice with stability loo')<jupyter_output><empty_output><jupyter_text>Centrality  with stability<jupyter_code>import networkx as nx
G_5fold_stability=nx.from_numpy_matrix(Final_sim_5fold_stability)
G_10fold_stability=nx.from_numpy_matrix(Final_sim_10fold_stability)
G_loo_stability=nx.from_numpy_matrix(Final_sim_loo_stability)
#centrality_5fold_stability=nx.degree_centrality(G_5fold_stability)
cc_5fold=nx.closeness_centrality(G_5fold_stability)
bc_5fold=nx.betweenness_centrality(G_5fold_stability)
cc_10fold=nx.closeness_centrality(G_10fold_stability)
bc_10fold=nx.betweenness_centrality(G_10fold_stability)
cc_loo=nx.closeness_centrality(G_loo_stability)
bc_loo=nx.betweenness_centrality(G_loo_stability)
cc_5fold
bc_5fold
cc_10fold
plt.hist(bc_5fold.values())
plt.title('Betweeness centrality 5-fold')
plt.hist(cc_5fold.values())
plt.title('Closeness centrality 5-fold')
cc_5fold
bc_10fold
cc_10fold
bc_loo
cc_loo<jupyter_output><empty_output><jupyter_text>Draw the graphs after stability<jupyter_code>import matplotlib.pyplot as plt

import networkx as nx
G=G_loo_stability
#G=nx.from_numpy_matrix(final_sim_kf5)
pos=nx.spring_layout(G) # positions for all nodes

# nodes
nx.draw_networkx_nodes(G,pos,
                       nodelist=[0,1,2,3,4,5,6,7,8],
                       node_color='r',
                       node_size=500,
                   alpha=0.8)
#nx.draw_networkx_nodes(G,pos,
#                       nodelist=[4,5,6,7],
#                       node_color='b',
#                       node_size=500,
#                   alpha=0.8)

# edges
nx.draw_networkx_edges(G,pos,width=1.0,alpha=0.5)
nx.draw_networkx_edges(G,pos,
                       width=2,alpha=0.5,edge_color='b')
#nx.draw_networkx_edges(G,pos,
#                       edgelist=[(4,5),(5,6),(6,7),(7,4)],
#                       width=8,alpha=0.5,edge_color='b')

#reliefF,lap_score,ll_l21,UDFS,fisher_score,chi_square,gini_index
# some math labels
labels={}
labels[0]=r'reliefF'
labels[1]=r'lap_score'
labels[2]=r'll_l21'
labels[3]=r'ls_l21'
labels[4]=r'UDFS'
labels[5]=r'fisher_score'
labels[6]=r'chi_square'
labels[7]=r'gini_index'
labels[8]=r'SPEC'
nx.draw_networkx_labels(G,pos,labels,font_size=12)

#plt.axis('off')

plt.rcParams["figure.figsize"] = (5,5)
#plt.savefig("5foldstability_graph.png") # save as png
plt.title('RH: loo graph with stability')
#plt.figure(figsize=(10,10))
plt.show() # display<jupyter_output><empty_output><jupyter_text>Reproducibility<jupyter_code>def intersection(a,b):
    ''' A function that return the percentage of common elements to both a and b'''
    sum_=0
    for x in range(a.shape[0]):
       # for y in range(a.shape[1]):
        sum_+=np.sum((a[x]==b[x]))
    #percentage=(sum_*100)/a.size
    percentage=(sum_)/a.size
    return(percentage)
def FS_to_FS_similarity(FS_k,k):
    n=len(FS_k)
    m=np.ones((n,n))
    for i in range(n):
        for j in range(i+1,n):
            m[i,j]=intersection(FS_k[i],FS_k[j])/k
            m[j,i]=m[i,j]
    for i in range(n):
        m[i,i]=intersection(FS_k[i],FS_k[i])/k#/100
    return(m)
def Nicholas_Reproducibility(k):
    
    top_k_ls_l21=[dataframe_ranking_5fold.ls_l21.loc[k],dataframe_ranking_10fold.ls_l21.loc[k],dataframe_ranking_loo.ls_l21.loc[k]]
    #top_k_reliefF=[df_ranking_5fold.reliefF.loc[k],df_ranking_10fold.reliefF.loc[k],df_ranking_loo.reliefF.loc[k]]
    #top_k_lap=[df_ranking_5fold.lap_score.loc[k],df_ranking_10fold.lap_score.loc[k],df_ranking_loo.lap_score.loc[k]]
    #top_k_ll=[df_ranking_5fold.ll_l21.loc[k],df_ranking_10fold.ll_l21.loc[k],df_ranking_loo.ll_l21.loc[k]]
    mat_ls_l21=FS_to_FS_similarity(top_k_ls_l21,k)
    #mat_reliefF=FS_to_FS_similarity(top_k_reliefF,k)
    #mat_lap=FS_to_FS_similarity(top_k_lap,k)
    #mat_ll=FS_to_FS_similarity(top_k_ll,k)
    #avg_mat= (mat_reliefF+mat_lap+mat_ll)/3
    labels=['5fold','10fold','LOO']
    dataframe_ls_l21=pd.DataFrame(mat_ls_l21,columns=labels,index=labels)
    #dataframe_lap=pd.DataFrame(mat_lap,columns=labels,index=labels)
    #dataframe_ll=pd.DataFrame(mat_ll,columns=labels,index=labels)
    #dataframe_avg=pd.DataFrame(avg_mat,columns=labels,index=labels)
    #return(dataframe_reliefF,dataframe_lap,dataframe_ll,dataframe_avg)
    return(dataframe_ls_l21)
df_ls_l21_reproducibility=Nicholas_Reproducibility(k)
Average_Nicholas_reproducibility=(np.average(np.triu(df_ls_l21_reproducibility.values,k=1)))*(10**3)
Average_Nicholas_reproducibility<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup