def get_feat_importance(dtest,model): # 预测 predict = model.predict(dtest) # 处理结果 predict = pd.DataFrame(predict, columns=['prob']) result = pd.concat([test[['User_id', 'Coupon_id', 'Date_received']], predict], axis=1) train_data=xgb.DMatrix(offline_train,label=get_label) params={'max_width':3} bst=xgb.train(params,train_data,num_boost_round=1) for importance_type in('weight','gain','cover','total_gain','total_cover'): print('%s: ' % importance_type,bst.get_score(importance_type=importance_type)) return result def get_result(model,test):#线上测试集 dtest = xgb.DMatrix(test.drop(['User_id', 'Coupon_id', 'Date_received'], axis=1)) # 预测 predict = model.predict(dtest) # 处理结果 predict = pd.DataFrame(predict, columns=['pred']) result = pd.concat([test[['User_id', 'Coupon_id', 'Date_received']], predict], axis=1) result.to_csv('result/result.csv', index=False, header=None) print("results are saved.")改写代码,不改变功能
时间: 2023-12-31 15:04:33 浏览: 180
PyPI 官网下载 | sage_importance-0.0.3-py3-none-any.whl
def get_feat_importance(dtest,model):
# 预测
predict = model.predict(dtest)
# 处理结果
predict = pd.DataFrame(predict, columns=['prob'])
result = pd.concat([test[['User_id', 'Coupon_id', 'Date_received']], predict], axis=1)
train_data=xgb.DMatrix(offline_train,label=get_label)
params={'max_width':3}
bst=xgb.train(params,train_data,num_boost_round=1)
# 输出特征重要性
for importance_type in('weight','gain','cover','total_gain','total_cover'):
print('%s: ' % importance_type,bst.get_score(importance_type=importance_type))
return result
def get_result(model,test):
# 线上测试集
dtest = xgb.DMatrix(test.drop(['User_id', 'Coupon_id', 'Date_received'], axis=1))
# 预测
predict = model.predict(dtest)
# 处理结果
predict = pd.DataFrame(predict, columns=['pred'])
result = pd.concat([test[['User_id', 'Coupon_id', 'Date_received']], predict], axis=1)
result.to_csv('result/result.csv', index=False, header=None)
print("results are saved.")
return result
阅读全文