[ドキュメント]defclear_row(self,dataset):""" Removes the given rows from the recommendation table. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('dataset must have `id`.')result=cli.clear_row(row_id)yield(idx,row_id,result)

[ドキュメント]defupdate_row(self,dataset):""" Update data points to the recommender model using the given dataset. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('datasets must have `id`')result=cli.update_row(row_id,d)yield(idx,row_id,result)

[ドキュメント]defcomplete_row_from_id(self,dataset):""" Returns data points from the row id in the recommender model, with missing value completed by predicted value. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('Non ID-based datasets must use `complete_row_from_datum`')result=cli.complete_row_from_id(row_id)yield(idx,row_id,result)

[ドキュメント]defcomplete_row_from_datum(self,dataset):""" Returns data points from the datum in the recommender model, with missing value completed by predicted value. """cli=self._client()for(idx,(row_id,d))indataset:result=cli.complete_row_from_datum(d)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_id(self,dataset,size=10):""" Returns similar data points from the row id in the recommender model. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('Non ID-based datasets must use `similar_row_from_datum`')result=cli.similar_row_from_id(row_id,size)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_id_and_score(self,dataset,score=0.8):""" Returns rows which are most similar to the row id and have a greater similarity score than score. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('Non ID-based datasets must use `similar_row_from_datum_and_score`')result=cli.similar_row_from_id_and_score(row_id,score)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_id_and_rate(self,dataset,rate=0.1):""" Returns the top rate of all the rows which are most similar to the row id. For example, return the top 10% of all the rows when 0.1 is specified as rate. The rate must be in (0, 1]. """ifrate<=0.0or1.0<rate:raiseValueError('rate must be in (0, 1], but {}'.format(rate))cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('Non ID-based datasets must use `similar_row_from_datum_and_rate`')result=cli.similar_row_from_id_and_rate(row_id,rate)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_datum(self,dataset,size=10):""" Returns similar data points from the datum in the recommender model. """cli=self._client()for(idx,(row_id,d))indataset:result=cli.similar_row_from_datum(d,size)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_datum_and_score(self,dataset,score=0.8):""" Returns rows which are most similar to row and have a greater similarity score than score. """cli=self._client()for(idx,(row_id,d))indataset:result=cli.similar_row_from_datum_and_score(d,score)yield(idx,row_id,result)

[ドキュメント]defsimilar_row_from_datum_and_rate(self,dataset,rate=0.1):""" Returns the top rate of all the rows which are most similar to row. For example, return the top 10% of all the rows when 0.1 is specified as rate. The rate must be in (0, 1]. """ifrate<=0.0or1.0<rate:raiseValueError('rate must be in (0, 1], but {}'.format(rate))cli=self._client()for(idx,(row_id,d))indataset:result=cli.similar_row_from_datum_and_rate(d,rate)yield(idx,row_id,result)

[ドキュメント]defdecode_row(self,dataset):""" Returns data points in the row id. """cli=self._client()for(idx,(row_id,d))indataset:ifrow_idisNone:raiseRuntimeError('Each data in datasets must has `row_id`')result=cli.decode_row(row_id)yield(idx,row_id,result)

@classmethoddef_default_method(cls):return'lsh'@classmethoddef_default_parameter(cls,method):ifmethodin('inverted_index','inverted_index_euclid'):returnNoneelifmethodin('minhash'):return{'hash_num':128,}elifmethodin('lsh','euclid_lsh'):return{'hash_num':128,'threads':-1,}elifmethodin('nearest_neighbor_recommender'):return{'method':'euclid_lsh','parameter':{'threads':-1,# use number of logical CPU cores'hash_num':128,},}else:raiseRuntimeError('unknown method: {0}'.format(method))