Fork me on GitHub

QUick math questions, I have a series of dates, my x-axis and a series of values for each date (my y-axis), the dates are 15 minutes segments. What do I want to DDG to figure out the trend of the values and see when that trend will cut the x axis ?


I mean what is the name of the math 'thing' that does this ?


i think the term is linear regression

📈 1

Linear Regression?


Thanks, I'll look that up!


Say my points look something like this (sorry for hte terrible MS Paint) Would linear regression have a way to ignore the big spike that is so far outside the normal range ? OR would I have to figure out way to remove this first before doing the linear regression part ?


The second. Linear regression just finds a, well, line, that fits your data better than any other. To filter out such spikes, you have to do it yourself - either by manually filtering for outliers or by using some statistical tool with some cut-offs.


Thanks, What I basically have is data recorded from a device, but it contains some rare spikes. However if the values outside that spike are trending down, I'd like to be able to figure out after each recording a rough prediction when it will be at 0


To within a couple of days, assuming samples are taken every 15 minutes


Does removing the spikes then linear regression seem like a reasonable way to achieve this ?


The easiest way is, no joke, to use Excel for that. :D Or LibreOffice Calc or whatever else spreadsheet software you might have. Assuming the amount of data is not huge.


> Does removing the spikes then linear regression seem like a reasonable way to achieve this ? Yes. Without any model behind the data, it's pretty much the way to do it.


I'd like to somehow automate it, the data coming in is automated, and I'd like to somehow get an alert to me that I need to do something


data science is always a two step process: clean the data, analyze the data


So I was thinking do this is at the service that is pulling the data off a rabbit MQ queue I have setup


Well, I'd also add "create a model for your data" as the step 0 above - otherwise, you can't really clean your data.


One possibility is to determine the mean μ, and standard deviation σ, and then filter out (or clip) all data that differs from the mean by, say, 2σ. So filtering: (filter #(< (abs (- % mean)) (* 2 std-dev)) data) or to clip:

(map #(let [std-dev2 (* 2 std-dev)
            diff (- % mean)]
        (if (> 0 diff)
          (max % (- mean std-dev2))
          (min % (+ mean std-dev2))))
That tends to clean up most extreme outliers. It’s not perfect. If outliers are really extreme, then it can change the mean to pull the some data outside of a 2σ range (this is incredibly unlikely). If that were to happen, then a 2 step process can help, where standard deviation is calculated once, then some large multiple of σ is used to filter the data, and then repeat the process with a more modest multiple of σ. (I’ve never seen this needed)

👍 1

Thanks that's brilliant!


As a bit of trivia, clipping extreme values is called


@U0K1RLM99 might just have som info on this.


Hello. I’m with @U2FRKM4TW on this, Excel/LibreOffice is the perfect starting point for any sort of Linear Regression. In the book I used Apache Commons Math to put together a 2D array of double values, that will output LR as well. Easy enough to retrain from RabbitMQ as well but you’ll have to persist the data somewhere obviously. I’m only skim reading the thread, so apologies if it’s already been covered.

josef moudrik22:02:05

Or you can also use linear model, but fitted with different error function. Normally, one uses Least squares error, but then outliers (e.g. your spike) can have disproportionate effect. So you might want to checkout Huber loss. Other keywords are outlier detection/removal, as @U051N6TTC suggests. You can also do that by "distance from the fitted line", ie, remove the points, that are most far away from the fit (instead of data mean).

👍 2

+1 on @U051N6TTC technique. I'd plot the values on a histogram, and if it looks reasonably bell-curvy, clipping out values 3 or 2 std deviations from the mean might work well. But convince yourself that you’re genuinely trimming the tails/outliers.


I’d filter it out - you know unless you’ve just discovered another particle past the Higgs.


Anyone here got this watch - any good?


It seems like the thing I'm after for while: good battery life, nothing fancy: time + pedometer, that's it. But this thing is even programmable.

Darin Douglass00:02:43

I have the original bangle but haven't used it much, it was too big. This looks much more manageable I thought about making a bangle-cljs wrapper lib back when I first got it :p


that would be funny because it would wrap over your ... caREPL tunnel

🅱️ 2
🅾️ 2
0️⃣ 2

@U04V15CAJ Did you end up ordering one? Looks quite interesting.