-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional linear regression functions #21630
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -590,6 +590,41 @@ Statistical Aggregate Functions | |||||||
Returns linear regression slope of input values. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_avgx(y, x) -> double | ||||||||
|
||||||||
Returns the average of the independent value in a group. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_avgy(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Returns the average of the dependent value in a group. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_count(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Returns the number of non-null pairs of input values. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_r2(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Returns the coefficient of determination of the linear regression. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_sxy(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Returns the sum of the product of the dependent and independent values in a group. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_syy(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Returns the sum of the squares of the dependent values in a group. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: regr_sxx(y, x) -> double | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks! I just now did a new pull and local build of the doc and everything looks good! Updating my review to Approve for the docs. |
||||||||
|
||||||||
Returns the sum of the squares of the independent values in a group. ``y`` is the dependent | ||||||||
value. ``x`` is the independent value. | ||||||||
|
||||||||
.. function:: skewness(x) -> double | ||||||||
|
||||||||
Returns the skewness of all input values. | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.operator.aggregation; | ||
|
||
import com.facebook.presto.common.block.Block; | ||
import com.facebook.presto.common.type.StandardTypes; | ||
import com.google.common.collect.ImmutableList; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
import static com.facebook.presto.block.BlockAssertions.createDoubleSequenceBlock; | ||
|
||
public abstract class AbstractTestDoubleRegrAggregationFunction | ||
extends AbstractTestAggregationFunction | ||
{ | ||
@Override | ||
public Block[] getSequenceBlocks(int start, int length) | ||
{ | ||
return new Block[] {createDoubleSequenceBlock(start, start + length), createDoubleSequenceBlock(start + 2, start + 2 + length)}; | ||
} | ||
|
||
@Override | ||
protected List<String> getFunctionParameterTypes() | ||
{ | ||
return ImmutableList.of(StandardTypes.DOUBLE, StandardTypes.DOUBLE); | ||
} | ||
|
||
@Test | ||
public void testSinglePosition() | ||
{ | ||
testAggregation(getExpectedValue(0, 2), getSequenceBlocks(0, 2)); | ||
} | ||
|
||
@Test | ||
public void testNonTrivialResult() | ||
{ | ||
testNonTrivialAggregation(new Double[] {1.0, 2.0, 3.0, 4.0, 5.0}, new Double[] {1.0, 4.0, 9.0, 16.0, 25.0}); | ||
testNonTrivialAggregation(new Double[] {1.0, 4.0, 9.0, 16.0, 25.0}, new Double[] {1.0, 2.0, 3.0, 4.0, 5.0}); | ||
} | ||
|
||
protected abstract void testNonTrivialAggregation(Double[] y, Double[] x); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.