예제 #1
0
def make_user_item_regression(random_state=123, n_user=20, n_item=20,
                              label_stdev=0.4, rank=2, bias=True,
                              first_order=True, stdev_w0=.2, stdev_w=0.3,
                              stdev_V=0.4, mean_w0=2, mean_w=5, mean_V=10):

    n_features = n_user + n_item
    n_samples = n_user * n_item
    # create design matrix
    user_cols = np.repeat(range(n_user), n_item)
    item_cols = np.array(list(range(n_item)) * n_user) + n_user
    cols = np.hstack((user_cols, item_cols))
    rows = np.hstack((np.arange(n_item*n_user), np.arange(n_item*n_user)))

    X = sp.coo_matrix((np.ones_like(cols, dtype=np.float64), (rows, cols)))
    X = sp.csc_matrix(X)
    assert X.shape[0] == n_samples
    assert X.shape[1] == n_features

    # sample the model parameter
    random_state = check_random_state(random_state)
    w0 = random_state.normal(mean_w0, stdev_w0)
    w = random_state.normal(mean_w, stdev_w, n_features)
    V = random_state.normal(mean_V, stdev_V, (rank, n_features))

    y = ffm_predict(w0, w, V, X)
    if label_stdev > 0:
        y = random_state.normal(y, label_stdev)

    return X, y, (w0, w, V)
예제 #2
0
파일: datasets.py 프로젝트: sebkur/fastFM
def make_user_item_regression(random_state=123, n_user=20, n_item=20,
                              label_stdev=0.4, rank=2, bias=True,
                              first_order=True, stdev_w0=.2, stdev_w=0.3,
                              stdev_V=0.4, mean_w0=2, mean_w=5, mean_V=10):

    n_features = n_user + n_item
    n_samples = n_user * n_item
    # create design matrix
    user_cols = np.repeat(range(n_user), n_item)
    item_cols = np.array(range(n_item) * n_user) + n_user
    cols = np.hstack((user_cols, item_cols))
    rows = np.hstack((np.arange(n_item*n_user), np.arange(n_item*n_user)))

    X = sp.coo_matrix((np.ones_like(cols, dtype=np.float64), (rows, cols)))
    X = sp.csc_matrix(X)
    assert X.shape[0] == n_samples
    assert X.shape[1] == n_features

    # sample the model parameter
    random_state = check_random_state(random_state)
    w0 = random_state.normal(mean_w0, stdev_w0)
    w = random_state.normal(mean_w, stdev_w, n_features)
    V = random_state.normal(mean_V, stdev_V, (rank, n_features))

    y = ffm_predict(w0, w, V, X)
    if label_stdev > 0:
        y = random_state.normal(y, label_stdev)

    return X, y, (w0, w, V)
예제 #3
0
파일: base.py 프로젝트: irwenqiang/fastFM
    def predict(self, X_test):
        """ Return predictions

        Parameters
        ----------
        X : scipy.sparse.csc_matrix, (n_samples, n_features)

        Returns
        ------

        T : array, shape (n_samples)
            The labels are returned for classification.
        """
        X_test = check_array(X_test, accept_sparse="csc", dtype=np.float64, order="F")
        assert sp.isspmatrix_csc(X_test)
        assert X_test.shape[1] == len(self.w_)
        return ffm.ffm_predict(self.w0_, self.w_, self.V_, X_test)
예제 #4
0
    def predict(self, X_test):
        """ Return predictions

        Parameters
        ----------
        X : scipy.sparse.csc_matrix, (n_samples, n_features)

        Returns
        ------

        T : array, shape (n_samples)
            The labels are returned for classification.
        """
        X_test = check_array(X_test, accept_sparse="csc", dtype=np.float64,
                             order="F")
        assert sp.isspmatrix_csc(X_test)
        assert X_test.shape[1] == len(self.w_)
        return ffm.ffm_predict(self.w0_, self.w_, self.V_, X_test)
예제 #5
0
def test_ffm_predict():
    w0, w, V, y, X = get_test_problem()
    y_pred = ffm.ffm_predict(w0, w, V, X)
    assert_equal(y_pred, y)
예제 #6
0
def test_ffm_predict():
    w0, w, V, y, X = get_test_problem()
    y_pred = ffm.ffm_predict(w0, w, V, X)
    assert_equal(y_pred, y)