Пример #1
0
def test_dummy_axis0():
    est = Dummy(axis=0)
    est.fit(X)
    X_predicted = est.predict(X).toarray()
    X_expected = [[2, 0, 0, 1], [2, 0, 10. / 3, 0], [0, 4, 10. / 3, 0],
                  [0, 0, 10. / 3, 0], [2, 0, 0, 0]]
    assert_array_almost_equal(X_predicted, X_expected)
Пример #2
0
def test_dummy_axis1():
    est = Dummy()
    est.fit(X)
    X_predicted = est.predict(X).toarray()
    X_expected = [[2, 0, 0, 2], [3.5, 0, 3.5, 0], [0, 3.5, 3.5, 0],
                  [0, 0, 2, 0], [1, 0, 0, 0]]
    assert_array_almost_equal(X_predicted, X_expected)
Пример #3
0
def test_dummy_axis0():
    est = Dummy(axis=0)
    est.fit(X)
    X_predicted = est.predict(X).toarray()
    X_expected = [[2, 0, 0, 1],
                  [2, 0, 10./3, 0],
                  [0, 4, 10./3, 0],
                  [0, 0, 10./3, 0],
                  [2, 0, 0, 0]]
    assert_array_almost_equal(X_predicted, X_expected)
Пример #4
0
def test_dummy_axis1():
    est = Dummy()
    est.fit(X)
    X_predicted = est.predict(X).toarray()
    X_expected = [[2, 0, 0, 2],
                  [3.5, 0, 3.5, 0],
                  [0, 3.5, 3.5, 0],
                  [0, 0, 2, 0],
                  [1, 0, 0, 0]]
    assert_array_almost_equal(X_predicted, X_expected)
Пример #5
0
cv = ShuffleSplit(n_iter=3, train_size=0.75, random_state=0)

for alpha in alphas:
    mf = ExplicitMF(n_components=30, max_iter=10, alpha=alpha)
    # mf = DictMF(n_components=30, n_epochs=10, alpha=alpha, verbose=1,
    #             batch_size=10, normalize=True,
    #             fit_intercept=True,
    #             random_state=0,
    #             learning_rate=.5)
    mf_scores.append(cross_val_score(mf, X, cv))

# Array of size n_alphas x n_folds.
mf_scores = np.array(mf_scores)

dummy = Dummy()
dummy_scores = cross_val_score(dummy, X, cv)

dummy = Dummy(axis=0)
dummy_scores2 = cross_val_score(dummy, X, cv)

plt.figure()
plt.plot(alphas, mf_scores.mean(axis=1), label="Matrix Factorization")
plt.plot(alphas, [dummy_scores.mean()] * len(alphas), label="User mean")
plt.plot(alphas, [dummy_scores2.mean()] * len(alphas), label="Movie mean")
plt.xlabel("alpha")
plt.xscale("log")
plt.ylabel("RMSE")
plt.legend()
plt.savefig('cross_val.pdf')