<jupyter_start><jupyter_text>Plotting Results<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import time
import pickle

RESULTPATH = '../results/'
DATAPATH = '../datasets/'
train = pd.read_csv(DATAPATH + 'train.csv')
test = pd.read_csv(DATAPATH + 'test.csv')
# train_metadata = pd.read_csv(DATAPATH + 'train_metadata.csv', encoding="latin-1")

train.columns = ['movie_id', 'customer_id', 'rating', 'date']
test.columns  = ['movie_id', 'customer_id', 'rating', 'date']

df = train.pivot_table(index='customer_id', \
                           columns='movie_id', values='rating', aggfunc=np.mean).fillna(0)
A = df.to_numpy().copy()
train
test
test_df = test.to_numpy().copy()
print(test_df.shape)
test_df
# df_df = pd. DataFrame(data=test_df,columns=['movie_id', 'customer_id', 'rating', 'date'])
# df_df
for tst in range(test_df.shape[0]):
    mvid  = test_df[tst,0]
    cstid = test_df[tst,1]
    test_df[tst,3] = pred_ratings[cstid, mvid]
    
qry=test[(test['movie_id']==11279) & (test['customer_id']==5858)]
qry['rating']=1
qry
def set_fonts():
    from matplotlib.font_manager import FontProperties
    font = FontProperties()
    font.set_family('serif')
    font.set_name('Calibri')
    return font

def plot_scores(tr, ts, method, tst_prc):
    font=set_fonts();
  
    fig, ax = plt.subplots(figsize=(8,8))
    plt.tight_layout()
    ax.plot(np.mean(tr,axis=0), label='Train', linewidth=4)
    ax.plot(np.mean(ts,axis=0), label='Test', linewidth=4)

    plt.tight_layout()
    plt.xlabel('Different k',  fontproperties=font, fontsize=22, fontweight='bold')
    plt.ylabel(method, fontproperties=font, fontsize=22, fontweight='bold')#, labelpad=16,)
    plt.title('Cross validation tuning using %s percent test data - Average over 100 epochs' %(tst_prc), fontproperties=font, fontweight='bold', fontsize=16)

    plt.legend(fontsize=11)
    plt.tight_layout()
    
def plot_eigengaps(eg, title):
    font=set_fonts();
  
    fig, ax = plt.subplots(figsize=(5,5))
    plt.tight_layout()    
    plt.scatter(x=np.arange(eg.shape[0]), y=eg) 

    plt.tight_layout()
    plt.ylabel('Eigengaps', fontproperties=font, fontsize=22, fontweight='bold')#, labelpad=16,)
    plt.title(title, fontproperties=font, fontweight='bold', fontsize=16)
    
    plt.legend(fontsize=11)
    plt.tight_layout()
# Save labels
f_tr = 'mc_RMSE_tr_mean_col_cosine_similarity_0.1_epch95.npy'
f_ts = 'mc_RMSE_ts_mean_col_cosine_similarity_0.1_epch95.npy'

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr1=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts1=pickle.load(f)
    
##############
f_tr = 'mc_RMSE_tr_mean_col_cosine_similarity_0.25_epch95.npy'
f_ts = 'mc_RMSE_ts_mean_col_cosine_similarity_0.25_epch95.npy'

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr2=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts2=pickle.load(f)

##############
f_tr = 'mc_cnt_corr_tr_mean_col_cosine_similarity_0.1_epch95.npy'
f_ts = 'mc_cnt_corr_ts_mean_col_cosine_similarity_0.1_epch95.npy'

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr3=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts3=pickle.load(f)
    
##############
f_tr = 'mc_cnt_corr_tr_mean_col_cosine_similarity_0.25_epch95.npy'
f_ts = 'mc_cnt_corr_ts_mean_col_cosine_similarity_0.25_epch95.npy'

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr4=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts4=pickle.load(f)
    
# kk=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40]
plot_scores(tr1, ts1, 'RMSE', '10')
plot_scores(tr2, ts2, 'RMSE', '25')
# plot_scores(tr3, ts3, 'Count Correct Pred.', '10')
# plot_scores(tr4, ts4, 'Count Correct Pred.', '25')
# Save labels
n_k = [3, 4, 5, 10]
RESULTPATH = '../results/mc_new/'
n_epochs=95
f_tr = 'mc_RMSE_tr_mean_col_cosine_similarity_0.1_epch%s.npy' %(n_epochs)
f_ts = 'mc_RMSE_ts_mean_col_cosine_similarity_0.1_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr1=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts1=pickle.load(f)
    
# ##############
f_tr = 'mc_RMSE_tr_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'mc_RMSE_ts_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr2=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts2=pickle.load(f)

##############
f_tr = 'mc_cnt_corr_tr_mean_col_cosine_similarity_0.1_epch%s.npy' %(n_epochs)
f_ts = 'mc_cnt_corr_ts_mean_col_cosine_similarity_0.1_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr3=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts3=pickle.load(f)
    
##############
f_tr = 'mc_cnt_corr_tr_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'mc_cnt_corr_ts_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr4=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts4=pickle.load(f)
    
# kk=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40]
print(tr1.shape)
plot_scores(tr1, ts1, 'RMSE', '10')
plot_scores(tr2, ts2, 'RMSE', '25')
# plot_scores(tr3, ts3, 'Count Correct Pred.', '10')
# plot_scores(tr3, ts3, 'Count Correct Pred.', '25')
# Save labels
from sklearn.cluster import KMeans, MiniBatchKMeans, SpectralClustering

# n_k = [3, 4, 5, 10]
RESULTPATH = '../results/results/'
n_epochs=5
f_tr = 'sc_MSE_tr_U_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'sc_MSE_ts_U_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr1=pickle.load(f)
    tr1=tr1[:n_epochs]
# plt.plot(tr1)
# plt.plot(ts1)
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts1=pickle.load(f)
    ts1=ts1[:n_epochs]
    
# # ##############
f_tr = 'sc_RMSE_tr_U_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'sc_RMSE_ts_U_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr2=pickle.load(f)
    tr2=tr2[:n_epochs]
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts2=pickle.load(f)
    ts2=ts2[:n_epochs]

# ##############
f_tr = 'sc_cnt_corr_tr_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'sc_cnt_corr_ts_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr3=pickle.load(f)
    tr3=tr3[:n_epochs]
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts3=pickle.load(f)
    ts3=ts3[:n_epochs]
print(tr3)
print(ts3)
# plt.scatter(x=np.arange(tr3.shape[0]),y=tr3)
# plt.scatter(x=np.arange(ts3.shape[0]),y=ts3)
# ##############
f_tr = 'sc_prc_corr_tr_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)
f_ts = 'sc_prc_corr_ts_mean_col_cosine_similarity_0.25_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f_tr
with open(fn_str, 'rb') as f:
    tr4=pickle.load(f)
    
fn_str = RESULTPATH + f_ts
with open(fn_str, 'rb') as f:
    ts4=pickle.load(f)  
# ##############
n_epochs=5

f1 = 'sc_eigengap_mean_col_cosine_similarity_0.25_k5_epch%s.npy' %(n_epochs)
f2 = 'sc_eigengap_mean_col_cosine_similarity_0.25_k50_epch%s.npy' %(n_epochs)
f3 = 'sc_eigengap_mean_col_cosine_similarity_0.25_k100_epch%s.npy' %(n_epochs)

fn_str = RESULTPATH + f1
with open(fn_str, 'rb') as f:
    eg1=pickle.load(f)
    
fn_str = RESULTPATH + f2
with open(fn_str, 'rb') as f:
    eg2=pickle.load(f)

fn_str = RESULTPATH + f3
with open(fn_str, 'rb') as f:
    eg3=pickle.load(f)
eg=eg1[0:]
title = 'K = 5'
plot_eigengaps(eg, title)

eg=eg2[0:]
title = 'K = 50'
plot_eigengaps(eg, title)

eg=eg3[0:]
title = 'K = 100'
plot_eigengaps(eg, title)
# plot_scores(tr3, ts3, 'Count Correct Pred.', '10')
plot_scores(tr4, ts4, 'MSE', '25')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16608738828202582, 'fraction_numerical': 0.03736345580933466, 'mean_word_length': 4.999255398361877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '117599', 'license': 'Apache-2.0', 'n_tokens_mistral': 3913, 'n_tokens_neox': 3740, 'n_words': 609, 'path': 'jupyters/generating_final_results_plots.ipynb', 'repo_name': 'MaryZolfaghar/NetflixRecommendationSystem', 'size': '8056'}