public LogitCoef GetLogitCoefArgsByFile() { string lines = File.ReadAllText(@"d:\logit_coef.json"); LogitCoef logitCoef = new LogitCoef(); var dd = JsonConvert.DeserializeObject<LogitCoef>(lines); logitCoef.listLogitCoef = dd.listLogitCoef.ToList(); //linearCoef.ListCoef = dd.ListCoef.Where(w => w.coef_type == 1).ToList(); return logitCoef; }
public int GetLogisticRegression(DidiDBDetail detailData, DidiPerData fixData, LogitCoef LogitCoefData) { log.Info("GetLogisticRegression data :{0}", DateTime.Now); float t2 = LogitCoefData.listLogitCoef.Where(w => w.coef_name == "(Intercept):2").Select(s => s.coef).FirstOrDefault(); t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "click:2").Select(s => s.coef).FirstOrDefault() * fixData.click; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "roi:2").Select(s => s.coef).FirstOrDefault() * fixData.roi; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "imp_rank1:2").Select(s => s.coef).FirstOrDefault() * fixData.imp_rank1; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "pc_score:2").Select(s => s.coef).FirstOrDefault() * fixData.pc_score; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "ctr_ind:2").Select(s => s.coef).FirstOrDefault() * fixData.ctr_ind; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_ind:2").Select(s => s.coef).FirstOrDefault() * fixData.cpc_ind; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_limt_ind:2").Select(s => s.coef).FirstOrDefault() * fixData.d_limt_ind; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_spend_ind:2").Select(s => s.coef).FirstOrDefault() * fixData.d_spend_ind; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "price_limt_ind:2").Select(s => s.coef).FirstOrDefault() * fixData.price_limit_ind; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_mm:2").Select(s => s.coef).FirstOrDefault() * fixData.cpc_mm; t2 = t2 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_p:2").Select(s => s.coef).FirstOrDefault() * fixData.cpc_p; float t3 = LogitCoefData.listLogitCoef.Where(w => w.coef_name == "(Intercept):3").Select(s => s.coef).FirstOrDefault(); t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "click:3").Select(s => s.coef).FirstOrDefault() * fixData.click; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "roi:3").Select(s => s.coef).FirstOrDefault() * fixData.roi; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "imp_rank1:3").Select(s => s.coef).FirstOrDefault() * fixData.imp_rank1; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "pc_score:3").Select(s => s.coef).FirstOrDefault() * fixData.pc_score; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "ctr_ind:3").Select(s => s.coef).FirstOrDefault() * fixData.ctr_ind; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_ind:3").Select(s => s.coef).FirstOrDefault() * fixData.cpc_ind; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_limt_ind:3").Select(s => s.coef).FirstOrDefault() * fixData.d_limt_ind; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_spend_ind:3").Select(s => s.coef).FirstOrDefault() * fixData.d_spend_ind; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "price_limt_ind:3").Select(s => s.coef).FirstOrDefault() * fixData.price_limit_ind; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_mm:3").Select(s => s.coef).FirstOrDefault() * fixData.cpc_mm; t3 = t3 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_p:3").Select(s => s.coef).FirstOrDefault() * fixData.cpc_p; float t4 = LogitCoefData.listLogitCoef.Where(w => w.coef_name == "(Intercept):4").Select(s => s.coef).FirstOrDefault(); t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "click:4").Select(s => s.coef).FirstOrDefault() * fixData.click; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "roi:4").Select(s => s.coef).FirstOrDefault() * fixData.roi; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "imp_rank1:4").Select(s => s.coef).FirstOrDefault() * fixData.imp_rank1; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "pc_score:4").Select(s => s.coef).FirstOrDefault() * fixData.pc_score; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "ctr_ind:4").Select(s => s.coef).FirstOrDefault() * fixData.ctr_ind; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_ind:4").Select(s => s.coef).FirstOrDefault() * fixData.cpc_ind; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_limt_ind:4").Select(s => s.coef).FirstOrDefault() * fixData.d_limt_ind; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "d_spend_ind:4").Select(s => s.coef).FirstOrDefault() * fixData.d_spend_ind; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "price_limt_ind:4").Select(s => s.coef).FirstOrDefault() * fixData.price_limit_ind; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_mm:4").Select(s => s.coef).FirstOrDefault() * fixData.cpc_mm; t4 = t4 + LogitCoefData.listLogitCoef.Where(w => w.coef_name == "cpc_p:4").Select(s => s.coef).FirstOrDefault() * fixData.cpc_p; double prob2 = Math.Exp(t2) / (1 + Math.Exp(t2) + Math.Exp(t3) + Math.Exp(t4)); double prob3 = Math.Exp(t3) / (1 + Math.Exp(t2) + Math.Exp(t3) + Math.Exp(t4)); double prob4 = Math.Exp(t4) / (1 + Math.Exp(t2) + Math.Exp(t3) + Math.Exp(t4)); double prob1 = 1 - prob2 - prob3 - prob4; double[] maxProb = { prob1, prob2, prob3, prob4 }; var max = maxProb.Max(); var result = Array.IndexOf(maxProb, max); log.Info("GetLogisticRegression data end :{0}", DateTime.Now); return result + 1; }