Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created September 1, 2016 08:49
Show Gist options
  • Select an option

  • Save joaofig/7537e92ca6110acad31c43c82d5ef97c to your computer and use it in GitHub Desktop.

Select an option

Save joaofig/7537e92ca6110acad31c43c82d5ef97c to your computer and use it in GitHub Desktop.
Linear regression model outlier detector
public bool IsOutlier(double radius, double x, double y)
{
double yHat = GetValue( x );
double studentizedResidue = Math.Abs(y - yHat) / Math.Sqrt( GetResidualVariance() );
return studentizedResidue > radius;
}
private double GetResidualVariance()
{
return GetRSS() / (count - 2);
}
private double GetRSS()
{
return beta * beta * sumXX
-2 * beta * sumXY
+2 * alpha * beta * sumX
+sumYY
-2 * alpha * sumY
+alpha * alpha * count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment