This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="https://d3js.org/d3.v6.js"></script> | |
<title></title> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<!-- Load d3.js --> | |
<script src="https://d3js.org/d3.v4.js"></script> | |
<!-- Create a div where the circle will take place --> | |
<div id="dataviz_brushZoom"></div> | |
<script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://d3js.org v7.0.1 Copyright 2010-2021 Mike Bostock | |
(function (global, factory) { | |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | |
typeof define === 'function' && define.amd ? define(['exports'], factory) : | |
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {})); | |
}(this, (function (exports) { 'use strict'; | |
var version = "7.0.1"; | |
function ascending$3(a, b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_2 = Model(input=model.get_layer('input_2').input, output = model.get_layer('embedding_2').output) | |
user_movie_embeddings = model_2.predict(x = usrc) # usrc = array of movie id liked by user | |
user_movie_embeddings = user_movie_embeddings.reshape(len(usrc),10) | |
user_movie_bias = np.array([5 for temp in range(len(usrc))]) | |
user_embedding, residuals, rank, s = np.linalg.lstsq(user_movie_embeddings,user_movie_bias, rcond=-1) # Get embedding for new user | |
user_embedding = user_embedding.reshape(1, 10) # User embedding based on choices of user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mc = keras.callbacks.ModelCheckpoint('weights{epoch:01d}.h5', period=1) | |
r = model.fit( | |
x=[df_train.userId.values, df_train.movie_idx.values], | |
y=df_train.rating.values - mu, | |
epochs=epochs, | |
batch_size=128, | |
validation_data=( | |
[df_test.userId.values, df_test.movie_idx.values], | |
df_test.rating.values - mu | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.compile( | |
loss='mse', | |
optimizer=SGD(lr=0.08, momentum=0.9), | |
metrics=['mse'], | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.utils import shuffle | |
from torch import nn | |
import torch | |
import torch.nn.functional as F | |
N = df.userId.max() + 1 # number of users | |
M = df.movie_idx.max() + 1 # number of movies | |
# split into train and test | |
df = shuffle(df, random_state = 12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# keras model | |
u = Input(shape=(1,)) | |
m = Input(shape=(1,)) | |
u_embedding = Embedding(N, K)(u) # (N, 1, K) | |
m_embedding = Embedding(M, K)(m) # (N, 1, K) | |
u_embedding = Flatten()(u_embedding) # (N, K) | |
m_embedding = Flatten()(m_embedding) # (N, K) | |
x = Concatenate()([u_embedding, m_embedding]) # (N, 2K) | |
x = Dense(400)(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from tqdm import tqdm | |
train_losses, test_losses = [], [] | |
for e in range(epochs): | |
running_loss = 0 | |
for i in tqdm(range(0, len(df_train), 128)): | |
train = df_train[i:i+128] | |
optimizer.zero_grad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch import optim | |
criterion = nn.MSELoss() | |
optimizer = optim.SGD(model.parameters(), lr = 0.08, momentum=0.9) |
NewerOlder