#%%
import pandas

file = r"C:\Users\davch\OneDrive - Microsoft\Shared with Team\Entity Ranking\Implicit Group\experiments\test data.tsv"

data = pandas.read_csv(file,sep='\t')

print(data.ndim)

#%%
columns = ["AdvancedPreferFeature_95",
"AdvancedPreferFeature_96",
"AdvancedPreferFeature_97",
"AdvancedPreferFeature_98",
"AdvancedPreferFeature_99",
"AdvancedPreferFeature_100",
"AdvancedPreferFeature_101",
"AdvancedPreferFeature_102",
"AdvancedPreferFeature_103",
"AdvancedPreferFeature_104",
"AdvancedPreferFeature_105",
"AdvancedPreferFeature_106",
"AdvancedPreferFeature_107",
"AdvancedPreferFeature_108",
"AdvancedPreferFeature_109",
"AdvancedPreferFeature_110",
"AdvancedPreferFeature_111",
"AdvancedPreferFeature_112",
"AdvancedPreferFeature_113",
"AdvancedPreferFeature_114",
"AdvancedPreferFeature_115"]

features = data.filter(items=columns).values
label = data.filter(items=["m:Rating"]).values
print(features.shape)
print(label.shape)

#%%
from sklearn.feature_selection import mutual_info_classif, mutual_info_regression
import numpy as np
mi = mutual_info_classif(features,np.ravel(label))
mi_reg = mutual_info_regression(features,np.ravel(label))
print("the classification mutual information ...")
print(mi)
print("="*100)
print("the regression mutual information ...")
print(mi_reg)
print("="*100)

#%%
import matplotlib.pyplot as plt

plt.figure(figsize=(40,60))
for i in range(21):
    plt.subplot(6,4,i+1)
    plt.scatter(features[:,i],label,edgecolors='black',s=10)
    plt.xlabel(columns[i], fontsize=14)
    plt.title("MI_classification={:.4f} MI_regression={:.4f}".format(mi[i],mi_reg[i]),fontsize=16)

plt.savefig(r"C:\Users\davch\OneDrive - Microsoft\Shared with Team\Entity Ranking\Implicit Group\experiments\analysis.png")