diff --git a/src/main/java/com/sztzjy/marketing/config/Constant.java b/src/main/java/com/sztzjy/marketing/config/Constant.java index 90c1231..d8d7598 100644 --- a/src/main/java/com/sztzjy/marketing/config/Constant.java +++ b/src/main/java/com/sztzjy/marketing/config/Constant.java @@ -25,6 +25,10 @@ public class Constant { public static final String INPUT_TYPE_TEACHER= "0"; public static final String INPUT_TYPE_BUILT_IN= "1"; + public static final String LINEAR_REGRESSION="线性回归"; + + public static final String LOGISTIC_REGRESSION="逻辑回归"; + diff --git a/src/main/java/com/sztzjy/marketing/controller/stu/StuDigitalMarketingModelController.java b/src/main/java/com/sztzjy/marketing/controller/stu/StuDigitalMarketingModelController.java index 4b1555a..eac48c4 100644 --- a/src/main/java/com/sztzjy/marketing/controller/stu/StuDigitalMarketingModelController.java +++ b/src/main/java/com/sztzjy/marketing/controller/stu/StuDigitalMarketingModelController.java @@ -1,6 +1,8 @@ package com.sztzjy.marketing.controller.stu; +import cn.hutool.core.util.IdUtil; import com.sztzjy.marketing.annotation.AnonymousAccess; +import com.sztzjy.marketing.config.Constant; import com.sztzjy.marketing.config.exception.handler.DigitalEconomyxception; import com.sztzjy.marketing.entity.StuSpendingLevel; import com.sztzjy.marketing.entity.StuTrainingOperateStepExample; @@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.math.BigDecimal; import java.text.DecimalFormat; @@ -194,7 +197,7 @@ public class StuDigitalMarketingModelController { Apriori.iteration(Apriori.C,Apriori.L,support); //根据最终的关联集,根据公式计算出各个关联事件 - List connection = Apriori.connection(confidence); + List connection = Apriori.connection(confidence); return new ResultEntity(HttpStatus.OK,"成功",connection); @@ -212,14 +215,11 @@ public class StuDigitalMarketingModelController { LinearRegression regression=new LinearRegression(); regression.fit(x,y); - double[] slopes = regression.getSlopes(); RAnalysisDTO rAnalysisDTO=new RAnalysisDTO(); rAnalysisDTO.setIntercept(regression.getIntercept()); - for (int i = 0; i < slopes.length; i++) { - rAnalysisDTO.setSlopes(slopes[i]); - } - + rAnalysisDTO.setSlopes(regression.getSlopes()); + rAnalysisDTO.setType("线性回归"); return new ResultEntity(HttpStatus.OK,"成功",rAnalysisDTO); } @@ -240,22 +240,51 @@ public class StuDigitalMarketingModelController { RAnalysisDTO rAnalysisDTO=new RAnalysisDTO(); rAnalysisDTO.setIntercept(Double.parseDouble(df.format(model.getIntercept()))); - rAnalysisDTO.setSlopes(Double.parseDouble(df.format(model.getCoefficient()))); + rAnalysisDTO.setSlope(Double.parseDouble(df.format(model.getCoefficient()))); + rAnalysisDTO.setType("逻辑回归"); return new ResultEntity(HttpStatus.OK,"成功",rAnalysisDTO); } + @ApiOperation("线性回归/逻辑回归--预测") + @PostMapping("/prediction") + @AnonymousAccess + public ResultEntity prediction(@RequestBody LogisticPredictDTO logisticPredictDTO) { + + DecimalFormat df = new DecimalFormat("#.0"); + if(logisticPredictDTO.getType().equals(Constant.LINEAR_REGRESSION)){ + // 创建线性回归模型 + LinearRegression regression=new LinearRegression(); + double predict = regression.predict(logisticPredictDTO.getRaX(), logisticPredictDTO.getIntercept(), logisticPredictDTO.getSlopes()); + return new ResultEntity(HttpStatus.OK,"成功",df.format(predict)); + + }else { + // 创建一个逻辑回归模型实例,0.1学习率 + LogisticRegression model = new LogisticRegression(0.1); + double predict = model.predict(logisticPredictDTO.getLX(), logisticPredictDTO.getSlope(), logisticPredictDTO.getIntercept());//预测 + return new ResultEntity(HttpStatus.OK,"成功",df.format(predict)); + } + + } + + + @ApiOperation("情感分析/文本挖掘") @PostMapping("/emotionalAnalysis") @AnonymousAccess - public ResultEntity emotionalAnalysis(@ApiParam("用户ID") String userId, - @ApiParam("模型类别") String modelType, - @ApiParam("输入内容") String content) throws IOException { - - return modelService.emotionalAnalysis(userId,modelType,content); + public ResultEntity emotionalAnalysis(@RequestBody EmotionalAnalysisDto emotionalAnalysisDto) throws IOException { + String id = emotionalAnalysisDto.getId(); + String modelType = emotionalAnalysisDto.getModelType(); + String content = emotionalAnalysisDto.getContent(); + String userId = emotionalAnalysisDto.getUserId(); + return modelService.emotionalAnalysis(userId,modelType,content,id); } + + + + @ApiOperation("批量导入") @PostMapping("/batchImport") @AnonymousAccess diff --git a/src/main/java/com/sztzjy/marketing/controller/stu/StuOnAnalysisController.java b/src/main/java/com/sztzjy/marketing/controller/stu/StuOnAnalysisController.java new file mode 100644 index 0000000..3313b16 --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/controller/stu/StuOnAnalysisController.java @@ -0,0 +1,229 @@ +package com.sztzjy.marketing.controller.stu; + +import cn.hutool.core.util.IdUtil; +import com.sztzjy.marketing.annotation.AnonymousAccess; +import com.sztzjy.marketing.config.Constant; +import com.sztzjy.marketing.entity.dto.*; +import com.sztzjy.marketing.util.excel.FilePortUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.checkerframework.checker.units.qual.C; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author tz + * @date 2024/8/19 10:14 + */ +@Api(tags = "分析结果下载") +@RequestMapping("api/analysis") +@RestController +public class StuOnAnalysisController { + + @ApiOperation("描述性统计表格下载") + @PostMapping("/dSExport") + @AnonymousAccess + public void dSExport(HttpServletResponse response, @RequestBody List dtoList) { + //导出的表名 + String title = IdUtil.simpleUUID(); + + +// List list=new ArrayList<>(); +// list.add(""); //表头第一个元素为空 +// for (DescriptiveStatisticsDTO dto: dtoList) { +// list.add(dto.getStatistic()); +// } +// //表中第一行表头字段 +// String[] headers=list.toArray(new String[list.size()]); // 使用 list.toArray() 转换为 String数组 + + String[] headers={"", "平均数", "中位数", "众数", "标准差", "方差", "标准误差", + "峰度", "偏度", "最大值", "最小值", "求和", "观测数"}; + + + List descriptiveStatistics=new ArrayList<>(); + //实际数据结果集 + for (DescriptiveStatisticsDTO dto: dtoList) { + descriptiveStatistics.add(dto.getStatistics()); + } + + + + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + List listColumn = Arrays.asList("field", "average", "median", "mode", "standardDeviation", "variance", "standardError", + "kurtosis", "skewness", "max", "min", "summation", "observations"); + try { + FilePortUtil.exportExcel(response, title, headers, descriptiveStatistics, listColumn); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @ApiOperation("聚类分析表格下载") + @PostMapping("/cAMExport") + @AnonymousAccess + public void cAMExport(HttpServletResponse response,@RequestBody List> data ) { +// Workbook workbook = new XSSFWorkbook(); +// Sheet sheet = workbook.createSheet("Sheet1"); +// +// for (int rowIndex = 0; rowIndex < data.size(); ++rowIndex) { +// Row row = sheet.createRow(rowIndex); +// for (int colIndex = 0; colIndex < data.get(rowIndex).size(); ++colIndex) { +// Object value = data.get(rowIndex).get(colIndex); +// if (value == null) { +// // 使用空字符串或其他显示文本代替 null 值 +// Cell cell = row.createCell(colIndex); +// cell.setCellValue(""); +// } else { +// Cell cell = row.createCell(colIndex); +// cell.setCellValue(value.toString()); +// } +// } +// } +// +// try (FileOutputStream outputStream = new FileOutputStream("output.xlsx")) { +// workbook.write(outputStream); +// } catch (IOException e) { +// org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(cAMExport.class); +// logger.error("An error occurred while writing the Excel file.", e); +// } + //导出的表名 + String title = IdUtil.simpleUUID(); + + + //取到表头 + List list=new ArrayList<>(); + for (int i = 0; i < data.size(); i++) { + for (int j = 0; j < data.get(i).size(); j++) { + list.add("field"+j); + } + + } + + //表中第一行表头字段 + String[] headers=list.toArray(new String[list.size()]); // 使用 list.toArray() 转换为 String数组 + + + + + + + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + List listColumn=new ArrayList<>(); + + //实际数据结果集 + + + + + + + try { + FilePortUtil.exportExcel(response, title, headers, data, listColumn); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @ApiOperation("关联规则挖掘表格下载") + @PostMapping("/aRMExport") + @AnonymousAccess + public void aRMExport(HttpServletResponse response, @RequestBody List dtoList) { + //导出的表名 + String title = IdUtil.simpleUUID(); + + //表中第一行表头字段 + String[] headers={"关联", "被关联", "置信度"}; + + + + //实际数据结果集 + List list=new ArrayList<>(); + + for (int i = 0; i < dtoList.size(); i++) { + + // 使用String.join()方法将元素以逗号和空格分隔 + String correlation = String.join(", ", dtoList.get(i).getCorrelation()); + + String associated= String.join(", ", dtoList.get(i).getAssociated()); + + + AssociationRules associationRules=new AssociationRules(); + + associationRules.setCorrelation(correlation); + associationRules.setAssociated(associated); + associationRules.setConfidenceLevel(dtoList.get(i).getConfidenceLevel()); + + list.add(associationRules); + } + + + + + + + + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + List listColumn = Arrays.asList("correlation", "associated", "confidenceLevel"); + try { + FilePortUtil.exportExcel(response, title, headers, list, listColumn); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @ApiOperation("回归分析表格下载") + @PostMapping("/rAMExport") + @AnonymousAccess + public void rAMExport(HttpServletResponse response, @RequestBody RAnalysisExportDTO rAnalysisExportDTO) { + //导出的表名 + String title = IdUtil.simpleUUID(); + + List list=new ArrayList<>(); + List listColumn=new ArrayList<>(); + list.add("回归系数值"); + + + if(rAnalysisExportDTO.getType().equals(Constant.LINEAR_REGRESSION)){ + + list.add("线性回归常数项值"); + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + listColumn = Arrays.asList("intercept", "slopes", "type","prediction"); + + + }else { + list.add("逻辑回归常数项值"); + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + listColumn = Arrays.asList("intercept", "slope", "type","prediction"); + } + list.add("回归类型"); + list.add("预测值"); + + //表中第一行表头字段 + String[] headers=list.toArray(new String[list.size()]); // 使用 list.toArray() 转换为 String数组 + + + //实际数据结果集 + List rAnalysisExportDTOS=new ArrayList<>(); + rAnalysisExportDTOS.add(rAnalysisExportDTO); + + + try { + FilePortUtil.exportExcel(response, title, headers, rAnalysisExportDTOS, listColumn); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/sztzjy/marketing/entity/StuUserAttribute.java b/src/main/java/com/sztzjy/marketing/entity/StuUserAttribute.java index af71259..22bf890 100644 --- a/src/main/java/com/sztzjy/marketing/entity/StuUserAttribute.java +++ b/src/main/java/com/sztzjy/marketing/entity/StuUserAttribute.java @@ -2,7 +2,6 @@ package com.sztzjy.marketing.entity; import java.util.Date; -import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** * 用户属性表 @@ -10,7 +9,6 @@ import io.swagger.annotations.ApiModelProperty; * @author whb * stu_user_attribute */ -@ApiModel("用户属性表") public class StuUserAttribute { @ApiModelProperty("id") private Integer id; @@ -57,6 +55,9 @@ public class StuUserAttribute { @ApiModelProperty("所在地") private String location; + @ApiModelProperty("文本") + private String text; + public Integer getId() { return id; } @@ -176,4 +177,12 @@ public class StuUserAttribute { public void setLocation(String location) { this.location = location == null ? null : location.trim(); } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text == null ? null : text.trim(); + } } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/entity/StuUserBehavior.java b/src/main/java/com/sztzjy/marketing/entity/StuUserBehavior.java index 2c0c926..4db0f45 100644 --- a/src/main/java/com/sztzjy/marketing/entity/StuUserBehavior.java +++ b/src/main/java/com/sztzjy/marketing/entity/StuUserBehavior.java @@ -47,7 +47,7 @@ public class StuUserBehavior { private String goodsSubcategories; @ApiModelProperty("用户行为类型") - private String userBehaviorType; + private Integer userBehaviorType; @ApiModelProperty("行为日期") private Date behaviorDate; @@ -58,6 +58,9 @@ public class StuUserBehavior { @ApiModelProperty("更新时间") private Date updateTime; + @ApiModelProperty("文本") + private String text; + public Integer getId() { return id; } @@ -154,12 +157,12 @@ public class StuUserBehavior { this.goodsSubcategories = goodsSubcategories == null ? null : goodsSubcategories.trim(); } - public String getUserBehaviorType() { + public Integer getUserBehaviorType() { return userBehaviorType; } - public void setUserBehaviorType(String userBehaviorType) { - this.userBehaviorType = userBehaviorType == null ? null : userBehaviorType.trim(); + public void setUserBehaviorType(Integer userBehaviorType) { + this.userBehaviorType = userBehaviorType; } public Date getBehaviorDate() { @@ -185,4 +188,12 @@ public class StuUserBehavior { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text == null ? null : text.trim(); + } } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/entity/StuUserBehaviorExample.java b/src/main/java/com/sztzjy/marketing/entity/StuUserBehaviorExample.java index 19e167a..c907446 100644 --- a/src/main/java/com/sztzjy/marketing/entity/StuUserBehaviorExample.java +++ b/src/main/java/com/sztzjy/marketing/entity/StuUserBehaviorExample.java @@ -945,62 +945,52 @@ public class StuUserBehaviorExample { return (Criteria) this; } - public Criteria andUserBehaviorTypeEqualTo(String value) { + public Criteria andUserBehaviorTypeEqualTo(Integer value) { addCriterion("user_behavior_type =", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeNotEqualTo(String value) { + public Criteria andUserBehaviorTypeNotEqualTo(Integer value) { addCriterion("user_behavior_type <>", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeGreaterThan(String value) { + public Criteria andUserBehaviorTypeGreaterThan(Integer value) { addCriterion("user_behavior_type >", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeGreaterThanOrEqualTo(String value) { + public Criteria andUserBehaviorTypeGreaterThanOrEqualTo(Integer value) { addCriterion("user_behavior_type >=", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeLessThan(String value) { + public Criteria andUserBehaviorTypeLessThan(Integer value) { addCriterion("user_behavior_type <", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeLessThanOrEqualTo(String value) { + public Criteria andUserBehaviorTypeLessThanOrEqualTo(Integer value) { addCriterion("user_behavior_type <=", value, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeLike(String value) { - addCriterion("user_behavior_type like", value, "userBehaviorType"); - return (Criteria) this; - } - - public Criteria andUserBehaviorTypeNotLike(String value) { - addCriterion("user_behavior_type not like", value, "userBehaviorType"); - return (Criteria) this; - } - - public Criteria andUserBehaviorTypeIn(List values) { + public Criteria andUserBehaviorTypeIn(List values) { addCriterion("user_behavior_type in", values, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeNotIn(List values) { + public Criteria andUserBehaviorTypeNotIn(List values) { addCriterion("user_behavior_type not in", values, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeBetween(String value1, String value2) { + public Criteria andUserBehaviorTypeBetween(Integer value1, Integer value2) { addCriterion("user_behavior_type between", value1, value2, "userBehaviorType"); return (Criteria) this; } - public Criteria andUserBehaviorTypeNotBetween(String value1, String value2) { + public Criteria andUserBehaviorTypeNotBetween(Integer value1, Integer value2) { addCriterion("user_behavior_type not between", value1, value2, "userBehaviorType"); return (Criteria) this; } diff --git a/src/main/java/com/sztzjy/marketing/entity/StuUserConsumptionAbility.java b/src/main/java/com/sztzjy/marketing/entity/StuUserConsumptionAbility.java index c2e1f38..9888868 100644 --- a/src/main/java/com/sztzjy/marketing/entity/StuUserConsumptionAbility.java +++ b/src/main/java/com/sztzjy/marketing/entity/StuUserConsumptionAbility.java @@ -3,7 +3,6 @@ package com.sztzjy.marketing.entity; import java.math.BigDecimal; import java.util.Date; -import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** * 用户消费能力表 @@ -11,8 +10,6 @@ import io.swagger.annotations.ApiModelProperty; * @author whb * stu_user_consumption_ability */ - -@ApiModel("用户消费能力表") public class StuUserConsumptionAbility { @ApiModelProperty("id") private Integer id; @@ -68,6 +65,9 @@ public class StuUserConsumptionAbility { @ApiModelProperty("更新时间") private Date updateTime; + @ApiModelProperty("文本") + private String text; + public Integer getId() { return id; } @@ -211,4 +211,12 @@ public class StuUserConsumptionAbility { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text == null ? null : text.trim(); + } } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/entity/StuUserLoginActive.java b/src/main/java/com/sztzjy/marketing/entity/StuUserLoginActive.java index b804953..728c3d5 100644 --- a/src/main/java/com/sztzjy/marketing/entity/StuUserLoginActive.java +++ b/src/main/java/com/sztzjy/marketing/entity/StuUserLoginActive.java @@ -55,6 +55,9 @@ public class StuUserLoginActive { @ApiModelProperty("更新时间") private Date updateTime; + @ApiModelProperty("文本") + private String text; + public Integer getId() { return id; } @@ -174,4 +177,12 @@ public class StuUserLoginActive { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text == null ? null : text.trim(); + } } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRules.java b/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRules.java new file mode 100644 index 0000000..eb075bd --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRules.java @@ -0,0 +1,22 @@ +package com.sztzjy.marketing.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author tz + * @date 2024/8/19 14:38 + */ +@Data +public class AssociationRules { + @ApiModelProperty("关联") + private String correlation; + + @ApiModelProperty("被关联") + private String associated; + + @ApiModelProperty("置信度") + private double confidenceLevel; +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRulesDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRulesDTO.java index 36f9dd6..c210207 100644 --- a/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRulesDTO.java +++ b/src/main/java/com/sztzjy/marketing/entity/dto/AssociationRulesDTO.java @@ -19,4 +19,7 @@ public class AssociationRulesDTO { @ApiModelProperty("置信度") private double confidenceLevel; + + @ApiModelProperty("规则") + private String rule; } diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/DSExportDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/DSExportDTO.java new file mode 100644 index 0000000..41e7460 --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/DSExportDTO.java @@ -0,0 +1,19 @@ +package com.sztzjy.marketing.entity.dto; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; + +/** + * @author tz + * @date 2024/8/19 10:33 + */ +@Data +@Api(tags = "描述性统计下载表格数据") +public class DSExportDTO extends DescriptiveStatistics{ + + @ApiModelProperty("字段名") + private String field; + +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatistics.java b/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatistics.java index d0379ae..4c576f1 100644 --- a/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatistics.java +++ b/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatistics.java @@ -46,4 +46,7 @@ public class DescriptiveStatistics { @ApiModelProperty("观测数") private Integer observations; + + @ApiModelProperty("字段名") + private String field; } diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatisticsDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatisticsDTO.java index d51e802..8c1821c 100644 --- a/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatisticsDTO.java +++ b/src/main/java/com/sztzjy/marketing/entity/dto/DescriptiveStatisticsDTO.java @@ -1,5 +1,6 @@ package com.sztzjy.marketing.entity.dto; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -11,4 +12,5 @@ public class DescriptiveStatisticsDTO { private String field; private DescriptiveStatistics statistics; + } diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/EmotionalAnalysisDto.java b/src/main/java/com/sztzjy/marketing/entity/dto/EmotionalAnalysisDto.java new file mode 100644 index 0000000..31ad455 --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/EmotionalAnalysisDto.java @@ -0,0 +1,22 @@ +package com.sztzjy.marketing.entity.dto; + +import io.swagger.annotations.ApiParam; +import lombok.Data; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.persistence.Column; +import javax.xml.bind.annotation.XmlElement; + +/** + * @author tz + * @date 2024/8/19 16:09 + */ +@Data +public class EmotionalAnalysisDto { + + private String userId; + private String modelType; + private String content; + @XmlElement(name = "optionalField", required = false) + private String id; +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/LogisticPredictDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/LogisticPredictDTO.java new file mode 100644 index 0000000..68e920c --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/LogisticPredictDTO.java @@ -0,0 +1,18 @@ +package com.sztzjy.marketing.entity.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.ujmp.core.util.R; + +/** + * @author tz + * @date 2024/8/19 9:38 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class LogisticPredictDTO extends RAnalysisDTO { + private double[] raX; + + private double lX; + +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisDTO.java index d2cae68..b491263 100644 --- a/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisDTO.java +++ b/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisDTO.java @@ -1,5 +1,6 @@ package com.sztzjy.marketing.entity.dto; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -8,6 +9,12 @@ import lombok.Data; */ @Data public class RAnalysisDTO { + @ApiModelProperty("回归系数值") private double intercept; - private double slopes; + @ApiModelProperty("线性回归常数项值") + private double[] slopes; + @ApiModelProperty("逻辑回归常数项值") + private double slope; + @ApiModelProperty("线性回归/逻辑回归") + private String type; } diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisExportDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisExportDTO.java new file mode 100644 index 0000000..83aca88 --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/RAnalysisExportDTO.java @@ -0,0 +1,16 @@ +package com.sztzjy.marketing.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author tz + * @date 2024/8/19 14:55 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class RAnalysisExportDTO extends RAnalysisDTO{ + @ApiModelProperty("预测值") + private double prediction; +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/cAMExport.java b/src/main/java/com/sztzjy/marketing/entity/dto/cAMExport.java new file mode 100644 index 0000000..e605cd8 --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/cAMExport.java @@ -0,0 +1,25 @@ +package com.sztzjy.marketing.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author tz + * @date 2024/8/19 11:38 + */ +@Data +public class cAMExport { + private double fieldOne; + private double fieldTow; + private double fieldThree; + private double fieldFour; + private double fieldFive; + private double fieldSix; + private double fieldSeven; + private double fieldEight; + private double fieldNine; + private double fieldTen; + + private String type; +} diff --git a/src/main/java/com/sztzjy/marketing/entity/dto/cAMExportDTO.java b/src/main/java/com/sztzjy/marketing/entity/dto/cAMExportDTO.java new file mode 100644 index 0000000..60dec2f --- /dev/null +++ b/src/main/java/com/sztzjy/marketing/entity/dto/cAMExportDTO.java @@ -0,0 +1,17 @@ +package com.sztzjy.marketing.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author tz + * @date 2024/8/19 11:12 + */ +@Data +public class cAMExportDTO { + private String field; + + private List cAMExports; + +} diff --git a/src/main/java/com/sztzjy/marketing/mapper/StuUserAttributeMapper.java b/src/main/java/com/sztzjy/marketing/mapper/StuUserAttributeMapper.java index 07f298e..1f30254 100644 --- a/src/main/java/com/sztzjy/marketing/mapper/StuUserAttributeMapper.java +++ b/src/main/java/com/sztzjy/marketing/mapper/StuUserAttributeMapper.java @@ -3,10 +3,10 @@ package com.sztzjy.marketing.mapper; import com.sztzjy.marketing.entity.StuUserAttribute; import com.sztzjy.marketing.entity.StuUserAttributeExample; import java.util.List; -import java.util.Map; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; - +@Mapper public interface StuUserAttributeMapper { long countByExample(StuUserAttributeExample example); @@ -18,17 +18,21 @@ public interface StuUserAttributeMapper { int insertSelective(StuUserAttribute record); + List selectByExampleWithBLOBs(StuUserAttributeExample example); + List selectByExample(StuUserAttributeExample example); StuUserAttribute selectByPrimaryKey(Integer id); int updateByExampleSelective(@Param("record") StuUserAttribute record, @Param("example") StuUserAttributeExample example); + int updateByExampleWithBLOBs(@Param("record") StuUserAttribute record, @Param("example") StuUserAttributeExample example); + int updateByExample(@Param("record") StuUserAttribute record, @Param("example") StuUserAttributeExample example); int updateByPrimaryKeySelective(StuUserAttribute record); - int updateByPrimaryKey(StuUserAttribute record); + int updateByPrimaryKeyWithBLOBs(StuUserAttribute record); - List> selectByFields(List fieldList, String table); + int updateByPrimaryKey(StuUserAttribute record); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/mapper/StuUserBehaviorMapper.java b/src/main/java/com/sztzjy/marketing/mapper/StuUserBehaviorMapper.java index 9b908ac..c4bf326 100644 --- a/src/main/java/com/sztzjy/marketing/mapper/StuUserBehaviorMapper.java +++ b/src/main/java/com/sztzjy/marketing/mapper/StuUserBehaviorMapper.java @@ -3,8 +3,10 @@ package com.sztzjy.marketing.mapper; import com.sztzjy.marketing.entity.StuUserBehavior; import com.sztzjy.marketing.entity.StuUserBehaviorExample; import java.util.List; -import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +@Mapper public interface StuUserBehaviorMapper { long countByExample(StuUserBehaviorExample example); @@ -16,15 +18,21 @@ public interface StuUserBehaviorMapper { int insertSelective(StuUserBehavior record); + List selectByExampleWithBLOBs(StuUserBehaviorExample example); + List selectByExample(StuUserBehaviorExample example); StuUserBehavior selectByPrimaryKey(Integer id); int updateByExampleSelective(@Param("record") StuUserBehavior record, @Param("example") StuUserBehaviorExample example); + int updateByExampleWithBLOBs(@Param("record") StuUserBehavior record, @Param("example") StuUserBehaviorExample example); + int updateByExample(@Param("record") StuUserBehavior record, @Param("example") StuUserBehaviorExample example); int updateByPrimaryKeySelective(StuUserBehavior record); + int updateByPrimaryKeyWithBLOBs(StuUserBehavior record); + int updateByPrimaryKey(StuUserBehavior record); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/mapper/StuUserConsumptionAbilityMapper.java b/src/main/java/com/sztzjy/marketing/mapper/StuUserConsumptionAbilityMapper.java index 9b54c38..638c565 100644 --- a/src/main/java/com/sztzjy/marketing/mapper/StuUserConsumptionAbilityMapper.java +++ b/src/main/java/com/sztzjy/marketing/mapper/StuUserConsumptionAbilityMapper.java @@ -3,8 +3,10 @@ package com.sztzjy.marketing.mapper; import com.sztzjy.marketing.entity.StuUserConsumptionAbility; import com.sztzjy.marketing.entity.StuUserConsumptionAbilityExample; import java.util.List; -import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +@Mapper public interface StuUserConsumptionAbilityMapper { long countByExample(StuUserConsumptionAbilityExample example); @@ -16,17 +18,21 @@ public interface StuUserConsumptionAbilityMapper { int insertSelective(StuUserConsumptionAbility record); + List selectByExampleWithBLOBs(StuUserConsumptionAbilityExample example); + List selectByExample(StuUserConsumptionAbilityExample example); StuUserConsumptionAbility selectByPrimaryKey(Integer id); int updateByExampleSelective(@Param("record") StuUserConsumptionAbility record, @Param("example") StuUserConsumptionAbilityExample example); + int updateByExampleWithBLOBs(@Param("record") StuUserConsumptionAbility record, @Param("example") StuUserConsumptionAbilityExample example); + int updateByExample(@Param("record") StuUserConsumptionAbility record, @Param("example") StuUserConsumptionAbilityExample example); int updateByPrimaryKeySelective(StuUserConsumptionAbility record); - int updateByPrimaryKey(StuUserConsumptionAbility record); + int updateByPrimaryKeyWithBLOBs(StuUserConsumptionAbility record); - List selectByFields(List fieldList, String table); + int updateByPrimaryKey(StuUserConsumptionAbility record); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/mapper/StuUserLoginActiveMapper.java b/src/main/java/com/sztzjy/marketing/mapper/StuUserLoginActiveMapper.java index 76b0ecc..3413ebc 100644 --- a/src/main/java/com/sztzjy/marketing/mapper/StuUserLoginActiveMapper.java +++ b/src/main/java/com/sztzjy/marketing/mapper/StuUserLoginActiveMapper.java @@ -3,8 +3,10 @@ package com.sztzjy.marketing.mapper; import com.sztzjy.marketing.entity.StuUserLoginActive; import com.sztzjy.marketing.entity.StuUserLoginActiveExample; import java.util.List; -import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +@Mapper public interface StuUserLoginActiveMapper { long countByExample(StuUserLoginActiveExample example); @@ -16,15 +18,21 @@ public interface StuUserLoginActiveMapper { int insertSelective(StuUserLoginActive record); + List selectByExampleWithBLOBs(StuUserLoginActiveExample example); + List selectByExample(StuUserLoginActiveExample example); StuUserLoginActive selectByPrimaryKey(Integer id); int updateByExampleSelective(@Param("record") StuUserLoginActive record, @Param("example") StuUserLoginActiveExample example); + int updateByExampleWithBLOBs(@Param("record") StuUserLoginActive record, @Param("example") StuUserLoginActiveExample example); + int updateByExample(@Param("record") StuUserLoginActive record, @Param("example") StuUserLoginActiveExample example); int updateByPrimaryKeySelective(StuUserLoginActive record); + int updateByPrimaryKeyWithBLOBs(StuUserLoginActive record); + int updateByPrimaryKey(StuUserLoginActive record); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/service/StuDigitalMarketingModelService.java b/src/main/java/com/sztzjy/marketing/service/StuDigitalMarketingModelService.java index 6b286c3..460f831 100644 --- a/src/main/java/com/sztzjy/marketing/service/StuDigitalMarketingModelService.java +++ b/src/main/java/com/sztzjy/marketing/service/StuDigitalMarketingModelService.java @@ -15,7 +15,7 @@ import java.util.Map; public interface StuDigitalMarketingModelService { List dropdownBox(String userId); - ResultEntity emotionalAnalysis(String userId, String modelType, String content) throws IOException; + ResultEntity emotionalAnalysis(String userId, String modelType, String content,String id) throws IOException; ResultEntity descriptiveStatistics(Map> map, List statistic, String userId); diff --git a/src/main/java/com/sztzjy/marketing/service/impl/StuDigitalMarketingModelServiceImpl.java b/src/main/java/com/sztzjy/marketing/service/impl/StuDigitalMarketingModelServiceImpl.java index da51f31..89b5e58 100644 --- a/src/main/java/com/sztzjy/marketing/service/impl/StuDigitalMarketingModelServiceImpl.java +++ b/src/main/java/com/sztzjy/marketing/service/impl/StuDigitalMarketingModelServiceImpl.java @@ -25,6 +25,8 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static com.sztzjy.marketing.util.algorithm.BaiDuZhiNengYun.getAccessToken; @@ -78,7 +80,7 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM } @Override - public ResultEntity emotionalAnalysis(String userId, String modelType, String content) throws IOException { + public ResultEntity emotionalAnalysis(String userId, String modelType, String content,String id) throws IOException { MediaType mediaType = MediaType.parse("application/json"); @@ -122,8 +124,10 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM if(modelType.equals(Constant.WORD_FREQUENCY)){ //词频分析 + String string = this.filterPunctuation(content); + // 使用 HanLP 分词 - List terms = HanLP.segment(content); + List terms = HanLP.segment(string); // 创建词汇表 Map wordCount = new HashMap<>(); // 统计词频 @@ -166,6 +170,18 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM return null; } + // 过滤标点符号的函数 + private String filterPunctuation(String originalContent) { + // 创建一个正则表达式,用于匹配所有标点符号 + String punctuationPattern = "[\\p{Punct}]"; + // 创建一个 Pattern 对象 + Pattern pattern = Pattern.compile(punctuationPattern); + // 创建一个 Matcher 对象 + Matcher matcher = pattern.matcher(originalContent); + // 使用 Matcher 的 replaceAll 方法替换所有匹配的标点符号为 "" + return matcher.replaceAll(""); + } + @Override public ResultEntity descriptiveStatistics(Map> map, List statistic, String userId) { @@ -179,36 +195,38 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM DescriptiveStatistics statistics=new DescriptiveStatistics(); + DecimalFormat df = new DecimalFormat("#.0"); + for (int i = 0; i < statistic.size(); i++) { if(statistic.get(i).equals("平均数")){ double mean = statisticsUtil.getMean(map.get(key)); - statistics.setAverage(mean); + statistics.setAverage(Double.parseDouble(df.format(mean))); } if(statistic.get(i).equals("中位数")){ double median = statisticsUtil.getMedian(map.get(key)); - statistics.setMedian(median); + statistics.setMedian(Double.parseDouble(df.format(median))); } if(statistic.get(i).equals("众数")){ Double mode = statisticsUtil.getMode(map.get(key)); - statistics.setMode(mode); + statistics.setMode(Double.parseDouble(df.format(mode))); } if(statistic.get(i).equals("标准差")){ double standardDeviation = statisticsUtil.getStandardDeviation(map.get(key)); - DecimalFormat df = new DecimalFormat("#.0"); + statistics.setStandardDeviation(Double.parseDouble(df.format(standardDeviation))); } if(statistic.get(i).equals("方差")){ double variance = statisticsUtil.getVariance(map.get(key)); - statistics.setVariance(variance); + statistics.setVariance(Double.parseDouble(df.format(variance))); } if(statistic.get(i).equals("标准误差")){ double standardError = statisticsUtil.getStandardError(map.get(key)); - statistics.setStandardError(standardError); + statistics.setStandardError(Double.parseDouble(df.format(standardError))); } if(statistic.get(i).equals("峰度")){ @@ -217,7 +235,7 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM if(Double.isNaN(kurtosis)){ statistics.setKurtosis(0); }else { - statistics.setKurtosis(kurtosis); + statistics.setKurtosis(Double.parseDouble(df.format(kurtosis))); } @@ -228,24 +246,24 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM if(Double.isNaN(skewness)){ statistics.setSkewness(0); }else { - statistics.setSkewness(skewness); + statistics.setSkewness(Double.parseDouble(df.format(skewness))); } } if(statistic.get(i).equals("最大值")){ double max = statisticsUtil.getMax(map.get(key)); - statistics.setMax(max); + statistics.setMax(Double.parseDouble(df.format(max))); } if(statistic.get(i).equals("最小值")){ double min = statisticsUtil.getMin(map.get(key)); - statistics.setMin(min); + statistics.setMin(Double.parseDouble(df.format(min))); } if(statistic.get(i).equals("求和")){ double sum = statisticsUtil.getSum(map.get(key)); - statistics.setSummation(sum); + statistics.setSummation(Double.parseDouble(df.format(sum))); } if(statistic.get(i).equals("观测数")){ @@ -263,43 +281,51 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM @Override public List viewMetrics(String userId, String tableName,String algorithmName) { + + List list=new ArrayList<>(); - if(tableName.equals(Constant.YHSXB)){ + if(algorithmName.equals("情感分析")){ + list.add("text"); + }else { + if(tableName.equals(Constant.YHSXB)){ // list=indicatorsMapper.getYHSXB(); - list.add("id"); - list.add("role_gender"); - list.add("role_age"); - } - if(tableName.equals(Constant.YHDLHYB)){ + list.add("id"); + list.add("role_gender"); + list.add("role_age"); + } + if(tableName.equals(Constant.YHDLHYB)){ // list=indicatorsMapper.getYHDLHYB(); - list.add("id"); - list.add("login_frequency"); - list.add("login_duration"); + list.add("id"); + list.add("login_frequency"); + list.add("login_duration"); - } - if(tableName.equals(Constant.YHXFNLB)){ + } + if(tableName.equals(Constant.YHXFNLB)){ // list=indicatorsMapper.getYHXFNLB(); if(algorithmName.equals("关联规则挖掘")){ list.add("consumer_goods"); } else { - list.add("id"); - list.add("consumer_amount"); - list.add("consumer_number"); - list.add("consumer_past_seven_days_amount"); - list.add("consumer_past_seven_days_number"); - } + list.add("id"); + list.add("consumer_amount"); + list.add("consumer_number"); + list.add("consumer_past_seven_days_amount"); + list.add("consumer_past_seven_days_number"); + } - } - if(tableName.equals(Constant.YHPLB) || tableName.equals(Constant.YHXWB)){ + } + if(tableName.equals(Constant.YHPLB) || tableName.equals(Constant.YHXWB)){ // list=indicatorsMapper.getYHPLB(); if(algorithmName.equals("关联规则挖掘")){ list.add("goods_name"); - }else { - list.add("id"); - list.add("user_behavior_type"); + }else { + list.add("id"); + list.add("user_behavior_type"); + } } } + + return list; } @@ -331,17 +357,17 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM - //将日期类型转为时间戳返回 - for (Map row : attributes) { - for (Map.Entry entry : row.entrySet()) { - if (entry.getValue() instanceof LocalDateTime) { - LocalDateTime localDateTime = (LocalDateTime) entry.getValue(); - ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); - Instant instant = zonedDateTime.toInstant(); - entry.setValue(instant.toEpochMilli()); - } - } - } +// //将日期类型转为时间戳返回 +// for (Map row : attributes) { +// for (Map.Entry entry : row.entrySet()) { +// if (entry.getValue() instanceof LocalDateTime) { +// LocalDateTime localDateTime = (LocalDateTime) entry.getValue(); +// ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); +// Instant instant = zonedDateTime.toInstant(); +// entry.setValue(instant.toEpochMilli()); +// } +// } +// } return new ResultEntity(HttpStatus.OK,attributes); @@ -349,11 +375,20 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM @Override public ResultEntity dataPreprocessing(String userId, String method, List> mapList) { + + if(mapList.isEmpty()){ + return null; + } + //数据去重 Set set = new HashSet<>(); List> deduplicatedDataList = new ArrayList<>(); + for (Map map : mapList) { + if(map.isEmpty()){ + continue; + } String mapString = map.toString(); if (!set.contains(mapString)) { set.add(mapString); diff --git a/src/main/java/com/sztzjy/marketing/util/algorithm/Apriori.java b/src/main/java/com/sztzjy/marketing/util/algorithm/Apriori.java index dc93ee8..1c2bde8 100644 --- a/src/main/java/com/sztzjy/marketing/util/algorithm/Apriori.java +++ b/src/main/java/com/sztzjy/marketing/util/algorithm/Apriori.java @@ -212,7 +212,7 @@ public class Apriori { /** * 根据最终的关联集,根据公式计算出各个关联事件 */ - public static List connection(double min_confident) { + public static List connection(double min_confident) { List list=new ArrayList<>(); @@ -249,6 +249,9 @@ public class Apriori { associationRulesDTO.setAssociated(item_post); associationRulesDTO.setConfidenceLevel(confident); + String string=item_pre + "==>" + item_post+"==>" + confident; + associationRulesDTO.setRule(string); + list.add(associationRulesDTO); @@ -256,7 +259,7 @@ public class Apriori { System.out.print(item_pre + "==>" + item_post );// 则是一个关联事件 System.out.println("==>" + confident); - String string=item_pre + "==>" + item_post+"==>" + confident; + lists.add(string); } @@ -266,7 +269,7 @@ public class Apriori { } } } - return lists; + return list; } public static void main(String[] args) { diff --git a/src/main/java/com/sztzjy/marketing/util/algorithm/LinearRegression.java b/src/main/java/com/sztzjy/marketing/util/algorithm/LinearRegression.java index a370d24..461a00f 100644 --- a/src/main/java/com/sztzjy/marketing/util/algorithm/LinearRegression.java +++ b/src/main/java/com/sztzjy/marketing/util/algorithm/LinearRegression.java @@ -53,11 +53,11 @@ public class LinearRegression { } // 预测方法 - public double predict(double[] x) { - if (x.length != this.slopes.length) { + public double predict(double[] x,double intercept,double[] slopes) { + if (x.length != slopes.length) { throw new IllegalArgumentException("输入的x维度与模型不匹配"); } - return this.intercept + dotProduct(this.slopes, x); + return intercept + dotProduct(slopes, x); } // 获取截距 @@ -70,29 +70,29 @@ public class LinearRegression { return this.slopes; } - public static void main(String[] args) { - // 示例数据 - double[][] x = {{1, 19}, {1, 21}, {2, 20}, {2, 23}, {2, 31}}; - double[] y = {15, 15, 16, 16, 17}; - - // 创建线性回归模型 - LinearRegression lr = new LinearRegression(); - lr.fit(x, y); - - DecimalFormat df = new DecimalFormat("#.0"); - - List list=new ArrayList<>(); - for (int i = 0; i < lr.getSlopes().length; i++) { - String format = df.format(lr.getSlopes()[i]); - list.add(format); - } - // 输出模型参数 - System.out.println("常数项值: " + df.format(lr.getIntercept())); - System.out.println("第一个特征系数值: " + list.get(0)); - - // 预测新数据 - double[] newX = {2, 88}; - double predictedY = lr.predict(newX); - System.out.println("输入x: " + java.util.Arrays.toString(newX) + "预测y=" + df.format(predictedY)); - } +// public static void main(String[] args) { +// // 示例数据 +// double[][] x = {{1, 19}, {1, 21}, {2, 20}, {2, 23}, {2, 31}}; +// double[] y = {15, 15, 16, 16, 17}; +// +// // 创建线性回归模型 +// LinearRegression lr = new LinearRegression(); +// lr.fit(x, y); +// +// DecimalFormat df = new DecimalFormat("#.0"); +// +// List list=new ArrayList<>(); +// for (int i = 0; i < lr.getSlopes().length; i++) { +// String format = df.format(lr.getSlopes()[i]); +// list.add(format); +// } +// // 输出模型参数 +// System.out.println("常数项值: " + df.format(lr.getIntercept())); +// System.out.println("第一个特征系数值: " + list.get(0)); +// +// // 预测新数据 +// double[] newX = {2, 88}; +// double predictedY = lr.predict(newX); +// System.out.println("输入x: " + java.util.Arrays.toString(newX) + "预测y=" + df.format(predictedY)); +// } } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/marketing/util/algorithm/LogisticRegression.java b/src/main/java/com/sztzjy/marketing/util/algorithm/LogisticRegression.java index d0917af..2831131 100644 --- a/src/main/java/com/sztzjy/marketing/util/algorithm/LogisticRegression.java +++ b/src/main/java/com/sztzjy/marketing/util/algorithm/LogisticRegression.java @@ -41,12 +41,12 @@ public class LogisticRegression { } // 预测函数 - public double predict(double x) { + public double predict(double x,double slopes,double intercept) { BigDecimalUtils bigDecimalUtils=new BigDecimalUtils(); - Double mul = bigDecimalUtils.mul(this.theta0, x); + Double mul = bigDecimalUtils.mul(intercept, x); - return bigDecimalUtils.add(this.theta1, mul); + return bigDecimalUtils.add(slopes, mul); } @@ -57,14 +57,14 @@ public class LogisticRegression { } return result; } - - // 梯度下降更新参数 - public void updateParameters(double x, double y) { - double h = predict(x); - double error = y - h; - theta1 += learningRate * error * h * (1 - h) * x; - theta0 += learningRate * error * h * (1 - h); - } +// +// // 梯度下降更新参数 +// public void updateParameters(double x, double y) { +// double h = predict(x); +// double error = y - h; +// theta1 += learningRate * error * h * (1 - h) * x; +// theta0 += learningRate * error * h * (1 - h); +// } private double exponentialDecayLearningRate(double currentEpoch, int totalEpochs) { return learningRate * Math.exp(-(currentEpoch / totalEpochs)); } @@ -96,26 +96,26 @@ public class LogisticRegression { return loss / data.length; } - public static void main(String[] args) { - LogisticRegression model = new LogisticRegression(0.1); // 创建一个逻辑回归模型实例 - - double[][] data = {{1}, {2}, {3}, {4}, {5}}; - double[] labels = {0, 0, 1, 1, 1}; // 假设这是一个二分类问题 - +// public static void main(String[] args) { +// LogisticRegression model = new LogisticRegression(0.1); // 创建一个逻辑回归模型实例 +// +//// double[][] data = {{1}, {2}, {3}, {4}, {5}}; +//// double[] labels = {0, 0, 1, 1, 1}; // 假设这是一个二分类问题 +// // double[][] data = {{1, 19}, {1, 21}, {2, 20}, {2, 23}, {2, 31}}; // double[] labels = {15, 15, 16, 16, 17}; - - model.train(data, labels, 1000); // 训练模型 - - DecimalFormat df = new DecimalFormat("#.0"); - - // 获取并打印截距项和系数 - double intercept = model.getIntercept(); - double coefficient = model.getCoefficient(); - System.out.println("常数项值: " + df.format(intercept)); - System.out.println("系数值 " + df.format(coefficient)); - - double prediction = model.predict(2); - System.out.println("x=3.5的预测: " + df.format(prediction)); - } +// +// model.train(data, labels, 1000); // 训练模型 +// +// DecimalFormat df = new DecimalFormat("#.0"); +// +// // 获取并打印截距项和系数 +// double intercept = model.getIntercept(); +// double coefficient = model.getCoefficient(); +// System.out.println("常数项值: " + df.format(intercept)); +// System.out.println("系数值 " + df.format(coefficient)); +// +// double prediction = model.predict(2); +// System.out.println("x=3.5的预测: " + df.format(prediction)); +// } } \ No newline at end of file diff --git a/src/main/resources/mappers/StuUserAttributeMapper.xml b/src/main/resources/mappers/StuUserAttributeMapper.xml index 4fed9cb..4e960c7 100644 --- a/src/main/resources/mappers/StuUserAttributeMapper.xml +++ b/src/main/resources/mappers/StuUserAttributeMapper.xml @@ -18,6 +18,9 @@ + + + @@ -80,6 +83,25 @@ id, user_id, login_name, user_name, student_id, stu_class, major, school, role_name, role_gender, create_time, role_age, update_time, backups, location + + text + + - select + , + from stu_user_attribute where id = #{id,jdbcType=INTEGER} @@ -115,14 +139,14 @@ user_name, student_id, stu_class, major, school, role_name, role_gender, create_time, role_age, - update_time, backups, location - ) + update_time, backups, location, + text) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{loginName,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, #{stuClass,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, #{school,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR}, #{roleGender,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{roleAge,jdbcType=INTEGER}, - #{updateTime,jdbcType=TIMESTAMP}, #{backups,jdbcType=VARCHAR}, #{location,jdbcType=VARCHAR} - ) + #{updateTime,jdbcType=TIMESTAMP}, #{backups,jdbcType=VARCHAR}, #{location,jdbcType=VARCHAR}, + #{text,jdbcType=LONGVARCHAR}) insert into stu_user_attribute @@ -172,6 +196,9 @@ location, + + text, + @@ -219,6 +246,9 @@ #{location,jdbcType=VARCHAR}, + + #{text,jdbcType=LONGVARCHAR}, + - SELECT - - ${field} - - FROM ${table} - \ No newline at end of file diff --git a/src/main/resources/mappers/StuUserBehaviorMapper.xml b/src/main/resources/mappers/StuUserBehaviorMapper.xml index 70541be..961585a 100644 --- a/src/main/resources/mappers/StuUserBehaviorMapper.xml +++ b/src/main/resources/mappers/StuUserBehaviorMapper.xml @@ -14,11 +14,14 @@ - + + + + @@ -82,6 +85,25 @@ goods_name, goods_type, goods_subcategories, user_behavior_type, behavior_date, create_time, update_time + + text + + - select + , + from stu_user_behavior where id = #{id,jdbcType=INTEGER} @@ -118,13 +142,13 @@ major, school, role_name, goods_name, goods_type, goods_subcategories, user_behavior_type, behavior_date, create_time, - update_time) + update_time, text) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{loginName,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, #{stuClass,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, #{school,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR}, #{goodsName,jdbcType=VARCHAR}, #{goodsType,jdbcType=VARCHAR}, #{goodsSubcategories,jdbcType=VARCHAR}, - #{userBehaviorType,jdbcType=VARCHAR}, #{behaviorDate,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}) + #{userBehaviorType,jdbcType=INTEGER}, #{behaviorDate,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, #{text,jdbcType=LONGVARCHAR}) insert into stu_user_behavior @@ -177,6 +201,9 @@ update_time, + + text, + @@ -216,7 +243,7 @@ #{goodsSubcategories,jdbcType=VARCHAR}, - #{userBehaviorType,jdbcType=VARCHAR}, + #{userBehaviorType,jdbcType=INTEGER}, #{behaviorDate,jdbcType=TIMESTAMP}, @@ -227,6 +254,9 @@ #{updateTime,jdbcType=TIMESTAMP}, + + #{text,jdbcType=LONGVARCHAR}, + + select + + distinct + + + , + + from stu_user_consumption_ability + + + + + order by ${orderByClause} + + - select + , + from stu_user_consumption_ability where id = #{id,jdbcType=INTEGER} @@ -121,14 +145,16 @@ consumer_goods, consumer_goods_type, consumer_amount, consumer_number, consumer_past_seven_days_amount, consumer_past_seven_days_number, recent_consumption_time, - create_time, update_time) + create_time, update_time, text + ) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{loginName,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, #{stuClass,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, #{school,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR}, #{consumerGoods,jdbcType=VARCHAR}, #{consumerGoodsType,jdbcType=VARCHAR}, #{consumerAmount,jdbcType=DECIMAL}, #{consumerNumber,jdbcType=INTEGER}, #{consumerPastSevenDaysAmount,jdbcType=DECIMAL}, #{consumerPastSevenDaysNumber,jdbcType=INTEGER}, #{recentConsumptionTime,jdbcType=TIMESTAMP}, - #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) + #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{text,jdbcType=LONGVARCHAR} + ) insert into stu_user_consumption_ability @@ -187,6 +213,9 @@ update_time, + + text, + @@ -243,6 +272,9 @@ #{updateTime,jdbcType=TIMESTAMP}, + + #{text,jdbcType=LONGVARCHAR}, + - - + update stu_user_consumption_ability @@ -309,11 +340,39 @@ update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + text = #{record.text,jdbcType=LONGVARCHAR}, + + + update stu_user_consumption_ability + set id = #{record.id,jdbcType=INTEGER}, + user_id = #{record.userId,jdbcType=VARCHAR}, + login_name = #{record.loginName,jdbcType=VARCHAR}, + user_name = #{record.userName,jdbcType=VARCHAR}, + student_id = #{record.studentId,jdbcType=VARCHAR}, + stu_class = #{record.stuClass,jdbcType=VARCHAR}, + major = #{record.major,jdbcType=VARCHAR}, + school = #{record.school,jdbcType=VARCHAR}, + role_name = #{record.roleName,jdbcType=VARCHAR}, + consumer_goods = #{record.consumerGoods,jdbcType=VARCHAR}, + consumer_goods_type = #{record.consumerGoodsType,jdbcType=VARCHAR}, + consumer_amount = #{record.consumerAmount,jdbcType=DECIMAL}, + consumer_number = #{record.consumerNumber,jdbcType=INTEGER}, + consumer_past_seven_days_amount = #{record.consumerPastSevenDaysAmount,jdbcType=DECIMAL}, + consumer_past_seven_days_number = #{record.consumerPastSevenDaysNumber,jdbcType=INTEGER}, + recent_consumption_time = #{record.recentConsumptionTime,jdbcType=TIMESTAMP}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + text = #{record.text,jdbcType=LONGVARCHAR} + + + + update stu_user_consumption_ability set id = #{record.id,jdbcType=INTEGER}, @@ -392,9 +451,34 @@ update_time = #{updateTime,jdbcType=TIMESTAMP}, + + text = #{text,jdbcType=LONGVARCHAR}, + where id = #{id,jdbcType=INTEGER} + + update stu_user_consumption_ability + set user_id = #{userId,jdbcType=VARCHAR}, + login_name = #{loginName,jdbcType=VARCHAR}, + user_name = #{userName,jdbcType=VARCHAR}, + student_id = #{studentId,jdbcType=VARCHAR}, + stu_class = #{stuClass,jdbcType=VARCHAR}, + major = #{major,jdbcType=VARCHAR}, + school = #{school,jdbcType=VARCHAR}, + role_name = #{roleName,jdbcType=VARCHAR}, + consumer_goods = #{consumerGoods,jdbcType=VARCHAR}, + consumer_goods_type = #{consumerGoodsType,jdbcType=VARCHAR}, + consumer_amount = #{consumerAmount,jdbcType=DECIMAL}, + consumer_number = #{consumerNumber,jdbcType=INTEGER}, + consumer_past_seven_days_amount = #{consumerPastSevenDaysAmount,jdbcType=DECIMAL}, + consumer_past_seven_days_number = #{consumerPastSevenDaysNumber,jdbcType=INTEGER}, + recent_consumption_time = #{recentConsumptionTime,jdbcType=TIMESTAMP}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + text = #{text,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=INTEGER} + update stu_user_consumption_ability set user_id = #{userId,jdbcType=VARCHAR}, @@ -416,11 +500,4 @@ update_time = #{updateTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} - \ No newline at end of file diff --git a/src/main/resources/mappers/StuUserLoginActiveMapper.xml b/src/main/resources/mappers/StuUserLoginActiveMapper.xml index 7e8c225..beb8605 100644 --- a/src/main/resources/mappers/StuUserLoginActiveMapper.xml +++ b/src/main/resources/mappers/StuUserLoginActiveMapper.xml @@ -18,6 +18,9 @@ + + + @@ -81,6 +84,25 @@ frequent_login_location, last_login_date, login_frequency, login_duration, create_time, update_time + + text + + - select + , + from stu_user_login_active where id = #{id,jdbcType=INTEGER} @@ -117,13 +141,13 @@ major, school, role_name, frequent_login_location, last_login_date, login_frequency, login_duration, create_time, - update_time) + update_time, text) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{loginName,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, #{stuClass,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, #{school,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR}, #{frequentLoginLocation,jdbcType=VARCHAR}, #{lastLoginDate,jdbcType=TIMESTAMP}, #{loginFrequency,jdbcType=INTEGER}, #{loginDuration,jdbcType=DOUBLE}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}) + #{updateTime,jdbcType=TIMESTAMP}, #{text,jdbcType=LONGVARCHAR}) insert into stu_user_login_active @@ -173,6 +197,9 @@ update_time, + + text, + @@ -220,6 +247,9 @@ #{updateTime,jdbcType=TIMESTAMP}, + + #{text,jdbcType=LONGVARCHAR}, +