数字营销实训算法第7轮修改

master
@t2652009480 7 months ago
parent fdfb7a1479
commit 33266785b4

@ -241,7 +241,7 @@ public class StuDigitalMarketingModelController {
LogisticRegression lr = new LogisticRegression(x, y);
double[] coefficients = lr.fit();
DecimalFormat df = new DecimalFormat("#.0");
DecimalFormat df = new DecimalFormat("#.00");
RAnalysisDTO rAnalysisDTO=new RAnalysisDTO();
rAnalysisDTO.setIntercept(Double.parseDouble(df.format(coefficients[0])));
@ -250,6 +250,21 @@ public class StuDigitalMarketingModelController {
return new ResultEntity(HttpStatus.OK,"成功",rAnalysisDTO);
}
@ApiOperation("回归分析--走势图")
@PostMapping("/trendChart")
@AnonymousAccess
public ResultEntity trendChart(@RequestBody LogisticDTO logisticDTO) {
double[] x = logisticDTO.getX();
double[] y = logisticDTO.getY();
LogisticRegression lr = new LogisticRegression(x, y);
double[][] coefficients = lr.getCoordinatesOnLine();
return new ResultEntity(HttpStatus.OK,"成功",coefficients);
}
@ApiOperation("线性回归/逻辑回归--预测")
@PostMapping("/prediction")

@ -1,5 +1,7 @@
package com.sztzjy.marketing.util.algorithm;
import java.util.Arrays;
public class LogisticRegression {
private double[] x;
@ -39,6 +41,19 @@ public class LogisticRegression {
return new double[] { intercept, slope };
}
public double[][] getCoordinatesOnLine() {
double[] parameters = fit();
double intercept = parameters[0];
double slope = parameters[1];
double[][] coordinates = new double[x.length][2];
for (int i = 0; i < x.length; i++) {
coordinates[i][0] = x[i];
coordinates[i][1] = slope * x[i] + intercept;
}
return coordinates;
}
}
Loading…
Cancel
Save