linear_regression_trend 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0886ac85ef56b725b1deaa5d4ca3331d4a981ee8
4
- data.tar.gz: f3e224e216a4cc89524c2fd27b44a28e139f9b8e
3
+ metadata.gz: 2fc6a051f494d36ea83d3a66caf42e40fe74abf1
4
+ data.tar.gz: f38fca3d95e629f05479ce1feb32d6956cf66ed1
5
5
  SHA512:
6
- metadata.gz: 733341279c21804fc37579789fd52f56bcf69d606e6dc2f117321f6dff3eb5673f3a500a0578c325388e700ad9a96ac59095685576e6e24ab66bef66a44512e9
7
- data.tar.gz: 4ecc8929a43d05fa0c67e46ce45d1ce2ee2690e7ffdf0d9a75e098e80ed5136caa67b108da641ca4b7fbdfabd4e9653d49291ae2bf300ffeb2feeac093c49707
6
+ metadata.gz: daa2c943c83b8357b20a2ede0e907b21eccf06f0489fde8aab0688d585894e1ba7952bae89a1bff13c0739a1f86c05c7a2c0df93c5dbf4b06734d8af51e842c0
7
+ data.tar.gz: 399945f52cf218eba613a072f08ab5740cb0da5731eb6a4bd2a89422d7a508a4ea51f852c44506926f7979ea21d4785a9ceb08c3890136de9bb4cae8897637ba
data/README.md CHANGED
@@ -46,6 +46,22 @@ trend_slope = trender.slope # => a negative number, indicating a descend
46
46
  trended_samples.last == 0 # => true, would've be -0.8927 otherwise
47
47
  ```
48
48
 
49
+ ## Usage: Forecasting values
50
+
51
+ Let's assume you're have a value for each day of the month, and it's currently the middle of the month. If you want to know what the trend will look like for
52
+ the remainder of the month, you can forecast the trend past the samples supplied.
53
+
54
+ ```ruby
55
+ samples = [10, 14, 18, 22, 26, 15, 19, 12, 1, 39, 31, 33, 16, 9, 12] # 15 days of samples
56
+ trender = LinearRegressionTrend::Calculator.new(samples)
57
+
58
+ forecast = trender.forecast_next(15) # => [20.267, 20.492, 20.717, 20.942, 21.167, 21.392, 21.617, 21.842, 22.067, 22.292, 22.517, 22.742, 22.967, 23.192, 23.417]
59
+ ```
60
+
61
+ In this example, the actual trend ends at `20.042`, and the forecast continues smoothly using the same slope from that point on.
62
+
63
+ This functionality will obey the `non_negative` flag's setting and forecast down to `0` if set.
64
+
49
65
  ## Development and extra documentation
50
66
 
51
67
  Check out the tests in the /spec dir, and also install iRuby notebook, and **take a look at the live documentation in /doc.**
@@ -144,12 +144,12 @@
144
144
  {
145
145
  "data": {
146
146
  "text/html": [
147
- "<div id='vis-15c391e9-f571-411f-83c9-8da90be28ce1'></div>\n",
147
+ "<div id='vis-47fa842d-71ec-4919-93f8-7ffc6b3add56'></div>\n",
148
148
  "<script>\n",
149
149
  "(function(){\n",
150
150
  " var render = function(){\n",
151
- " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"f4ab127e-0b11-41e9-9e1f-7ef326bd0021\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[0,18]}}],\"data\":{\"f4ab127e-0b11-41e9-9e1f-7ef326bd0021\":[{\"data0\":\"1\",\"data1\":1},{\"data0\":\"2\",\"data1\":2},{\"data0\":\"3\",\"data1\":3},{\"data0\":\"4\",\"data1\":6},{\"data0\":\"5\",\"data1\":10},{\"data0\":\"6\",\"data1\":11},{\"data0\":\"7\",\"data1\":12},{\"data0\":\"8\",\"data1\":12},{\"data0\":\"9\",\"data1\":12},{\"data0\":\"10\",\"data1\":12},{\"data0\":\"11\",\"data1\":15},{\"data0\":\"12\",\"data1\":18},{\"data0\":\"13\",\"data1\":18},{\"data0\":\"14\",\"data1\":16},{\"data0\":\"15\",\"data1\":16},{\"data0\":\"16\",\"data1\":15},{\"data0\":\"17\",\"data1\":14},{\"data0\":\"18\",\"data1\":11},{\"data0\":\"19\",\"data1\":9},{\"data0\":\"20\",\"data1\":9},{\"data0\":\"21\",\"data1\":7},{\"data0\":\"22\",\"data1\":4},{\"data0\":\"23\",\"data1\":2},{\"data0\":\"24\",\"data1\":1},{\"data0\":\"25\",\"data1\":1}]},\"extension\":[]}\n",
152
- " var id_name = '#vis-15c391e9-f571-411f-83c9-8da90be28ce1';\n",
151
+ " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"3dd384c5-7269-49f9-b1bc-3ccdb4bf5bcf\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[0,18]}}],\"data\":{\"3dd384c5-7269-49f9-b1bc-3ccdb4bf5bcf\":[{\"data0\":\"1\",\"data1\":1},{\"data0\":\"2\",\"data1\":2},{\"data0\":\"3\",\"data1\":3},{\"data0\":\"4\",\"data1\":6},{\"data0\":\"5\",\"data1\":10},{\"data0\":\"6\",\"data1\":11},{\"data0\":\"7\",\"data1\":12},{\"data0\":\"8\",\"data1\":12},{\"data0\":\"9\",\"data1\":12},{\"data0\":\"10\",\"data1\":12},{\"data0\":\"11\",\"data1\":15},{\"data0\":\"12\",\"data1\":18},{\"data0\":\"13\",\"data1\":18},{\"data0\":\"14\",\"data1\":16},{\"data0\":\"15\",\"data1\":16},{\"data0\":\"16\",\"data1\":15},{\"data0\":\"17\",\"data1\":14},{\"data0\":\"18\",\"data1\":11},{\"data0\":\"19\",\"data1\":9},{\"data0\":\"20\",\"data1\":9},{\"data0\":\"21\",\"data1\":7},{\"data0\":\"22\",\"data1\":4},{\"data0\":\"23\",\"data1\":2},{\"data0\":\"24\",\"data1\":1},{\"data0\":\"25\",\"data1\":1}]},\"extension\":[]}\n",
152
+ " var id_name = '#vis-47fa842d-71ec-4919-93f8-7ffc6b3add56';\n",
153
153
  " Nyaplot.core.parse(model, id_name);\n",
154
154
  "\n",
155
155
  " require(['downloadable'], function(downloadable){\n",
@@ -168,7 +168,7 @@
168
168
  "</script>\n"
169
169
  ],
170
170
  "text/plain": [
171
- "#<Nyaplot::Frame:0x007ff6544286f8 @properties={:panes=>[#<Nyaplot::Plot:0x007ff65442aca0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007ff654428ba8 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"f4ab127e-0b11-41e9-9e1f-7ef326bd0021\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[0, 18]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[0, 18]}}>], :data=>{\"f4ab127e-0b11-41e9-9e1f-7ef326bd0021\"=>#<Nyaplot::DataFrame:0x007ff65442a778 @name=\"f4ab127e-0b11-41e9-9e1f-7ef326bd0021\", @rows=[{:data0=>\"1\", :data1=>1}, {:data0=>\"2\", :data1=>2}, {:data0=>\"3\", :data1=>3}, {:data0=>\"4\", :data1=>6}, {:data0=>\"5\", :data1=>10}, {:data0=>\"6\", :data1=>11}, {:data0=>\"7\", :data1=>12}, {:data0=>\"8\", :data1=>12}, {:data0=>\"9\", :data1=>12}, {:data0=>\"10\", :data1=>12}, {:data0=>\"11\", :data1=>15}, {:data0=>\"12\", :data1=>18}, {:data0=>\"13\", :data1=>18}, {:data0=>\"14\", :data1=>16}, {:data0=>\"15\", :data1=>16}, {:data0=>\"16\", :data1=>15}, {:data0=>\"17\", :data1=>14}, {:data0=>\"18\", :data1=>11}, {:data0=>\"19\", :data1=>9}, {:data0=>\"20\", :data1=>9}, {:data0=>\"21\", :data1=>7}, {:data0=>\"22\", :data1=>4}, {:data0=>\"23\", :data1=>2}, {:data0=>\"24\", :data1=>1}, {:data0=>\"25\", :data1=>1}]>}, :extension=>[]}>"
171
+ "#<Nyaplot::Frame:0x007fedec1540f0 @properties={:panes=>[#<Nyaplot::Plot:0x007fedec166318 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fedec154cf8 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"3dd384c5-7269-49f9-b1bc-3ccdb4bf5bcf\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[0, 18]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[0, 18]}}>], :data=>{\"3dd384c5-7269-49f9-b1bc-3ccdb4bf5bcf\"=>#<Nyaplot::DataFrame:0x007fedec15f6a8 @name=\"3dd384c5-7269-49f9-b1bc-3ccdb4bf5bcf\", @rows=[{:data0=>\"1\", :data1=>1}, {:data0=>\"2\", :data1=>2}, {:data0=>\"3\", :data1=>3}, {:data0=>\"4\", :data1=>6}, {:data0=>\"5\", :data1=>10}, {:data0=>\"6\", :data1=>11}, {:data0=>\"7\", :data1=>12}, {:data0=>\"8\", :data1=>12}, {:data0=>\"9\", :data1=>12}, {:data0=>\"10\", :data1=>12}, {:data0=>\"11\", :data1=>15}, {:data0=>\"12\", :data1=>18}, {:data0=>\"13\", :data1=>18}, {:data0=>\"14\", :data1=>16}, {:data0=>\"15\", :data1=>16}, {:data0=>\"16\", :data1=>15}, {:data0=>\"17\", :data1=>14}, {:data0=>\"18\", :data1=>11}, {:data0=>\"19\", :data1=>9}, {:data0=>\"20\", :data1=>9}, {:data0=>\"21\", :data1=>7}, {:data0=>\"22\", :data1=>4}, {:data0=>\"23\", :data1=>2}, {:data0=>\"24\", :data1=>1}, {:data0=>\"25\", :data1=>1}]>}, :extension=>[]}>"
172
172
  ]
173
173
  },
174
174
  "metadata": {},
@@ -199,12 +199,12 @@
199
199
  {
200
200
  "data": {
201
201
  "text/html": [
202
- "<div id='vis-77606c3f-45ec-4d9d-83f4-d387935bb1a5'></div>\n",
202
+ "<div id='vis-b565fcc2-6117-4d03-869d-436e4045fd9f'></div>\n",
203
203
  "<script>\n",
204
204
  "(function(){\n",
205
205
  " var render = function(){\n",
206
- " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"ea7a4bcf-0823-4c0b-b7af-e05a762e8b60\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[0,10.246153846153847]}}],\"data\":{\"ea7a4bcf-0823-4c0b-b7af-e05a762e8b60\":[{\"data0\":\"1\",\"data1\":10.246153846153847},{\"data0\":\"2\",\"data1\":10.182307692307694},{\"data0\":\"3\",\"data1\":10.118461538461538},{\"data0\":\"4\",\"data1\":10.054615384615385},{\"data0\":\"5\",\"data1\":9.990769230769232},{\"data0\":\"6\",\"data1\":9.926923076923078},{\"data0\":\"7\",\"data1\":9.863076923076923},{\"data0\":\"8\",\"data1\":9.79923076923077},{\"data0\":\"9\",\"data1\":9.735384615384616},{\"data0\":\"10\",\"data1\":9.671538461538463},{\"data0\":\"11\",\"data1\":9.607692307692307},{\"data0\":\"12\",\"data1\":9.543846153846154},{\"data0\":\"13\",\"data1\":9.48},{\"data0\":\"14\",\"data1\":9.416153846153847},{\"data0\":\"15\",\"data1\":9.352307692307694},{\"data0\":\"16\",\"data1\":9.288461538461538},{\"data0\":\"17\",\"data1\":9.224615384615385},{\"data0\":\"18\",\"data1\":9.160769230769231},{\"data0\":\"19\",\"data1\":9.096923076923078},{\"data0\":\"20\",\"data1\":9.033076923076923},{\"data0\":\"21\",\"data1\":8.96923076923077},{\"data0\":\"22\",\"data1\":8.905384615384616},{\"data0\":\"23\",\"data1\":8.841538461538462},{\"data0\":\"24\",\"data1\":8.777692307692309},{\"data0\":\"25\",\"data1\":8.713846153846154}]},\"extension\":[]}\n",
207
- " var id_name = '#vis-77606c3f-45ec-4d9d-83f4-d387935bb1a5';\n",
206
+ " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"d7619b72-d79f-42cf-840f-b377c686c7e9\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[0,10.246153846153847]}}],\"data\":{\"d7619b72-d79f-42cf-840f-b377c686c7e9\":[{\"data0\":\"1\",\"data1\":10.246153846153847},{\"data0\":\"2\",\"data1\":10.182307692307694},{\"data0\":\"3\",\"data1\":10.118461538461538},{\"data0\":\"4\",\"data1\":10.054615384615385},{\"data0\":\"5\",\"data1\":9.990769230769232},{\"data0\":\"6\",\"data1\":9.926923076923078},{\"data0\":\"7\",\"data1\":9.863076923076923},{\"data0\":\"8\",\"data1\":9.79923076923077},{\"data0\":\"9\",\"data1\":9.735384615384616},{\"data0\":\"10\",\"data1\":9.671538461538463},{\"data0\":\"11\",\"data1\":9.607692307692307},{\"data0\":\"12\",\"data1\":9.543846153846154},{\"data0\":\"13\",\"data1\":9.48},{\"data0\":\"14\",\"data1\":9.416153846153847},{\"data0\":\"15\",\"data1\":9.352307692307694},{\"data0\":\"16\",\"data1\":9.288461538461538},{\"data0\":\"17\",\"data1\":9.224615384615385},{\"data0\":\"18\",\"data1\":9.160769230769231},{\"data0\":\"19\",\"data1\":9.096923076923078},{\"data0\":\"20\",\"data1\":9.033076923076923},{\"data0\":\"21\",\"data1\":8.96923076923077},{\"data0\":\"22\",\"data1\":8.905384615384616},{\"data0\":\"23\",\"data1\":8.841538461538462},{\"data0\":\"24\",\"data1\":8.777692307692309},{\"data0\":\"25\",\"data1\":8.713846153846154}]},\"extension\":[]}\n",
207
+ " var id_name = '#vis-b565fcc2-6117-4d03-869d-436e4045fd9f';\n",
208
208
  " Nyaplot.core.parse(model, id_name);\n",
209
209
  "\n",
210
210
  " require(['downloadable'], function(downloadable){\n",
@@ -223,7 +223,7 @@
223
223
  "</script>\n"
224
224
  ],
225
225
  "text/plain": [
226
- "#<Nyaplot::Frame:0x007ff653a55c48 @properties={:panes=>[#<Nyaplot::Plot:0x007ff652928790 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007ff653a56080 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"ea7a4bcf-0823-4c0b-b7af-e05a762e8b60\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[0, 10.246153846153847]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[0, 10.246153846153847]}}>], :data=>{\"ea7a4bcf-0823-4c0b-b7af-e05a762e8b60\"=>#<Nyaplot::DataFrame:0x007ff653a57bb0 @name=\"ea7a4bcf-0823-4c0b-b7af-e05a762e8b60\", @rows=[{:data0=>\"1\", :data1=>10.246153846153847}, {:data0=>\"2\", :data1=>10.182307692307694}, {:data0=>\"3\", :data1=>10.118461538461538}, {:data0=>\"4\", :data1=>10.054615384615385}, {:data0=>\"5\", :data1=>9.990769230769232}, {:data0=>\"6\", :data1=>9.926923076923078}, {:data0=>\"7\", :data1=>9.863076923076923}, {:data0=>\"8\", :data1=>9.79923076923077}, {:data0=>\"9\", :data1=>9.735384615384616}, {:data0=>\"10\", :data1=>9.671538461538463}, {:data0=>\"11\", :data1=>9.607692307692307}, {:data0=>\"12\", :data1=>9.543846153846154}, {:data0=>\"13\", :data1=>9.48}, {:data0=>\"14\", :data1=>9.416153846153847}, {:data0=>\"15\", :data1=>9.352307692307694}, {:data0=>\"16\", :data1=>9.288461538461538}, {:data0=>\"17\", :data1=>9.224615384615385}, {:data0=>\"18\", :data1=>9.160769230769231}, {:data0=>\"19\", :data1=>9.096923076923078}, {:data0=>\"20\", :data1=>9.033076923076923}, {:data0=>\"21\", :data1=>8.96923076923077}, {:data0=>\"22\", :data1=>8.905384615384616}, {:data0=>\"23\", :data1=>8.841538461538462}, {:data0=>\"24\", :data1=>8.777692307692309}, {:data0=>\"25\", :data1=>8.713846153846154}]>}, :extension=>[]}>"
226
+ "#<Nyaplot::Frame:0x007feded119210 @properties={:panes=>[#<Nyaplot::Plot:0x007feded1203a8 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007feded1196c0 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"d7619b72-d79f-42cf-840f-b377c686c7e9\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[0, 10.246153846153847]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[0, 10.246153846153847]}}>], :data=>{\"d7619b72-d79f-42cf-840f-b377c686c7e9\"=>#<Nyaplot::DataFrame:0x007feded11ba88 @name=\"d7619b72-d79f-42cf-840f-b377c686c7e9\", @rows=[{:data0=>\"1\", :data1=>10.246153846153847}, {:data0=>\"2\", :data1=>10.182307692307694}, {:data0=>\"3\", :data1=>10.118461538461538}, {:data0=>\"4\", :data1=>10.054615384615385}, {:data0=>\"5\", :data1=>9.990769230769232}, {:data0=>\"6\", :data1=>9.926923076923078}, {:data0=>\"7\", :data1=>9.863076923076923}, {:data0=>\"8\", :data1=>9.79923076923077}, {:data0=>\"9\", :data1=>9.735384615384616}, {:data0=>\"10\", :data1=>9.671538461538463}, {:data0=>\"11\", :data1=>9.607692307692307}, {:data0=>\"12\", :data1=>9.543846153846154}, {:data0=>\"13\", :data1=>9.48}, {:data0=>\"14\", :data1=>9.416153846153847}, {:data0=>\"15\", :data1=>9.352307692307694}, {:data0=>\"16\", :data1=>9.288461538461538}, {:data0=>\"17\", :data1=>9.224615384615385}, {:data0=>\"18\", :data1=>9.160769230769231}, {:data0=>\"19\", :data1=>9.096923076923078}, {:data0=>\"20\", :data1=>9.033076923076923}, {:data0=>\"21\", :data1=>8.96923076923077}, {:data0=>\"22\", :data1=>8.905384615384616}, {:data0=>\"23\", :data1=>8.841538461538462}, {:data0=>\"24\", :data1=>8.777692307692309}, {:data0=>\"25\", :data1=>8.713846153846154}]>}, :extension=>[]}>"
227
227
  ]
228
228
  },
229
229
  "metadata": {},
@@ -245,7 +245,7 @@
245
245
  },
246
246
  {
247
247
  "cell_type": "code",
248
- "execution_count": 13,
248
+ "execution_count": 5,
249
249
  "metadata": {
250
250
  "collapsed": false
251
251
  },
@@ -274,7 +274,7 @@
274
274
  },
275
275
  {
276
276
  "cell_type": "code",
277
- "execution_count": 12,
277
+ "execution_count": 6,
278
278
  "metadata": {
279
279
  "collapsed": false
280
280
  },
@@ -282,12 +282,12 @@
282
282
  {
283
283
  "data": {
284
284
  "text/html": [
285
- "<div id='vis-e93ae034-724e-40dd-89ff-8e9e06f30d71'></div>\n",
285
+ "<div id='vis-cfe833a8-7dd7-4041-a740-0bf68252fa8a'></div>\n",
286
286
  "<script>\n",
287
287
  "(function(){\n",
288
288
  " var render = function(){\n",
289
- " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"759c4fe1-01be-4c0f-bf93-49ab6d168710\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[-0.8927692307692308,7.428769230769229]}}],\"data\":{\"759c4fe1-01be-4c0f-bf93-49ab6d168710\":[{\"data0\":\"1\",\"data1\":7.428769230769229},{\"data0\":\"2\",\"data1\":7.082038461538459},{\"data0\":\"3\",\"data1\":6.73530769230769},{\"data0\":\"4\",\"data1\":6.388576923076921},{\"data0\":\"5\",\"data1\":6.041846153846151},{\"data0\":\"6\",\"data1\":5.695115384615383},{\"data0\":\"7\",\"data1\":5.348384615384614},{\"data0\":\"8\",\"data1\":5.001653846153845},{\"data0\":\"9\",\"data1\":4.654923076923075},{\"data0\":\"10\",\"data1\":4.308192307692306},{\"data0\":\"11\",\"data1\":3.961461538461537},{\"data0\":\"12\",\"data1\":3.6147307692307677},{\"data0\":\"13\",\"data1\":3.267999999999999},{\"data0\":\"14\",\"data1\":2.92126923076923},{\"data0\":\"15\",\"data1\":2.5745384615384603},{\"data0\":\"16\",\"data1\":2.2278076923076915},{\"data0\":\"17\",\"data1\":1.8810769230769226},{\"data0\":\"18\",\"data1\":1.534346153846153},{\"data0\":\"19\",\"data1\":1.187615384615384},{\"data0\":\"20\",\"data1\":0.8408846153846152},{\"data0\":\"21\",\"data1\":0.4941538461538455},{\"data0\":\"22\",\"data1\":0.14742307692307666},{\"data0\":\"23\",\"data1\":-0.19930769230769219},{\"data0\":\"24\",\"data1\":-0.5460384615384619},{\"data0\":\"25\",\"data1\":-0.8927692307692308}]},\"extension\":[]}\n",
290
- " var id_name = '#vis-e93ae034-724e-40dd-89ff-8e9e06f30d71';\n",
289
+ " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"2f6a05eb-5092-4677-9bec-ac912016ebc9\"}],\"options\":{\"width\":700,\"xrange\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\"],\"yrange\":[0,7.428769230769229]}}],\"data\":{\"2f6a05eb-5092-4677-9bec-ac912016ebc9\":[{\"data0\":\"1\",\"data1\":7.428769230769229},{\"data0\":\"2\",\"data1\":7.082038461538459},{\"data0\":\"3\",\"data1\":6.73530769230769},{\"data0\":\"4\",\"data1\":6.388576923076921},{\"data0\":\"5\",\"data1\":6.041846153846151},{\"data0\":\"6\",\"data1\":5.695115384615383},{\"data0\":\"7\",\"data1\":5.348384615384614},{\"data0\":\"8\",\"data1\":5.001653846153845},{\"data0\":\"9\",\"data1\":4.654923076923075},{\"data0\":\"10\",\"data1\":4.308192307692306},{\"data0\":\"11\",\"data1\":3.961461538461537},{\"data0\":\"12\",\"data1\":3.6147307692307677},{\"data0\":\"13\",\"data1\":3.267999999999999},{\"data0\":\"14\",\"data1\":2.92126923076923},{\"data0\":\"15\",\"data1\":2.5745384615384603},{\"data0\":\"16\",\"data1\":2.2278076923076915},{\"data0\":\"17\",\"data1\":1.8810769230769226},{\"data0\":\"18\",\"data1\":1.534346153846153},{\"data0\":\"19\",\"data1\":1.187615384615384},{\"data0\":\"20\",\"data1\":0.8408846153846152},{\"data0\":\"21\",\"data1\":0.4941538461538455},{\"data0\":\"22\",\"data1\":0.14742307692307666},{\"data0\":\"23\",\"data1\":0},{\"data0\":\"24\",\"data1\":0},{\"data0\":\"25\",\"data1\":0}]},\"extension\":[]}\n",
290
+ " var id_name = '#vis-cfe833a8-7dd7-4041-a740-0bf68252fa8a';\n",
291
291
  " Nyaplot.core.parse(model, id_name);\n",
292
292
  "\n",
293
293
  " require(['downloadable'], function(downloadable){\n",
@@ -306,7 +306,7 @@
306
306
  "</script>\n"
307
307
  ],
308
308
  "text/plain": [
309
- "#<Nyaplot::Frame:0x007ff6544894a8 @properties={:panes=>[#<Nyaplot::Plot:0x007ff65448bc30 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007ff654489bb0 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"759c4fe1-01be-4c0f-bf93-49ab6d168710\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[-0.8927692307692308, 7.428769230769229]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[-0.8927692307692308, 7.428769230769229]}}>], :data=>{\"759c4fe1-01be-4c0f-bf93-49ab6d168710\"=>#<Nyaplot::DataFrame:0x007ff65448b6e0 @name=\"759c4fe1-01be-4c0f-bf93-49ab6d168710\", @rows=[{:data0=>\"1\", :data1=>7.428769230769229}, {:data0=>\"2\", :data1=>7.082038461538459}, {:data0=>\"3\", :data1=>6.73530769230769}, {:data0=>\"4\", :data1=>6.388576923076921}, {:data0=>\"5\", :data1=>6.041846153846151}, {:data0=>\"6\", :data1=>5.695115384615383}, {:data0=>\"7\", :data1=>5.348384615384614}, {:data0=>\"8\", :data1=>5.001653846153845}, {:data0=>\"9\", :data1=>4.654923076923075}, {:data0=>\"10\", :data1=>4.308192307692306}, {:data0=>\"11\", :data1=>3.961461538461537}, {:data0=>\"12\", :data1=>3.6147307692307677}, {:data0=>\"13\", :data1=>3.267999999999999}, {:data0=>\"14\", :data1=>2.92126923076923}, {:data0=>\"15\", :data1=>2.5745384615384603}, {:data0=>\"16\", :data1=>2.2278076923076915}, {:data0=>\"17\", :data1=>1.8810769230769226}, {:data0=>\"18\", :data1=>1.534346153846153}, {:data0=>\"19\", :data1=>1.187615384615384}, {:data0=>\"20\", :data1=>0.8408846153846152}, {:data0=>\"21\", :data1=>0.4941538461538455}, {:data0=>\"22\", :data1=>0.14742307692307666}, {:data0=>\"23\", :data1=>-0.19930769230769219}, {:data0=>\"24\", :data1=>-0.5460384615384619}, {:data0=>\"25\", :data1=>-0.8927692307692308}]>}, :extension=>[]}>"
309
+ "#<Nyaplot::Frame:0x007fedec32d7c8 @properties={:panes=>[#<Nyaplot::Plot:0x007feded130960 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fedec32dcc8 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"2f6a05eb-5092-4677-9bec-ac912016ebc9\"}, @xrange=[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], @yrange=[0, 7.428769230769229]>], :options=>{:width=>700, :xrange=>[\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", \"25\"], :yrange=>[0, 7.428769230769229]}}>], :data=>{\"2f6a05eb-5092-4677-9bec-ac912016ebc9\"=>#<Nyaplot::DataFrame:0x007feded130208 @name=\"2f6a05eb-5092-4677-9bec-ac912016ebc9\", @rows=[{:data0=>\"1\", :data1=>7.428769230769229}, {:data0=>\"2\", :data1=>7.082038461538459}, {:data0=>\"3\", :data1=>6.73530769230769}, {:data0=>\"4\", :data1=>6.388576923076921}, {:data0=>\"5\", :data1=>6.041846153846151}, {:data0=>\"6\", :data1=>5.695115384615383}, {:data0=>\"7\", :data1=>5.348384615384614}, {:data0=>\"8\", :data1=>5.001653846153845}, {:data0=>\"9\", :data1=>4.654923076923075}, {:data0=>\"10\", :data1=>4.308192307692306}, {:data0=>\"11\", :data1=>3.961461538461537}, {:data0=>\"12\", :data1=>3.6147307692307677}, {:data0=>\"13\", :data1=>3.267999999999999}, {:data0=>\"14\", :data1=>2.92126923076923}, {:data0=>\"15\", :data1=>2.5745384615384603}, {:data0=>\"16\", :data1=>2.2278076923076915}, {:data0=>\"17\", :data1=>1.8810769230769226}, {:data0=>\"18\", :data1=>1.534346153846153}, {:data0=>\"19\", :data1=>1.187615384615384}, {:data0=>\"20\", :data1=>0.8408846153846152}, {:data0=>\"21\", :data1=>0.4941538461538455}, {:data0=>\"22\", :data1=>0.14742307692307666}, {:data0=>\"23\", :data1=>0}, {:data0=>\"24\", :data1=>0}, {:data0=>\"25\", :data1=>0}]>}, :extension=>[]}>"
310
310
  ]
311
311
  },
312
312
  "metadata": {},
@@ -328,7 +328,7 @@
328
328
  },
329
329
  {
330
330
  "cell_type": "code",
331
- "execution_count": 10,
331
+ "execution_count": 7,
332
332
  "metadata": {
333
333
  "collapsed": false
334
334
  },
@@ -349,6 +349,15 @@
349
349
  "source": [
350
350
  "IRuby.display IRuby.table([(1..y.size).to_a.reverse, t.trend.reverse])"
351
351
  ]
352
+ },
353
+ {
354
+ "cell_type": "code",
355
+ "execution_count": null,
356
+ "metadata": {
357
+ "collapsed": true
358
+ },
359
+ "outputs": [],
360
+ "source": []
352
361
  }
353
362
  ],
354
363
  "metadata": {
@@ -41,6 +41,13 @@ module LinearRegressionTrend
41
41
  @x_values.map { |x| predict(x) }
42
42
  end
43
43
 
44
+ def forecast_next(n = 1)
45
+ start_val = @size + 1
46
+ stop_val = @size + n.to_i
47
+
48
+ (start_val..stop_val).to_a.map { |x| predict(x) }
49
+ end
50
+
44
51
  # Get the Y value for any given X value
45
52
  # from y = mx + b, or
46
53
  # y = slope * x + intercept
@@ -48,7 +55,8 @@ module LinearRegressionTrend
48
55
  predicted = @slope * x + @intercept
49
56
 
50
57
  return 0 if predicted < 0 and @no_negs
51
- return predicted
58
+
59
+ predicted
52
60
  end
53
61
 
54
62
  # Get the "next" value if the sequence
@@ -1,3 +1,3 @@
1
1
  module LinearRegressionTrend
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.9"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "pry", "~> 0.10.1"
24
- spec.add_development_dependency "rspec", "~> 3.3"
25
- spec.add_development_dependency "guard-rspec", "~> 4.6"
26
- spec.add_development_dependency "iruby", "~> 0.2.7"
27
- spec.add_development_dependency "nyaplot", "~> 0.1.5"
28
- spec.add_development_dependency "awesome_print", "~> 1.2"
22
+ spec.add_development_dependency "rake", "~> 13.0"
23
+ spec.add_development_dependency "pry", "~> 0.13.1"
24
+ spec.add_development_dependency "rspec", "~> 3.9"
25
+ spec.add_development_dependency "guard-rspec", "~> 4.7.3"
26
+ spec.add_development_dependency "cztop", "~> 0.14.1"
27
+ spec.add_development_dependency "iruby", "~> 0.4.0"
28
+ spec.add_development_dependency "nyaplot", "~> 0.1.6"
29
+ spec.add_development_dependency "awesome_print", "~> 1.8.0"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linear_regression_trend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Fortuna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,98 +30,112 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.10.1
47
+ version: 0.13.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.1
54
+ version: 0.13.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.3'
61
+ version: '3.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.3'
68
+ version: '3.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4.6'
75
+ version: 4.7.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '4.6'
82
+ version: 4.7.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: cztop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.14.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: iruby
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.2.7
103
+ version: 0.4.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.2.7
110
+ version: 0.4.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: nyaplot
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.1.5
117
+ version: 0.1.6
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.1.5
124
+ version: 0.1.6
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: awesome_print
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '1.2'
131
+ version: 1.8.0
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '1.2'
138
+ version: 1.8.0
125
139
  description: A simple library for calculating linear trend regressions against a time
126
140
  series data set. See README for more info
127
141
  email:
@@ -165,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
179
  version: '0'
166
180
  requirements: []
167
181
  rubyforge_project:
168
- rubygems_version: 2.4.5
182
+ rubygems_version: 2.6.14.3
169
183
  signing_key:
170
184
  specification_version: 4
171
185
  summary: A library for calculating linear trend regressions against a time series