推荐系统Surprise-Basic algorithms之NormalPredictor

这种预测算法是假设评分数据是来自一个正态分布的数据

现有一组用户对电影的评分数据,这是一个稀疏矩阵,其中含有很多空白数据,我们要做的就是对这些数据进行预测.

下面对数据进行建模:
假设所有的预测数据r̂ ui服从一个正太分布(μ̂ ,σ̂ 2) ,屌丝手写

μ̂ σ̂ =1|Rtrain|ruiRtrainrui=ruiRtrain(ruiμ̂ )2|Rtrain| μ ^ = 1 | R t r a i n | ∑ r u i ∈ R t r a i n r u i σ ^ = ∑ r u i ∈ R t r a i n ( r u i − μ ^ ) 2 | R t r a i n |

推荐系统Surprise-Basic algorithms之NormalPredictor_第1张图片
下面我们来实用surprise来直接实现

from surprise import Dataset
from surprise import NormalPredictor, evaluate
from surprise.model_selection import cross_validate
data = Dataset.load_builtin('ml-100k')

# Select the algorithm
algo = NormalPredictor()

# deprecated
# evaluate(algo, data, measures=['RMSE', 'MAE'])

# Test the model
pref = cross_validate(algo, data, verbose=True)

print(pref)

测试结果:

Evaluating RMSE, MAE of algorithm NormalPredictor on 5 split(s).

                  Fold 1  Fold 2  Fold 3  Fold 4  Fold 5  Mean    Std     
RMSE (testset)    1.5054  1.5228  1.5109  1.5185  1.5133  1.5142  0.0060  
MAE (testset)     1.2070  1.2233  1.2137  1.2216  1.2161  1.2163  0.0058  
Fit time          0.08    0.13    0.09    0.10    0.07    0.09    0.02    
Test time         0.16    0.19    0.18    0.18    0.13    0.17    0.02    
{'test_rmse': array([1.50536524, 1.5228481 , 1.51093185, 1.51848558, 1.51326424]), 'test_mae': array([1.20696218, 1.22329666, 1.21374827, 1.22158879, 1.21606117]), 'fit_time': (0.07692193984985352, 0.12638354301452637, 0.09193754196166992, 0.09979796409606934, 0.0673062801361084), 'test_time': (0.1640009880065918, 0.19167232513427734, 0.18456101417541504, 0.1820223331451416, 0.13440251350402832)}

你可能感兴趣的:(机器学习)