PLSQL - prediction of linear regression.
Hey, Chaps.
I'm puzzled! I hope you can help...
SQL
WITH tblData AS ( SELECT 1 AS known_ys, TO_DATE('01/01/2015', 'DD/MM/YYYY') AS known_xs FROM DUAL UNION ALL SELECT 2, TO_DATE('02/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL SELECT 3, TO_DATE('03/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL SELECT 4, TO_DATE('04/01/2015', 'DD/MM/YYYY') FROM DUAL ) SELECT * FROM tblData ;
What I'm trying to do, is provide by using my known_ys what happens on 01/05/2015 (known_xs). The answer is of course 5
In Excel, I'd FORECAST ("01/05/2015", known_ys, knownxs) and it spits out 5. Unfortunately my data are so large in Excel (and other stats packages) I need to push the calculation in the Oracle server.
I spent 30 minutes to read the Sub and get more confused -anyone know (and ideally give an example) how to proceed?
Created this just now that works but it is a little "garbage."
WITH tblData AS ( SELECT 1 AS known_ys, TO_DATE('01/01/2015', 'DD/MM/YYYY') AS known_xs FROM DUAL UNION ALL SELECT 2, TO_DATE('02/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL SELECT 4, TO_DATE('03/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL SELECT 8, TO_DATE('04/01/2015', 'DD/MM/YYYY') FROM DUAL ) SELECT last_value, REGR_SLOPE(known_ys, (known_xs - SYSDATE)) AS slope, last_value + REGR_SLOPE(known_ys, (known_xs - SYSDATE)) AS nxt_value FROM tblData, (SELECT FIRST_VALUE(known_ys) OVER (PARTITION BY 1 ORDER BY known_xs DESC) AS last_value FROM tblData) GROUP BY last_value ;
Something like this (no PL/SQL required):
WITH tblData AS
(
SELECT 1 AS known_ys, TO_DATE('01/01/2015', 'DD/MM/YYYY') AS known_xs DE DOUBLE UNION ALL
SELECT 2, TO_DATE (FEBRUARY 1, 2015 ',' DD/MM/YYYY "") OF THE WHOLE UNION DOUBLE
CHOOSE 3, TO_DATE (MARCH 1, 2015 ',' DD/MM/YYYY ') FROM DUAL UNION ALL
SELECT 4, TO_DATE (APRIL 1, 2015 ',' DD/MM/YYYY ') FROM DUAL
)
SELECT REGR_INTERCEPT (known_ys, known_xs - TO_DATE (May 1, 2015 ',' DD/MM/YYYY ')) x
OF tblData
;
SQL > /.
X
----------
5
http://docs.Oracle.com/database/121/SQLRF/functions165.htm#SQLRF00696
REGR_INTERCEPT predicted where the graph will cross the axis, so I subtracted TO_DATE(5/01/2015,'DD/MM/YYYY') get a data type number, 0 being equivalent to the date that I was interested.
REGR_ features * supports window clauses, you can perform calculations on multiple series of data in the same table with a single pass in the data.
Tags: Database
Similar Questions
-
Hello
I need to make a non-linear regression in LabWindows but I don't not eat in order to find a function for that...
I know that there s for linear regression (LinFit) function, but not could find one for non-linear... Is there such function CVI?
Or maybe someone has an algorithm to do this...
Any help is very appreciated!
Thank you
ZZippo
Hi ZZippo,
as long as you have the AdvancedAnalysisLibrary there are three related functions for nonlinear curve fit:
NonLinearFit (-);
NonLinearFitWithMaxIters (, 100);
NonLinearFitWithWeight (, 100);
the last two offer more options than the first.
If you do not have this library (i.e. the full version of the CVI instead of the basic version), you can use the following implementation of Levenberg-Marquardt:http://www.ics.forth.gr/~lourakis/levmar/
-
Line of best fit / linear regression
I am trying ot get a line to better adapt to a set of data in oracle
Let's say I have the following dataset.
Since there are a lot of 0 in the terms I want to ignore these terms
Use only terms that have values for a line of regression.
Any help will be appreciated.
Thank you.
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64biTERMS Count TERM_0801 78 TERM_0802 58 TERM_0803 0 TERM_0804 82 TERM_0805 0 TERM_0806 0 TERM_0807 32 TERM_0808 0 TERM_0901 92 TERM_0902 0 TERM_0903 0 TERM_0904 56 TERM_0905 0 TERM_0906 0 TERM_0907 0 TERM_0908 0 TERM_1001 85 TERM_1002 0 TERM_1003 0 TERM_1004 67
Published by: Chloe_19 on July 24, 2012 23:14Maybe:
with the_data(terms,count) as (select 'TERM_0801',78 from dual union all select 'TERM_0802',58 from dual union all select 'TERM_0803',0 from dual union all select 'TERM_0804',82 from dual union all select 'TERM_0805',0 from dual union all select 'TERM_0806',0 from dual union all select 'TERM_0807',32 from dual union all select 'TERM_0808',0 from dual union all select 'TERM_0901',92 from dual union all select 'TERM_0902',0 from dual union all select 'TERM_0903',0 from dual union all select 'TERM_0904',56 from dual union all select 'TERM_0905',0 from dual union all select 'TERM_0906',0 from dual union all select 'TERM_0907',0 from dual union all select 'TERM_0908',0 from dual union all select 'TERM_1001',85 from dual union all select 'TERM_1002',0 from dual union all select 'TERM_1003',0 from dual union all select 'TERM_1004',67 from dual ) select regr_slope(cnt,rn) r_slope, regr_intercept(cnt,rn) r_intercept, regr_count(cnt,rn) r_count, regr_r2(cnt,rn) r_r2, regr_avgx(cnt,rn) r_avgx, regr_avgy(cnt,rn) r_avgy, regr_sxx(cnt,rn) r_sxx, regr_syy(cnt,rn) r_syy, regr_sxy(cnt,rn) r_sxy from (select count cnt,row_number() over (order by terms) rn from the_data ) where cnt != 0 R_SLOPE | R_INTERCEPT | R_COUNT | R_R2 | R_AVGX | R_AVGY | R_SXX | R_SYY | R_SXY 0,241071428571429 | 66,5803571428571 | 8 | 0,00723884549185754 | 9 | 68,75 | 336 | 2697,5 | 81
Concerning
Etbin
-
Is it possible to get the R2 of the nonlinear function made in Labview?
Do corospond "residue" of R2?Use of vi of goodness of the Fit in the curve in advanced editing Palette. The aid must be explicit.
See you soon,.
McDuff
-
How to choose between a linear and logistic model in the regression of the glm?
Hello
documentation, I learned that the algorithm of glm for the linear regression model supports linear and logistic regression. However, I can't find any switch or parameter that selects one or the other. How can I tell ODM what kind of regression I want?
Thanks in advance!
Hi Bernd,
Here are some additional tips.
Hope this is what you are looking for.
THX, mark
If you specify a classification, it is logistics. If you specify the regression, linear regression. Logistic regression only we offer is the variance and binary logistic regression canonical link. If you have a target with values in [0,..., 100] and you want to use logistic regression of glm, and then create a view that selects a share point, for example, 50. There is no parameter variation algorithm.
Create view bin_v as
to select which target< 50="" then="" 0="" else="" 1="" end="">
var1, var2,... varn my_data.
Otherwise if you want linear regression, specify regression and let the data it is.
-
How to use BIEE to analysis of the data. as the regression
I want to know information about the feature of oracle BIEE. and I need to regression analysis or other logistical methods in my data.how to solve it thanks!Hi user,
Take a look: http://kpipartners.blogspot.com/2009/04/linear-regression.html
Thank you
Saichand.v -
Analysis of capacity Vcops algorithms
Hello
I would like to ask if anyone knows what are the specific algorithms used by Vcops to implement the predictive ability. Are they simple algorithms based on regression analysis for example or something more advanced, such as combined neural networks, etc.?
Thank you!
Its much more than just linear regression - there are at least 8 algorithms that work and are in competition to interepret data:
-
Forecasting functions - orders
Is there a function I could use in a sql statement to predict orders for the same months in 2013 according to the planned 2012 data? Thank you.
Full month
01/01/2012 4 077
01/02/2012 4 044
01/03/2012 5 188
01/04/2012 5 244
01/05/2012 5 741
01/06/2012 6 284
01/07/2012 6 447
01/08/2012 6 645
01/09/2012 6 102
01/10/2012 6 313
01/11/2012 5 973
01/12/2012 5 197
01/01/2013 5 138Hello
989618 wrote:
Is there a function I could use in a sql statement to predict orders for the same months in 2013 according to the planned 2012 data?Of course, there are many functions.
A common way to forecast includes regression functions, like REGR_INTERCEPT and REGR_SLOPE, like this:WITH got_d AS ( SELECT month , complete , month - DATE '2000-01-01' AS d FROM table_x -- WHERE ... -- If you want any filtering, put it here ) , regr_results AS ( SELECT REGR_SLOPE (complete, d) AS slope , REGR_INTERCEPT (complete, d) AS intercept FROM got_d ) , all_months AS ( SELECT ADD_MONTHS ( DATE '2011-12-01' , LEVEL ) AS month FROM dual CONNECT BY LEVEL <= 24 ) SELECT m.month , d.complete , (r.slope * (m.month - DATE '2000-01-01')) + r.intercept AS estimated FROM all_months m LEFT OUTER JOIN got_d d ON d.month = m.month CROSS JOIN regr_results r ORDER BY m.month ;
The 'magic' date of 1 January 2000 is an arbitrary point where we can count the days. You can use any DATE (before, during or after the period covered by the request), just be consistent in both places where you have to use it.
Linear regression is to find a straight line such that none of the actual data points are far from the line; That's what the Group functions calculate.
In the above query, we will extend this straight line in the main query, such that we display a few points on the line of the beach of the actual data.Thank you.
Full month
01/01/2012 4 077
01/02/2012 4 044
01/03/2012 5 188...If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.
See the FAQ forum {message identifier: = 9360002} -
Building my projection prediction by using the function.
It seems to work except that it clearly lacks the notion of seasonality. Someone at - he really understand the calc and what settings can control something like that.
Right now if I load several years. He sees just as a long line and completely misses the waves that occur during the year.You can only use the seasonality on the parameters of linear regression (LR) calculations.
Then, you add a variable (12) after LR to seasonality throughout the year.
-
HP 10BII + statistics PN questions?
After getting weird with the HP 10BII PN + statistics (unexpected) results, I dug out some old books with sample data and checked I get different results on the 10BII + on other machines.
Examples of data of HP - 34 c Manual (p. 38):
x / y: 696/1945, 994/1950, 1330/1955, 1512, 1960, 1965-1750, 2162/1970, 2243/1971, 2382/1972, 2482/1973.
I enter all 9 data and even on the 10BII +, I check the linear regression and then use:
RS-5, RS - K (Swap) to get the slope, m - HP 10BII + returns 0.01612 [should be 61.1612]
RS-6, RS - K (Swap) to get the y originally b - HP 10BII + return 1934.1695 [should be-118, 290.6295]
Maybe I'm missing something basic, but the 10BII + gives the answers that appear all just bad. I checked the "should be" translated on a HP - 34 c, WP 34s and HP - 15 c and they agree.
I read (and reread) the 10BII User Guide + to ensure the correct keystrokes, and also made C.ALL to ensure no conflict of memory (e.g. too many CFlows, etc.). Curiously, linear estimates appear to be OK when I interpolate w/samples.
What happens to Tim?
but here's an interesting result...
If the order of the columns is changed (x and y values are reversed)...
X Y
[[1945 696.]
[1950 994.]
[1955 1330.]
[1960 1512.]
[1750 1965.]
[2162 1970.]
[1971 2243.]
[1972 2382.]
[1973 2482.]]Now run a linear regression model... and the result is...
'(-118242.173643) +(61.1364341085*X)'
the issue seems to be the way in which data is entered into the calculator...
-
PREMIUM HP: HP PREMIUM: improve 2 VAR APP with interception of axis Y
Here the desired improvement:
With MS Excel, in linear regression is chosen, it is possible to define the intercept with the y-axis.
Its is interesting when you know that the correct answer is y = M * X (for example: d = V * t or A = k * C (beer-Lambert),...)
So, I suggest to add this new setting with linear, polynomial, and exponential regression.
Thank you.
Simpler: F1 (X) = Statistics_2VAR Sigma (XY) / Statistics_2VAR. Sigma(x2)
Then 'User Defined' and fit: F1 (X)
-
I'm relatively new to VBS and difficulties to come with a solution. I have a sine wave which I need to do some calculations on. I need to cut a window each cycle to +-1000N. To calculate the linear regression on each of these sections. Than the average slopes that positive/negative. I'm looking to produce 2 plots, one to the positive terminal and the other for negative in the end. So far, I was able to cut the data and insert the NoValues. I'm looking for assistance under each of the linear regression between the NoValues data sections.
Dim oChn, K, currentValue lastValue, I have
Calculate call ("Ch(""[1]/Total)" "") = Ch(""[1]/Filtered_Total_TR_Load"") + CTNV (Ch(""[1]/Filtered_Total_TR_Load"") > 1000) ", NULL, NULL," ")"
Calculate call ("Ch(""[1]/Total)" "") = Ch(""[1]/Total"") + CTNV (Ch(""[1]/Filtered_Total_TR_Load"")<>lastValue = 0
Set oChn = data. GetChannel ("Total")
For K = 1 To oChn.Size
currentValue = oChn (K)If (IsNull (currentValue)) then
oChn (K) = lastValueOn the other
lastValue = currentValueEnd If
Next
Hi mindmaster,.
What version of DIAdem do you use? If you have DIAdem 2015, then you can use the new ChnEvent... functions () to find the beaches of the line of all your tracks positive and negative. From there you can loop over each of them, extraction ranging from the line to a new channel and the execution of the function of linear regression from the ANALYSIS Panel on this subset extracted to calculate the slope of this cycle. You can then save the values of slope in the new 'Cycle number' and 'Positive slope' channels 'negative slope", which you can then average on all cycles.
Even if you have DIAdem 2014, I can show you the pre-release version hidden in the ChnEvent... functions () which will allow the first step of the preceding analysis. If you have an even older version of DIAdem, you must use the ChnFind() function in a loop to determine the row of slopes of positive and negative of each cycle ranges.
Brad Turpin
Tiara Product Support Engineer
National Instruments
-
Function MATLAB Detrend in DIAdem
Hello
I'm trying to pre process certain data for the treatment of the fft in Matlab, I would use the Detrend function and I was wondering if it's something similar in tiara.
I use DIAdem 2012
Thank you
Essentially in Matlab Detrend on a simple matrix subtracts the linear regression of each data value line in a table.
For example, if you have a table a [2,3,5,7,5] and you had to he relaxes in MatLab, it would equal detA [-04 - 0.4, 0.6, 1.6, -1,4].
If you subtract A detA you will get A-detA [2.4, 3.4, 4.4, 5.4, 6.4] which is exaclty same find the linera for optimal adjustment to A line.
-
noise of biaxial precision accelerometer
Hello
I do calibration on accelerometer analog biaxial acceleration providing the angle of the sensor measurement.
Based on spec sheet of the analog, the sensor should be in equation linear V = Ka + B
V = output voltage
K = linear sensitivity
a = acceleration of axis
B = polarization voltage.
However, I turn the sensor with a known angle, I get the tension. Draw the graph of the voltage compared to acceleration, I'm not able to obtain a linear curve V = Ka + B, but not linear graph.
How can I determine the non-linear error and the resolution on the graph newly traced in labview? I collected data. and I want to do a regression analysis. How can I do it in labview?
After getting the non-linear regression, how will I know my new model (new equation) improved in error and resolution?
Can anyone help ple
your kindness is much appreciated
Concerning
OK, this description makes sense. Probably nothing wrong with your Setup. If you want to create an equation using data points you acquired during the tilt in the X direction and Y? The function Arctan not serve the purpose? Divide all values of all values of Ay Ax and feed the ATAN function table. I used three-point line in the following example, and the output is linear.
-
I use the R client to connect to oracle. my local computer has 1 GB of RAM and server is superior to it. My data is huge and I do not want the functions of R as lm. But I don't know that makes data load on the client and then treat the client or my service running on the server?
If 2' th is true (it's good for me) made any other algorithm to do R and the algorithms of ore?
Published by: Nasiri Mahdi on 23 February 2013 01:16Nguyen,
Both approaches are supported. It really depends on what you're trying to do. For linear regression, you can try ore.lm or ore.odmGLM. If you build models partitioned on a large data, you can try ore.groupApply lm inside. If you do not yet take a look at the examples that we have in our 'Learning R Series' [url http://www.oracle.com/technetwork/database/options/advanced-analytics/r-enterprise/index.html] here.
Denis
Maybe you are looking for
-
P7-1299cb: no sound for desktop computer after update to windows 10
I have a desktop computer that used to run windows 7 and finally decided to upgrade to windows 10. Update had no problems, but I have no sound. I tried to update the driver through windows update and HP support assistant, both did not acknowledge t
-
I had a problem with my HP Chromebook intermittently keys work only not - y, m, n, etc. They would work, then not work, and it was very frustrating esp to log in b/c I couldn't get my typed password. I thought that I would need a new keyboard, but m
-
Change other printing settings does not resolve the problem. Firefox is perfectly up to date.
-
I picked up the T400 I mentioned in a previous post for $100, apparently needs a hard drive. It's a RH4 7417 It starts and has Windows Vista installed, but it does a scan of material comes up with something about bad sectors on the hard drive. (1) ca
-
Pavilion G6 1d73u5: Pavilion G6 CPU upgrate
Hello! I have a Pavilion G6 laptop(g6-1d73u5) with processor i3 of 2350 m altitude. I need an upgrate the processor that I use mainly for audio and encoding. I found a better processor i5 cpu 2430 M for about $50 and think it would be quite better >M