text_html_output_1.png
import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
M = np.array([[1, 1, 1, 0, 0], [3, 3, 3, 0, 0], [4, 4, 4, 0, 0], [5, 5, 5, 0, 0], [0, 0, 0, 4, 4], [0, 0, 0, 5, 5], [0, 0, 0, 2, 2]])
d = pd.DataFrame(M, index=['Joe', 'Jim', 'John', 'Jack', 'Jill', 'Jenny', 'Jane'], columns=['Matrix', 'Alien', 'Star Wars', 'Casablanca', 'Titanic'])

Sigma = np.zeros((7, 5), dtype=float)
Sigma[:5, :5] = np.diag(S)

U = U[:, 0:2]
Sigma = np.zeros((2, 2), dtype=float)
Sigma[:2, :2] = np.diag(S[:2])
Vt = Vt[0:2, :]

q = np.array([4, 0, 0, 0, 0])
V = Vt.transpose()
print(f'Query: q={q}')
qV = np.dot(q, V)
print(f'Map to concept space: qV={qV}')
print(f'Map back to movie space by multiplying by Vt = {np.dot(qV, Vt)}')