def main(): X1_train, X2_train, Y_train, X1_test, X2_test, Y_test = davis_data.setting2_split() learner = KronRLS(X1 = X1_train, X2 = X2_train, Y = Y_train) log_regparams = range(15, 35) for log_regparam in log_regparams: learner.solve(2.**log_regparam) P = learner.predict(X1_test, X2_test) perf = cindex(Y_test, P) print("regparam 2**%d, cindex %f" %(log_regparam, perf))
def main(): X1_train, X2_train, Y_train, X1_test, X2_test, Y_test = davis_data.settingB_split() learner = KronRLS(X1 = X1_train, X2 = X2_train, Y = Y_train) log_regparams = range(15, 35) for log_regparam in log_regparams: learner.solve(2.**log_regparam) P = learner.predict(X1_test, X2_test) perf = cindex(Y_test, P) print("regparam 2**%d, cindex %f" %(log_regparam, perf))
def main(): X1_train, X2_train, Y_train, X1_test, X2_test, Y_test = davis_data.settingD_split() kernel1 = GaussianKernel(X1_train, gamma=0.01) kernel2 = GaussianKernel(X2_train, gamma=10**-9) K1_train = kernel1.getKM(X1_train) K1_test = kernel1.getKM(X1_test) K2_train = kernel2.getKM(X2_train) K2_test = kernel2.getKM(X2_test) learner = KronRLS(K1 = K1_train, K2 = K2_train, Y = Y_train) log_regparams = range(-15, 15) for log_regparam in log_regparams: learner.solve(2.**log_regparam) P = learner.predict(K1_test, K2_test) perf = cindex(Y_test, P) print("regparam 2**%d, cindex %f" %(log_regparam, perf))
class QuestionsXTags(): def fit(self, Y, user_features, item_features, reg): self.Y = np.array(Y.toarray(), dtype=float) self.m, self.n = Y.shape self.Y = self.Y.ravel(order='F') self.user_features = user_features self.item_features = item_features X_users = np.array(user_features.toarray(), dtype=float) X_items = np.array(item_features.toarray(), dtype=float) self.learner = KronRLS(X1=X_users, X2=X_items, Y=self.Y, regparam=reg) def predict(self, row): x = self.user_features.getrow(row) W = self.learner.predictor.W X = sp.kron(self.item_features, x) predictions = X.dot(W) return (predictions) def predict_online(self, x): #x = x.reshape(1,-1) W = self.learner.predictor.W X = sp.kron(self.item_features, x) predictions = X.dot(W) return (predictions) def predict1(self): m, n = self.m, self.n X_users = np.array(self.user_features.toarray(), dtype=float) X_items = np.array(self.item_features.toarray(), dtype=float) predictions = self.learner.predict(X_users, X_items).reshape((m, n), order='F') return (predictions) def predict2(self, item_features): m, n = self.m, self.n t, k = item_features.shape X_users = np.array(self.user_features.toarray(), dtype=float) predictions = self.learner.predict(X_users, item_features).reshape( (m, t), order='F') return (predictions) def predict3(self, user_features): m, n = self.m, self.n t, k = user_features.shape X_items = np.array(self.item_features.toarray(), dtype=float) predictions = self.learner.predict(user_features, X_items).reshape( (t, n), order='F') return (predictions) def predict4(self, user_features, item_features): t, k = user_features.shape s, k = item_features.shape predictions = self.learner.predict(user_features, item_features).reshape((t, s), order='F') return (predictions)