A statistical and data mining tool for ECharts. You can use it to analyze data and then visualize the results with ECharts, or just use it to process data.
It works both in node.js and in the browser.
If you use npm, you can install it with:
npm install echarts-statOtherwise, download this tool from dist directory:
<script src='./dist/ecStat.js'></script>
<script>
var result = ecStat.clustering.hierarchicalKMeans(data, clusterNumber, false);
</script>Clustering can divide the original data set into multiple data clusters with different characteristics. And through ECharts, you can visualize the results of clustering, or visualize the process of clustering.
var result = ecStat.clustering.hierarchicalKMeans(data, clusterNumber, stepByStep);
-
data -
Two-dimensional Numeric Array, each data point can have more than two numeric attributes in the original data set. In the following example,data[0]is calleddata pointanddata[0][1]is one of the numeric attributes ofdata[0].var data = [ [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], ... ];
-
clusterNumer -
number, the number of clusters generated -
stepByStep -
Boolean, control whether doing the clustering step by step
-
result -
Object, including the centroids, clusterAssment, and pointsInCluster. For Example:result.centroids = [ [-0.460, -2.778], [2.934, 3.128], ... ]; // indicate which cluster each data point belonging to, and the distance to cluster centroids result.clusterAssment = [ [1, 0.145], [2, 0.680], [0, 1.022], ... ]; // concrete data point in each cluster result.pointsInCluster = [ [ [0.335, -3.376], [-0.994, -0.884], ... ], ... ];
You can not only do cluster analysis through this interface, but also use ECharts to visualize the results.
Note: the clustering algorithm can handle multiple numeric attributes, but for the convenience of visualization, two numeric attributes are chosen here as an example.
<script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var clusterNumber = 3;
var result = ecStat.clustering.hierarchicalKMeans(data, clusterNumber, false);
</script><script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var clusterNumber = 6;
var result = ecStat.clustering.hierarchicalKMeans(data, clusterNumber, true);
</script>Regression algorithm can according to the value of the dependent and independent variables of the data set, fitting out a curve to reflect their trends. The regression algorithm here only supports two numeric attributes.
var myRegression = ecStat.regression(regressionType, data, order);
-
regressionType -
String, there are four types of regression, whice arelinear,exponential,logarithmic,polynomial -
data -
Two-dimensional Numeric Array, each data object should have two numeric attributes in the original data set. For Example:var data = [ [1, 2], [3, 5], ... ];
-
order -
number, the order of polynomial. If you choose other types of regression, you can ignore it
-
myRegression -
Object, Including points, parameter, and expression. For Example:myRegression.points = [ [1, 2], [3, 4], ... ]; // this is the parameter of linear regression, for other types, it shoule be a little different myRegression.parameter = { gradient: 1.695, intercept: 3.008 }; myRegression.expression = 'y = 1.7x + 3.01';
You can not only do regression analysis through this interface, you can also use ECharts to visualize the results.
<script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var myRegression = ecStat.regression('linear', data);
</script><script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var myRegression = ecStat.regression('exponential', data);
</script><script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var myRegression = ecStat.regression('logarithmic', data);
</script><script src='https://cdn.bootcss.com/echarts/3.4.0/echarts.js'></script>
<script src='./dist/ecStat.js'></script>
<script>
var myRegression = ecStat.regression('polynomial', data, 3);
</script>This interface provides general statistical services such as maximum, minimum, average, median, sum, etc.
var maxValue = ecStat.statistic.max(dataList);
- dataList :
Array.<number>
- maxValue:
number, the maximum value of the data list
var minValue = ecStat.statistic.min(dataList);
- dataList :
Array.<number>
- minValue:
number, the minimum value of the data list
var meanValue = ecStat.statistic.mean(dataList);
- dataList :
Array.<number>
- meanValue:
number, the average of the data list
var medianValue = ecStat.statistic.median(dataList);
- dataList :
Array.<number>
- medianValue:
number, the median of the data list
var sumValue = ecStat.statistic.sum(dataList);
- dataList :
Array.<number>
- sumValue:
number, the sum of the data list