Ejemplo n.º 1
0
#
# It is made available under the MIT License

from sklearn.linear_model import LinearRegression
from load_ml100k import load
import numpy as np
import similar_movie
import usermodel
import corrneighbours

sreviews = load()
reviews = sreviews.toarray()
reg = LinearRegression()
es = np.array([
    usermodel.all_estimates(sreviews),
    similar_movie.all_estimates(reviews, k=1),
    similar_movie.all_estimates(reviews, k=2),
    similar_movie.all_estimates(reviews, k=3),
    similar_movie.all_estimates(reviews, k=4),
    similar_movie.all_estimates(reviews, k=5),
])

total_error = 0.0
coefficients = []
for u in xrange(reviews.shape[0]):
    es0 = np.delete(es, u, 1)
    r0 = np.delete(reviews, u, 0)
    X, Y = np.where(r0 > 0)
    X = es[:, X, Y]
    y = r0[r0 > 0]
    reg.fit(X.T, y)
Ejemplo n.º 2
0
# It is made available under the MIT License

from __future__ import print_function
from sklearn.linear_model import LinearRegression
from load_ml100k import load
import numpy as np
import similar_movie
import usermodel
import corrneighbours

reviews = load()
reg = LinearRegression()
es = np.array([
    usermodel.all_estimates(reviews),
    corrneighbours.all_estimates(reviews),
    similar_movie.all_estimates(reviews),
])

total_error = 0.0
coefficients = []
for u in range(reviews.shape[0]):
    es0 = np.delete(es, u, 1)
    r0 = np.delete(reviews, u, 0)
    X, Y = np.where(r0 > 0)
    X = es[:, X, Y]
    y = r0[r0 > 0]
    reg.fit(X.T, y)
    coefficients.append(reg.coef_)

    r0 = reviews[u]
    X = np.where(r0 > 0)