def tune_alpha(self,
                range_alpha=np.arange(0.5, 1.5, 0.1),
                k=100,
                shrink=0,
                threshold=0,
                verbose_tune=False,
                filename='tuning_bm25_alpha',
                overwrite=False,
                save_mean=True,
                save_full=True):
     tp = TunePrint(filename=filename,
                    full=save_full,
                    mean=save_mean,
                    overwrite=overwrite)
     self.model(
         alpha=1, beta=0, k=k, shrink=shrink,
         threshold=threshold)  #exploit this trick to generate fastest model
     save_data = self.s.data
     for alpha in range_alpha:
         self.s.data = save_data
         self.s.data = np.power(self.s.data, alpha)
         self.alpha = alpha
         self.fast_recommend()
         mean, df_all_values = self.fast_evaluate_eurm()
         self.clear_eurm()
         s_mean = 'P = %1.4f, NDCG = %1.4f, CLICK = %1.4f' % (
             mean[0], mean[1], mean[2])
         if verbose_tune: print(str(self) + '\n' + s_mean)
         if save_mean: tp.print_mean_values(str(self), mean)
         if save_full:
             tp.print_full_values(description=str(self),
                                  dict_val={'alpha': alpha},
                                  dataframe=df_all_values)
     tp.make_pdf_full()
 def tune_shrink(self,
                 range_shrink=np.arange(25, 300, 25),
                 alpha=1,
                 beta=0,
                 k=200,
                 threshold=0,
                 verbose_tune=True,
                 filename='tuning_bm25_shrink',
                 overwrite=False,
                 save_mean=True,
                 save_full=True):
     tp = TunePrint(filename=filename,
                    full=save_full,
                    mean=save_mean,
                    overwrite=overwrite)
     for shrink in range_shrink:
         self.model(alpha=alpha,
                    beta=beta,
                    k=k,
                    shrink=shrink,
                    threshold=threshold)
         self.fast_recommend()
         self.clear_similarity()
         mean, df_all_values = self.fast_evaluate_eurm()
         self.clear_eurm()
         s_mean = 'P = %1.4f, NDCG = %1.4f, CLICK = %1.4f' % (
             mean[0], mean[1], mean[2])
         if verbose_tune: print(str(self) + '\n' + s_mean)
         # save values
         if save_mean: tp.print_mean_values(str(self), mean)
         if save_full:
             tp.print_full_values(description=str(self),
                                  dict_val={'shrink': shrink},
                                  dataframe=df_all_values)
     tp.make_pdf_full()
Beispiel #3
0
 def tune_alpha_beta(self,
                     range_alpha=np.arange(0, 1.1, 0.1),
                     range_beta=np.arange(0, 1.1, 0.1),
                     k=200,
                     shrink=0,
                     threshold=0,
                     power=1,
                     verbose_tune=True,
                     filename='tuning_bm25_alpha_beta',
                     overwrite=False,
                     save_mean=True,
                     save_full=True):
     tp = TunePrint(filename=filename,
                    full=save_full,
                    mean=save_mean,
                    overwrite=overwrite)
     for alpha in range_alpha:
         for beta in range_beta:
             self.model(alpha=alpha,
                        beta=beta,
                        k=k,
                        shrink=shrink,
                        power=power,
                        threshold=threshold)
             self.fast_recommend()
             self.clear_similarity()
             mean, df_all_values = self.fast_evaluate_eurm()
             self.clear_eurm()
             s_mean = 'P = %1.4f, NDCG = %1.4f, CLICK = %1.4f' % (
                 mean[0], mean[1], mean[2])
             if verbose_tune: print(str(self) + '\n' + s_mean)
             if save_mean: tp.print_mean_values(str(self), mean)
             if save_full:
                 tp.print_full_values(description=str(self),
                                      dict_val={
                                          'alpha': alpha,
                                          'beta': beta
                                      },
                                      dataframe=df_all_values)
     tp.make_pdf_full()