fly12357 / ctr_xlearn Goto Github PK
View Code? Open in Web Editor NEW使用python, Loads Xlearn产出的txt模型
使用python, Loads Xlearn产出的txt模型
您好,按照您给的方法,预测主要分成两部分,线性和非线性两块,上线后发现了一个问题,预测两百个条目,当压力上来时,较慢,如果超过100毫秒算超时的话,超时挺多的,我已将模型和预测的条目都缓存到本地了,想问问有没有,更好的办法,提升预测的速度,谢谢!(60个field, 8w向量,模型500w行)。
首先很荣幸能看到你的代码,
目前有问题想咨询您:
用你提供的预测方式,跟xlearn 自带的预测结果不同:
ffm_model.setTest("./single_predict_data") # 测试数据
ffm_model.predict("./model.out", "./output1.txt")
我用的是xlearn0.44, 甚至xlearn新开发的api也不行
string = "0,1:22166:1,2:22169:1,3:22175:1,4:22302:1,5:0:1,6:6:1,7:16:1,8:18:1,9:39:1,10:1062:1,11:1079:1,12:1089:1,13:1092:1,14:1094:1,15:1096:1,16:1098:1,17:1100:1,18:1102:1,19:1104:1,20:1107:1,21:1108:1,22:1110:1,23:1114:1,24:1564:1,25:20787:1,26:20804:1,27:20914:1,28:22161:1,29:181:1,30:20804:1,31:20993:1,32:1117:1,33:1062:1,34:1474:1,35:1095:1,36:1096:1,37:1104:1,38:1101:1,39:1080:1,29:181:1,30:20804:1,31:20993:1,32:1117:1,33:1062:1,34:1474:1,35:1095:1,36:1096:1,37:1104:1,38:1101:1,39:1080:1"
r = string.split(',')
X = [0]*22320
field_map = [0]*22320
for index, i in enumerate(r):
if index == 0:
continue
field_value = int(i.split(':')[0])
feature_index = int(i.split(':')[1])
feature_value = int(i.split(':')[2])
X[feature_index] = feature_value
field_map[feature_index] = field_value
X = np.array(X)
X = X.reshape((1, -1))
X = check_array(X, accept_sparse=['csr'])
test_set = xl.DMatrix(X, None, field_map=field_map)
fm_model = xl.create_ffm() # Use factorization machine
fm_model.setTest(test_set)
fm_model.disableNorm()
pred = fm_model.predict('./model.out')
print(pred)
想问您遇到过此问题吗。是否xlearn有了一些额外的逻辑?
非常感谢您的回答。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.