<s> from fastFM . datasets import make_user_item_regression <EOL> from fastFM import als <EOL> from sklearn . metrics import mean_squared_error <EOL> import scipy . sparse as sp <EOL> import numpy as np <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> X , y , coef = make_user_item_regression ( label_stdev = <NUM_LIT> ) <EOL> from sklearn . cross_validation import train_test_split <EOL> X_train , X_test , y_train , y_test = train_test_split ( <EOL> X , y , test_size = <NUM_LIT> , random_state = <NUM_LIT> ) <EOL> X_train = sp . csc_matrix ( X_train ) <EOL> X_test = sp . csc_matrix ( X_test ) <EOL> n_iter = <NUM_LIT:50> <EOL> """<STR_LIT>""" <EOL> n_iter = <NUM_LIT:50> <EOL> rank = <NUM_LIT:4> <EOL> seed = <NUM_LIT> <EOL> step_size = <NUM_LIT:1> <EOL> l2_reg_w = <NUM_LIT:0> <EOL> l2_reg_V = <NUM_LIT:0> <EOL> fm = als . FMRegression ( n_iter = <NUM_LIT:0> , l2_reg_w = l2_reg_w , <EOL> l2_reg_V = l2_reg_V , rank = rank , random_state = seed ) <EOL> fm . fit ( X_train , y_train ) <EOL> rmse_train = [ ] <EOL> rmse_test = [ ] <EOL> for i in range ( <NUM_LIT:1> , n_iter ) : <EOL> fm . fit ( X_train , y_train , n_more_iter = step_size ) <EOL> y_pred = fm . predict ( X_test ) <EOL> rmse_train . append ( np . sqrt ( mean_squared_error ( fm . predict ( X_train ) , y_train ) ) ) <EOL> rmse_test . append ( np . sqrt ( mean_squared_error ( fm . predict ( X_test ) , y_test ) ) ) <EOL> print '<STR_LIT>' <EOL> values = np . arange ( <NUM_LIT:1> , n_iter ) <EOL> rmse_test_re = [ ] <EOL> rmse_train_re = [ ] <EOL> for i in values : <EOL> fm = als . FMRegression ( n_iter = i , l2_reg_w = l2_reg_w , <EOL> l2_reg_V = l2_reg_V , rank = rank , random_state = seed ) <EOL> fm . fit ( X_train , y_train ) <EOL> rmse_test_re . append ( np . sqrt ( mean_squared_error ( fm . predict ( X_test ) , y_test ) ) ) <EOL> rmse_train_re . append ( np . sqrt ( mean_squared_error ( fm . predict ( X_train ) , y_train ) ) ) <EOL> from matplotlib import pyplot as plt <EOL> x = np . arange ( <NUM_LIT:1> , n_iter ) * step_size <EOL> with plt . style . context ( '<STR_LIT>' ) : <EOL> plt . plot ( x , rmse_train , label = '<STR_LIT:train>' ) <EOL> plt . plot ( x , rmse_test , label = '<STR_LIT:test>' ) <EOL> plt . plot ( values , rmse_train_re , label = '<STR_LIT>' , linestyle = '<STR_LIT>' ) <EOL> plt . plot ( values , rmse_test_re , label = '<STR_LIT>' , ls = '<STR_LIT>' ) <EOL> plt . legend ( ) <EOL> plt . show ( ) </s>
