How to use the simple-statistics.linearRegression function in simple-statistics

To help you get started, we’ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudkeeper-io / cloudkeeper-ui / src / components / data-cards / trends-card / trends-card.utils.tsx View on Github external
export const getGraphData = (data: any, activeIndex: number) => {
  const { dateField, valueField } = TRENDS[activeIndex]
  const formattedCostData = map(data, (x) => ({ date: DateTime.fromISO(x[dateField]).valueOf(), value: x[valueField] }))
  const regressionData = map(formattedCostData, (x) => [x.date, x.value])
  const regression = linearRegression(regressionData)
  const lineFn = linearRegressionLine(regression)

  return map(formattedCostData, (x, index) => ({ ...x, trendData: lineFn(first(regressionData[index])) }))
}