{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport datetime\nfrom tqdm import tqdm\nimport gc","metadata":{"_uuid":"f9c06103-190d-4d6b-bcb5-68754cc0f690","_cell_guid":"1c71c75b-3d6e-4899-91ad-718e2e365706","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:54:36.725052Z","iopub.execute_input":"2023-07-25T21:54:36.725468Z","iopub.status.idle":"2023-07-25T21:54:36.761073Z","shell.execute_reply.started":"2023-07-25T21:54:36.725433Z","shell.execute_reply":"2023-07-25T21:54:36.760012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv', dtype={\"article_id\": str,'postal_code':str})\nprint(customer_df.shape)\ncustomer_df.head()\n\nlocation_customers = customer_df['postal_code'].value_counts()[1:201].index\ncustomer_df = customer_df.loc[customer_df['postal_code'].isin(location_customers)]\n\ndf = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\", dtype={\"article_id\": str})\nprint(df.shape)\n\ndf[\"t_dat\"] = pd.to_datetime(df[\"t_dat\"])\nactive_articles = df.groupby(\"article_id\")[\"t_dat\"].max().reset_index()\nactive_articles = active_articles[active_articles[\"t_dat\"] >= \"2019-09-01\"].reset_index()\nprint(active_articles.shape)\ndf = df[df[\"article_id\"].isin(active_articles[\"article_id\"])].reset_index(drop=True)\ndf[\"week\"] = (df[\"t_dat\"].max() - df[\"t_dat\"]).dt.days // 7\nprint(df[\"week\"].value_counts())\n\narticle_df = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv\", dtype={\"article_id\": str})\ntest = article_df[article_df.product_type_name.isin(['Trousers','T-shirt','Shirt','Socks'])]\ndf = df[df['article_id'].isin(test.article_id)]\n\ndf = df[df['customer_id'].isin(customer_df.customer_id)]\ncustomer_df = customer_df[customer_df['customer_id'].isin(df.customer_id)]\ndf['postal_code'] = df['customer_id'].map(customer_df.set_index('customer_id')['postal_code'])\ndf.reset_index(inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-25T21:54:36.762955Z","iopub.execute_input":"2023-07-25T21:54:36.763261Z","iopub.status.idle":"2023-07-25T21:56:38.839509Z","shell.execute_reply.started":"2023-07-25T21:54:36.763236Z","shell.execute_reply":"2023-07-25T21:56:38.838205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Split data","metadata":{"_uuid":"21be1e0e-2de0-4f67-a389-5e1bae48aca4","_cell_guid":"deec049e-a155-4e19-86e2-0099c6eaaef3","trusted":true}},{"cell_type":"code","source":"df.drop(['index','t_dat', 'price','sales_channel_id','postal_code'], inplace=True, axis=1)\ndf['bought'] = 1\ndf.reset_index(inplace=True)","metadata":{"_uuid":"8ee2d296-cccd-4601-aa7a-d518ccf10297","_cell_guid":"cb0e47e5-fb58-4cf9-a1f0-b63869dd3075","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:38.842273Z","iopub.execute_input":"2023-07-25T21:56:38.843165Z","iopub.status.idle":"2023-07-25T21:56:38.858410Z","shell.execute_reply.started":"2023-07-25T21:56:38.843122Z","shell.execute_reply":"2023-07-25T21:56:38.857489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_dataset(df, week):\n    hist_df = df[df[\"week\"] > week]\n    val_df = df[df[\"week\"] <= week]\n    \n    return hist_df,val_df\n\ntrain_df,val_df = create_dataset(df,50)\ntrain_df.shape, val_df.shape","metadata":{"_uuid":"169fb71f-c094-4cf0-856e-f3f24356414e","_cell_guid":"d01a2e09-db6b-40d2-87b0-fe035676c296","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:38.861393Z","iopub.execute_input":"2023-07-25T21:56:38.862755Z","iopub.status.idle":"2023-07-25T21:56:38.887070Z","shell.execute_reply.started":"2023-07-25T21:56:38.862724Z","shell.execute_reply":"2023-07-25T21:56:38.886007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = train_df.groupby(['customer_id','article_id'])['bought'].count().reset_index()\nval_df = val_df.groupby(['customer_id','article_id'])['bought'].count().reset_index()","metadata":{"_uuid":"f66e2f7e-186f-47a2-9f9e-b0cb2df9205d","_cell_guid":"2a8d28fe-1223-4d54-ae53-9e8993ff1c9f","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:38.888527Z","iopub.execute_input":"2023-07-25T21:56:38.889091Z","iopub.status.idle":"2023-07-25T21:56:38.995967Z","shell.execute_reply.started":"2023-07-25T21:56:38.889060Z","shell.execute_reply":"2023-07-25T21:56:38.994857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#only consider those customers and items existing before.\nfrequent_users = train_df.customer_id.values\nval_df = val_df[val_df['customer_id'].isin(frequent_users)]\nfrequent_items = train_df.article_id.values\nval_df = val_df[val_df['article_id'].isin(frequent_items)]","metadata":{"_uuid":"0bd3b4ed-2f2f-4d44-9528-c777a03fec71","_cell_guid":"7af6c5ed-8f84-4891-8692-44c87e8be8cf","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:38.997446Z","iopub.execute_input":"2023-07-25T21:56:38.997900Z","iopub.status.idle":"2023-07-25T21:56:39.024243Z","shell.execute_reply.started":"2023-07-25T21:56:38.997862Z","shell.execute_reply":"2023-07-25T21:56:39.023038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions = pd.concat([train_df, val_df])\nprint(\"The number of customer: \",transactions['customer_id'].nunique())\nprint(\"The number of article: \",transactions['article_id'].nunique())","metadata":{"_uuid":"ce3afafa-bb9c-41d5-81bf-a03ddd7a74a0","_cell_guid":"2ddb10d9-cd8e-410b-9d43-191f6d1c5f07","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:39.025973Z","iopub.execute_input":"2023-07-25T21:56:39.026716Z","iopub.status.idle":"2023-07-25T21:56:39.060819Z","shell.execute_reply.started":"2023-07-25T21:56:39.026671Z","shell.execute_reply":"2023-07-25T21:56:39.059568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Due to the big amount of items, we can not consider the whole matrix in order to train. Therefore, we need to generate some negative samples: transactions that have never occured.","metadata":{"_uuid":"69474c4f-7971-44a3-8298-7366b38ce8ce","_cell_guid":"22090196-acca-4e13-9a82-6a1d757725c0","trusted":true}},{"cell_type":"code","source":"print(train_df.shape)\nprint(val_df.shape)","metadata":{"_uuid":"0fe31f2d-ea83-4bfd-8c26-16b80a8340e8","_cell_guid":"ba455bcc-2b7c-4b1b-b3cc-13e4b8f6505b","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T21:56:39.062238Z","iopub.execute_input":"2023-07-25T21:56:39.062708Z","iopub.status.idle":"2023-07-25T21:56:39.068432Z","shell.execute_reply.started":"2023-07-25T21:56:39.062667Z","shell.execute_reply":"2023-07-25T21:56:39.067354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Labelencoder","metadata":{}},{"cell_type":"code","source":"transactions = pd.concat([train_df, val_df])\ncustomers = np.unique(transactions.customer_id.values)#6588\narticles = np.unique(transactions.article_id.values)#5102\ncustomer_id2index = {c: i for i, c in enumerate(customers)}\narticle_id2index = {a: i for i, a in enumerate(articles)}","metadata":{"execution":{"iopub.status.busy":"2023-07-25T21:56:39.072457Z","iopub.execute_input":"2023-07-25T21:56:39.072841Z","iopub.status.idle":"2023-07-25T21:56:39.214263Z","shell.execute_reply.started":"2023-07-25T21:56:39.072811Z","shell.execute_reply":"2023-07-25T21:56:39.213135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.customer_id = train_df.customer_id.map(customer_id2index)\ntrain_df.article_id = train_df.article_id.map(article_id2index)\n\nval_df.customer_id = val_df.customer_id.map(customer_id2index)\nval_df.article_id = val_df.article_id.map(article_id2index)","metadata":{"execution":{"iopub.status.busy":"2023-07-25T21:56:39.215540Z","iopub.execute_input":"2023-07-25T21:56:39.215888Z","iopub.status.idle":"2023-07-25T21:56:39.264298Z","shell.execute_reply.started":"2023-07-25T21:56:39.215858Z","shell.execute_reply":"2023-07-25T21:56:39.263500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Network","metadata":{}},{"cell_type":"code","source":"import networkx as nx\nfrom networkx.generators.classic import empty_graph\nfrom networkx.utils import discrete_sequence, py_random_state, weighted_choice\nimport numbers\nfrom collections import Counter\n\ndef random_k_out_graph(n, k, alpha, self_loops=False, seed=None):\n    if alpha < 0:\n        raise ValueError(\"alpha must be positive\")\n    G = nx.empty_graph(n, create_using=nx.MultiDiGraph)\n    weights = Counter({v: alpha for v in G})\n    for i in range(k * n):\n        u = np.random.choice([v for v, d in G.out_degree() if d < k])\n        # If self-loops are not allowed, make the source node `u` have\n        # weight zero.\n        if not self_loops:\n            adjustment = Counter({u: weights[u]})\n        else:\n            adjustment = Counter()\n        v = weighted_choice(weights - adjustment, seed=seed)\n        G.add_edge(u, v)\n        weights[v] += 1\n    return G\n\n\n#2\npairs = []\nGraph = random_k_out_graph(6588,2,50)\nfor u,v in Graph.edges():\n    pairs.append([u,v])","metadata":{"execution":{"iopub.status.busy":"2023-07-25T21:56:39.265409Z","iopub.execute_input":"2023-07-25T21:56:39.266004Z","iopub.status.idle":"2023-07-25T22:00:04.847668Z","shell.execute_reply.started":"2023-07-25T21:56:39.265974Z","shell.execute_reply":"2023-07-25T22:00:04.845379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = 6588\nadjacency_matrix = np.zeros((m,m))\n# for u,v in Graph.edges():\nfor u,v in pairs:\n    adjacency_matrix[u][v] = 1\n#first order\nimport copy\n#due to different transactions generated by the same customer.\ncommunication_cost_each_customer = np.ones((m,1))\nAdjacency_List = {}\ncommunication_cost = 0\nfor i in tqdm(range(m)):\n    Adjacency_List[i] = set()\n    for j in range(m):\n        if adjacency_matrix[i][j] == 1:\n            Adjacency_List[i].update(set([j]))\n    communication_cost_each_customer[i] = len(Adjacency_List[i])\n    communication_cost += len(Adjacency_List[i])\nprint('communication cost at first order if going through all customers once is: ', communication_cost)\nAdjacency_List_pre = copy.deepcopy(Adjacency_List)\n\ndef neighbors_range(Adjacency_List):\n    lower = m\n    upper = 0\n    for i in range(m):\n        lower = min(lower,len(Adjacency_List[i]))\n        upper = max(upper,len(Adjacency_List[i]))\n    return lower, upper\n\ndef add_one_order(Adjacency_List):\n    New_Adjacency_List = copy.deepcopy(Adjacency_List)\n    for i in tqdm(range(m)):\n        for j in Adjacency_List[i]:\n            New_Adjacency_List[i].update(Adjacency_List_pre[j])\n        # Remove duplicated communication\n        communication_cost_each_customer[i] += len(New_Adjacency_List[i])\n    return New_Adjacency_List\n\ndef count_order(Adjacency_List):\n    lower = 1\n    count = 1\n    while lower < m:\n        count += 1\n        lower, upper = neighbors_range(Adjacency_List)\n        Adjacency_List= add_one_order(Adjacency_List)\n    return count \ncurrent = 1\nlower,upper = neighbors_range(Adjacency_List)\nprint(lower,upper)","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:00:04.853769Z","iopub.execute_input":"2023-07-25T22:00:04.854235Z","iopub.status.idle":"2023-07-25T22:00:35.172782Z","shell.execute_reply.started":"2023-07-25T22:00:04.854203Z","shell.execute_reply":"2023-07-25T22:00:35.171397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Training","metadata":{"_uuid":"c9f5691e-753e-4438-86ba-9812c5f33241","_cell_guid":"15afe07a-7e71-4489-926c-120b6b164ea1","trusted":true}},{"cell_type":"markdown","source":"Define your hyperparameters and fit the model. Take into account that there are more customizable parameters in the data processing section.","metadata":{"_uuid":"2b83591e-199b-41d0-93fb-e2fdbd1f1694","_cell_guid":"2691ee89-c24b-45f8-985e-286d5d60a467","trusted":true}},{"cell_type":"code","source":"from torch.utils.data import Dataset, DataLoader\nimport torch\nfrom tqdm import tqdm\n\nclass HMDataset(Dataset):\n    def __init__(self, df):\n        self.df = df.reset_index(drop=True)\n\n    def __len__(self):\n        return self.df.shape[0]\n\n    def __getitem__(self, index):\n        row = self.df.iloc[index]\n\n        target = torch.tensor(row.bought).float()\n        customer = torch.tensor(row.customer_id)\n        item = torch.tensor(row.article_id)\n\n        return customer,item, target\n\nHMDataset(train_df)[0]\n","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:00:35.174556Z","iopub.execute_input":"2023-07-25T22:00:35.175431Z","iopub.status.idle":"2023-07-25T22:00:39.030865Z","shell.execute_reply.started":"2023-07-25T22:00:35.175398Z","shell.execute_reply":"2023-07-25T22:00:39.029566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def adjust_lr(optimizer, epoch):\n    lr = 5e-3\n\n    for p in optimizer.param_groups:\n        p['lr'] = lr\n    return lr\n\n\ndef get_optimizer(net):\n    optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad, net.parameters()), lr=3e-3, betas=(0.9, 0.999),\n                                 eps=1e-08)\n\n    return optimizer","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:00:39.033529Z","iopub.execute_input":"2023-07-25T22:00:39.034423Z","iopub.status.idle":"2023-07-25T22:00:39.041466Z","shell.execute_reply.started":"2023-07-25T22:00:39.034385Z","shell.execute_reply":"2023-07-25T22:00:39.040203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch.nn as nn\nimport torch.nn.functional as F\nimport copy\n\nclass HMModel(nn.Module):\n    def __init__(self,index):\n        super(HMModel, self).__init__()\n        self.index = index\n        torch.manual_seed(3)\n        self.all_user_emb = nn.Embedding(6588, embedding_dim=30).float()\n        self.item_emb = nn.Embedding(5102, embedding_dim=30).float()\n        self.top = nn.Sequential(nn.Linear(60, 32), nn.LeakyReLU(), nn.Linear(32, 1), nn.LeakyReLU())\n        self.user_emb = torch.nn.parameter.Parameter(self.all_user_emb(torch.tensor(self.index))).float()\n\n    def forward(self, inputs):\n        user_index, item_index = inputs[0], inputs[1]\n        u_e = self.user_emb.reshape(30)\n        i_e = self.item_emb(item_index).reshape(30)\n        x = torch.cat((u_e,i_e),0)\n        x = self.top(x).type(torch.FloatTensor)\n        \n        return x\n  \n","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:00:39.042944Z","iopub.execute_input":"2023-07-25T22:00:39.043501Z","iopub.status.idle":"2023-07-25T22:00:39.059535Z","shell.execute_reply.started":"2023-07-25T22:00:39.043446Z","shell.execute_reply":"2023-07-25T22:00:39.058198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_dict = {}\nfor x in tqdm(range(6588)):\n    model_dict[\"model{0}\".format(x)] = HMModel(x)","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:00:39.061138Z","iopub.execute_input":"2023-07-25T22:00:39.061889Z","iopub.status.idle":"2023-07-25T22:01:18.540346Z","shell.execute_reply.started":"2023-07-25T22:00:39.061852Z","shell.execute_reply":"2023-07-25T22:01:18.537917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\n\ndef read_data(data):\n    return tuple(d for d in data[:-1]), data[-1]\n\ndef validate(model_dict, val_loader):\n\n    tbar = val_loader\n    criterion = nn.MSELoss()\n    loss_list = []\n    for i in range(len(model_dict)):\n            model_dict[\"model{0}\".format(i)].eval()\n\n    with torch.no_grad():\n        for idx, data in enumerate(tbar):\n            inputs, target = read_data(data)\n            #print(model_dict[\"model{0}\".format(3)])\n            #model_dict[\"model{0}\".format(int(inputs[0]))].eval()\n            logits = model_dict[\"model{0}\".format(int(inputs[0]))](inputs)\n            loss = torch.sqrt(criterion(logits, target))\n\n            loss_list.append(loss.detach().cpu().item())\n        avg_loss = np.mean(loss_list)\n\n    return avg_loss\n\nNW = 0\n\nval_dataset = HMDataset(val_df)\nval_loader = DataLoader(val_dataset, batch_size=1, shuffle=False, num_workers=NW,\n                          pin_memory=False, drop_last=False)","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:01:18.541680Z","iopub.execute_input":"2023-07-25T22:01:18.542608Z","iopub.status.idle":"2023-07-25T22:01:18.554187Z","shell.execute_reply.started":"2023-07-25T22:01:18.542573Z","shell.execute_reply":"2023-07-25T22:01:18.553272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Select Order\ncurrent = 1\ndef get_order(current,Adjacency_List):\n    for i in range(5):\n        Adjacency_List = add_one_order(Adjacency_List)\n        current += 1\n        lower, upper = neighbors_range(Adjacency_List)\n        print('The range of the number of neighbor is: ',lower,'-',upper)\n    return current,Adjacency_List\n\ncurrent,Adjacency_List = get_order(current,Adjacency_List)\ncurrent","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:01:18.555358Z","iopub.execute_input":"2023-07-25T22:01:18.556251Z","iopub.status.idle":"2023-07-25T22:01:20.617802Z","shell.execute_reply.started":"2023-07-25T22:01:18.556220Z","shell.execute_reply":"2023-07-25T22:01:20.616474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_loss = []\noptimizer_dict = {}\ndef train(model_dict, train_loader, epochs):\n\n    criterion = nn.MSELoss()\n    val_map = validate(model_dict, val_loader)\n    val_loss.append(val_map)\n    for i in tqdm(range(6588)):\n        optimizer_dict[\"model{0}\".format(i)] = get_optimizer(model_dict[\"model{0}\".format(i)])\n    \n    for e in range(epochs):\n        tbar = tqdm(train_loader, file=sys.stdout)\n        #lr = adjust_lr(optimizer, e)\n        for i in range(len(model_dict)):\n            model_dict[\"model{0}\".format(i)].train()\n        loss_list = []\n        for idx, data in enumerate(tbar):\n            inputs, target = read_data(data)\n            #model_dict[\"model{0}\".format(int(inputs[0]))].train()\n            optimizer = optimizer_dict[\"model{0}\".format(int(inputs[0]))] \n            optimizer.zero_grad()\n            logits = model_dict[\"model{0}\".format(int(inputs[0]))](inputs)\n            loss = torch.sqrt(criterion(logits, target))\n            loss.backward()\n            \n            #Get gradients of current Model\n            model_gradient = {}\n            for name,param in model_dict[\"model{0}\".format(int(inputs[0]))].named_parameters():\n                if name == 'user_emb':\n                    model_gradient[name] = None\n                    continue\n                gradient = param.grad\n                model_gradient[name] = gradient\n                \n            #Assign gradients to neighbors' Model\n            user_n = list(Adjacency_List[int(inputs[0])])\n            for neighbor in user_n:\n                neighbor_model = model_dict[\"model{0}\".format(neighbor)]\n                neighbor_optimizer = optimizer_dict[\"model{0}\".format(neighbor)]\n                neighbor_model.zero_grad()\n                for name,param in neighbor_model.named_parameters():\n                    param.grad = model_gradient[name]\n                neighbor_optimizer.step()\n                \n            optimizer.step()\n            loss_list.append(loss.detach().cpu().item())\n            avg_loss = np.mean(loss_list)\n            tbar.set_description(f\"Epoch {e+1} Loss: {np.round(avg_loss,7)}\")\n            #print(model.layer_dict[\"model1\"][0].weight == model.layer_dict[\"model2\"][0].weight)\n\n        val_map = validate(model_dict, val_loader)\n        val_loss.append(val_map)\n        log_text = f\"Epoch {e+1}\\nTrain Loss: {avg_loss}\\nValidation Loss: {val_map}\\n\"\n        print(log_text)\n\n\n\n\ntrain_dataset = HMDataset(train_df)\ntrain_loader = DataLoader(train_dataset, batch_size=1, shuffle=True, num_workers=NW,\n                          pin_memory=False, drop_last=False)\n\ntrain(model_dict, train_loader,epochs=4)","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:01:20.619735Z","iopub.execute_input":"2023-07-25T22:01:20.620208Z","iopub.status.idle":"2023-07-25T22:02:23.572184Z","shell.execute_reply.started":"2023-07-25T22:01:20.620166Z","shell.execute_reply":"2023-07-25T22:02:23.570732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_loss","metadata":{"execution":{"iopub.status.busy":"2023-07-25T22:02:23.573969Z","iopub.status.idle":"2023-07-25T22:02:23.574978Z","shell.execute_reply.started":"2023-07-25T22:02:23.574665Z","shell.execute_reply":"2023-07-25T22:02:23.574695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import matplotlib.pyplot as plt\n# x = np.arange(0,len(val_loss))\n# #plt.title('Random_5_out Graph')\n# plt.plot(x,  val_loss, label = \"NCF_Decentralized\")\n# # plt.plot(x, vanilla, label = \"Vanilla\")\n# # plt.plot(x, gossip_learning, label = \"Gossip_Learning\")\n# # plt.plot(x, decentralized, label = \"Decentralized\")\n# plt.xlabel('Epoch')\n# plt.ylabel('Loss')\n# plt.legend()\n# plt.show()","metadata":{"_uuid":"9a7cb51a-7149-44a0-a0ad-7a5fbdfdef12","_cell_guid":"0c60e9d9-066c-4e7c-9d7b-934784b060ef","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-25T22:02:23.576631Z","iopub.status.idle":"2023-07-25T22:02:23.577873Z","shell.execute_reply.started":"2023-07-25T22:02:23.577562Z","shell.execute_reply":"2023-07-25T22:02:23.577593Z"},"trusted":true},"execution_count":null,"outputs":[]}]}