|
|
|
@ -30,7 +30,7 @@ import java.math.BigDecimal;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static com.sztzjy.marketing.util.algorithm.KMeans.readIrisData;
|
|
|
|
|
import static com.sztzjy.marketing.util.algorithm.KMeans.*;
|
|
|
|
|
import static com.sztzjy.marketing.util.algorithm.KMeansResult.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -62,8 +62,9 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
@PostMapping("/viewMetrics")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity viewMetrics(@ApiParam("用户ID") String userId,
|
|
|
|
|
@ApiParam("表格名") String tableName) {
|
|
|
|
|
List<String> list=modelService.viewMetrics(userId,tableName);
|
|
|
|
|
@ApiParam("表格名") String tableName,
|
|
|
|
|
@ApiParam("算法名称") String algorithmName) {
|
|
|
|
|
List<String> list=modelService.viewMetrics(userId,tableName,algorithmName);
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +113,9 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
Integer k = clusterScatterPlotDTO.getK();
|
|
|
|
|
List<Map<String, Object>> deduplicatedDataList = clusterScatterPlotDTO.getDeduplicatedDataList();
|
|
|
|
|
|
|
|
|
|
List<KMeans.Point> irisData = readIrisData(deduplicatedDataList);
|
|
|
|
|
List<String> strings = convertToDelimitedStringList(deduplicatedDataList);
|
|
|
|
|
|
|
|
|
|
List<KMeans.Point> irisData = readIrisData(strings);
|
|
|
|
|
|
|
|
|
|
//获取数据集
|
|
|
|
|
KMeans kMeans = new KMeans(k, t, irisData);
|
|
|
|
@ -148,12 +151,16 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
@ApiOperation("聚类分析--分析结果")
|
|
|
|
|
@PostMapping("/clusterAnalysisResult")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity clusterAnalysisResult(@ApiParam("簇数") Integer k,
|
|
|
|
|
@ApiParam("最大迭代次数") Integer t,
|
|
|
|
|
@ApiParam("最大迭代次数") String userId,
|
|
|
|
|
@RequestParam(required = false) @RequestPart MultipartFile file) {
|
|
|
|
|
public ResultEntity clusterAnalysisResult(@RequestBody ClusterScatterPlotDTO clusterScatterPlotDTO) {
|
|
|
|
|
|
|
|
|
|
Integer t = clusterScatterPlotDTO.getT();
|
|
|
|
|
Integer k = clusterScatterPlotDTO.getK();
|
|
|
|
|
List<Map<String, Object>> deduplicatedDataList = clusterScatterPlotDTO.getDeduplicatedDataList();
|
|
|
|
|
|
|
|
|
|
List<String> strings = convertToDelimitedStringList(deduplicatedDataList);
|
|
|
|
|
|
|
|
|
|
//初始化数据
|
|
|
|
|
ArrayList<ArrayList<Float>> arrayLists = readTable(file);
|
|
|
|
|
ArrayList<ArrayList<Float>> arrayLists = readTable(strings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//随机选择 k 个数据点作为初始聚类中心
|
|
|
|
@ -163,7 +170,7 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
ArrayList<ArrayList<ArrayList<Float>>> kmeans = kmeans(k, t, centerList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK);
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,kmeans);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -171,20 +178,23 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
@ApiOperation("关联规则挖掘")
|
|
|
|
|
@PostMapping("/apriori")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity apriori(@ApiParam("最小支持度阀值") double support,
|
|
|
|
|
@ApiParam("最小置信度") double confidence,
|
|
|
|
|
@ApiParam("用户ID") String userId,
|
|
|
|
|
@RequestParam(required = false) @RequestPart MultipartFile file) throws IOException {
|
|
|
|
|
public ResultEntity apriori(@RequestBody AprioriDTO aprioriDTO) throws IOException {
|
|
|
|
|
|
|
|
|
|
double support = aprioriDTO.getSupport();
|
|
|
|
|
double confidence = aprioriDTO.getConfidence();
|
|
|
|
|
String userId = aprioriDTO.getUserId();
|
|
|
|
|
List<Map<String, Object>> deduplicatedDataList = aprioriDTO.getDeduplicatedDataList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> strings = convertToDelimitedStringList(deduplicatedDataList);
|
|
|
|
|
//初始化事务数据库、项目集、候选集再进行剪枝
|
|
|
|
|
Apriori.init(file,support);
|
|
|
|
|
Apriori.init(strings,support);
|
|
|
|
|
|
|
|
|
|
//迭代求出最终的候选频繁集
|
|
|
|
|
Apriori.iteration(Apriori.C,Apriori.L,support);
|
|
|
|
|
|
|
|
|
|
//根据最终的关联集,根据公式计算出各个关联事件
|
|
|
|
|
List<AssociationRulesDTO> connection = Apriori.connection(confidence);
|
|
|
|
|
List<String> connection = Apriori.connection(confidence);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",connection);
|
|
|
|
@ -202,26 +212,38 @@ 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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",regression);
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",rAnalysisDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ApiOperation("回归分析--逻辑回归")
|
|
|
|
|
// @PostMapping("/logistic")
|
|
|
|
|
// @AnonymousAccess
|
|
|
|
|
// public ResultEntity logistic(@RequestBody LogisticDTO logisticDTO) {
|
|
|
|
|
// double[] x = logisticDTO.getX();
|
|
|
|
|
// double[] y = logisticDTO.getY();
|
|
|
|
|
//
|
|
|
|
|
// // 创建线性回归模型
|
|
|
|
|
// LogisticRegression regression=new LogisticRegression();
|
|
|
|
|
// regression.fit(x,y);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return new ResultEntity(HttpStatus.OK,"成功",regression);
|
|
|
|
|
// }
|
|
|
|
|
@ApiOperation("回归分析--逻辑回归")
|
|
|
|
|
@PostMapping("/logistic")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity logistic(@RequestBody LogisticDTO logisticDTO) {
|
|
|
|
|
double[][] x = logisticDTO.getX();
|
|
|
|
|
double[] y = logisticDTO.getY();
|
|
|
|
|
|
|
|
|
|
// 创建一个逻辑回归模型实例,0.1学习率
|
|
|
|
|
LogisticRegression model = new LogisticRegression(0.1);
|
|
|
|
|
model.train(x,y,1000); //训练模型
|
|
|
|
|
|
|
|
|
|
DecimalFormat df = new DecimalFormat("#.0");
|
|
|
|
|
RAnalysisDTO rAnalysisDTO=new RAnalysisDTO();
|
|
|
|
|
|
|
|
|
|
rAnalysisDTO.setIntercept(Double.parseDouble(df.format(model.getIntercept())));
|
|
|
|
|
rAnalysisDTO.setSlopes(Double.parseDouble(df.format(model.getCoefficient())));
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",rAnalysisDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("情感分析/文本挖掘")
|
|
|
|
@ -237,7 +259,7 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
@ApiOperation("批量导入")
|
|
|
|
|
@PostMapping("/batchImport")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity batchImport(@RequestPart MultipartFile file) {
|
|
|
|
|
public ResultEntity batchImport(@RequestParam(required = false) @RequestPart MultipartFile file) {
|
|
|
|
|
|
|
|
|
|
//验证文件类型
|
|
|
|
|
if (!file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(".xls") && !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(".xlsx")) {
|
|
|
|
@ -262,10 +284,10 @@ public class StuDigitalMarketingModelController {
|
|
|
|
|
|
|
|
|
|
StuSpendingLevel stuSpendingLevel=new StuSpendingLevel();
|
|
|
|
|
stuSpendingLevel.setId(Integer.valueOf((String) list.get(0)));
|
|
|
|
|
stuSpendingLevel.setGender(Integer.valueOf((String) list.get(0)));
|
|
|
|
|
stuSpendingLevel.setAge(Integer.valueOf((String) list.get(0)));
|
|
|
|
|
stuSpendingLevel.setAnnualIncome(Integer.valueOf((String) list.get(0)));
|
|
|
|
|
stuSpendingLevel.setSpendingScore(Integer.valueOf((String) list.get(0)));
|
|
|
|
|
stuSpendingLevel.setGender(Integer.valueOf((String) list.get(1)));
|
|
|
|
|
stuSpendingLevel.setAge(Integer.valueOf((String) list.get(2)));
|
|
|
|
|
stuSpendingLevel.setAnnualIncome(Integer.valueOf((String) list.get(3)));
|
|
|
|
|
stuSpendingLevel.setSpendingScore(Integer.valueOf((String) list.get(4)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|