Skip to content

Commit

Permalink
1.add neighborhood model
Browse files Browse the repository at this point in the history
2.the function in neighborhood model can handle different situation
  • Loading branch information
Ykid committed Aug 2, 2013
1 parent 17a8daa commit 41c7a18
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 262 deletions.
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#['rmt','FM','RelatedMovieTag',['2']]

#['basicSVD','SVD','Basic',[]]
['ImplicitFeedbackSVD','SVD','ImplicitFeedback',[]]
#['ImplicitFeedbackSVD','SVD','ImplicitFeedback',[]]
['NeighborhoodMovieTag', 'SVD' , 'Neighborhood' , ['MovieTag']]
]

# Defining models:
Expand Down
46 changes: 40 additions & 6 deletions utils/SVDModel.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from Model import Model
import ImplicitFeedbackFunctions as IFF #IFF for implicitFeedbackFunctions
import neighborhoodFunctions as NF
class SVDModel(Model):

### Construct ###

def __init__(self,configModel,utils,config,strTrial):
#This function is to set up different parameters only.
Model.__init__(self,configModel,utils,strTrial) #come from model!it's another class object.
#This function is to set up different parameters.
Model.__init__(self,configModel,utils,strTrial)
self.configPath = utils.MODEL_CONFIG_PATH + self.tag + \
'_t' + strTrial
self.userHistoryReindexPath= utils.MODEL_TMP_PATH + self.tag + \
'_userHistoryReindex' + '_t' + strTrial


### Baidu Specific ###
### Implicit Feedback Files ###
self.userHistoryReindexPath= utils.MODEL_TMP_PATH + self.tag + \
'_userHistoryReindex' + '_t' + strTrial
#The following 3 files are implicit feature files
self.ImfeatTrain = utils.MODEL_FEATURED_PATH + self.tag + \
'_Imtrain' + '_t' + strTrial
Expand All @@ -32,6 +33,16 @@ def __init__(self,configModel,utils,config,strTrial):
### End Implicit Feature Files ###

self.regularizationFeedback = config.SVD_REGULARIZATION_FEEDBACK


### Neighborhood Model Files###
if self.misc[0] == "MovieTag":
self.TagFilePath = self.movieTagPath
self.TagFileReindexPath = utils.MODEL_TMP_PATH + self.tag + \
'_' + self.misc[0] + '_t' + strTrial
self.ShareTagPath = utils.MODEL_TMP_PATH + self.tag + \
'_share_' + self.misc[0] + '_t' + strTrial
### End Neighborhood Model Files###
### End Baidu Specific ###

self.numIter = config.SVD_NUM_ITER
Expand Down Expand Up @@ -180,7 +191,8 @@ def reIndex(self):

def dataConvert(self):
import os
if self.featureSet == 'Basic':
if self.featureSet == 'Basic' or \
self.featureSet == 'Neighborhood':
os.system(self.SVDBufferPath + ' ' +
self.featTrain + ' ' + self.runTrain)
os.system(self.SVDBufferPath + ' ' +
Expand Down Expand Up @@ -238,6 +250,8 @@ def setupFeatures(self):
### Baidu Specific Features ###
if self.featureSet == 'ImplicitFeedback':
self.setupImplicitFeatures()
if self.featureSet == 'Neighborhood':
self.NeighborhoodSetup()
### End Baidu Specific Features ###

def basicConvert(self,fin,fout):
Expand Down Expand Up @@ -364,3 +378,23 @@ def setupImplicitFeatures(self):
self.formatType = 1
self.numUserFeedback = len(ItemDic)




def NeighborhoodSetup(self):
#second
NSnoUser,NSnoMovie,NSAvg = NF.reIndex(self.bootTrain, self.TagFilePath, self.bootTest, self.bootCV, self.tmpTrain, self.TagFileReindexPath, self.tmpTest, self.tmpCV)

#third
NF.share(self.TagFileReindexPath,self.ShareTagPath)

#fourth
NumGlobal = NF.neighborhood(self.tmpTrain, self.ShareTagPath, self.tmpTest, self.featTrain, self.featTest)
NF.neighborhood(self.tmpCV, self.ShareTagPath, self.tmpTest, self.featCV, self.featTest)

# set the parameters.
self.numUser = NSnoUser
self.numMovie = NSnoMovie
self.numGlobal = NumGlobal + 1
self.avg = NSAvg

255 changes: 0 additions & 255 deletions utils/neighborhood Functions.py

This file was deleted.

Loading

0 comments on commit 41c7a18

Please sign in to comment.