在 2016年10月10日星期一 UTC+8上午4:12:19,Alexey Renyov写道:
> Hi!
> Check that your features indices starts from 0. That was my problem.
>
>
> On Sunday, October 9, 2016 at 6:34:40 AM UTC+3,
hzzen...@gmail.com wrote:I have same problem with you, is it my code has a bug, how do you solve?
Hi!
I make my features indices starts from 0 instead from 1, now the number of feature and matrix V is right . Thanks a lot
I use model to write my own predictor, I find my own prob is not same as the libfm's prob,my code is:
def main():
nfactor = int(os.environ.get('nfactor'))
num_feature = int(os.environ.get('num_feature'))
try:
weight_name = os.environ.get('weight_name')
except:
weight_name = 'weight'
weight = open(weight_name)
weights = weight.readlines()
if(len(weights) != (num_feature + num_feature * nfactor + 1)):
print "weights size and num_feature size is wrong!"
sys.exit()
for line in sys.stdin:
end =""
data = line.strip().split("\t")
clk = data[0]
pv = data[1]
sum_wx = 0.0
sum_wx = float(weights[len(weights)-1].split("\t")[1])
prop = 0.0
# single feature
for i in range(2,len(data)):
featureid = int(data[i].split(":")[0])
value = float(data[i].split(":")[1]) if len(data[i].split(":"))>1 else 1.0
weight_value = float(weights[featureid].split("\t")[1])
sum_wx += weight_value * value
# pair wised interation
for i in range(nfactor):
sum1 = 0.0
sum2 = 0.0
for j in range(2,len(data)):
featureid = int(data[j].split(":")[0])
value = float(data[j].split(":")[1]) if len(data[j].split(":"))>1 else 1.0
n = num_feature + featureid * nfactor + i
weight_value = float(weights[n].split("\t")[1])
sum1 += (weight_value * value)
sum2 += (weight_value * value) * (weight_value * value)
sum_wx += 0.5 * (sum1 * sum1 - sum2)
prop = 1.0/(1.0+math.exp(-sum_wx))
prop = round(prop, 8)
#now print the value we want
print"%s\t%s"%(prop , clk )
is it some wrong? If you can, give me a copy of your code about predict to me
thanks a lot ,my email is :
zak...@163.com