Home

linregress

linregress is a function in SciPy’s statistics module that performs ordinary least squares linear regression on two 1-D arrays, x and y. It fits a line of the form y = slope * x + intercept to the data and returns several statistics that describe the fit.

Inputs and handling: x and y must be numeric, 1-D, and of equal length with at least

Outputs and interpretation: The function returns a LinregressResult, typically accessed as a small, six-element tuple or

Method and limitations: Calculations follow standard simple linear regression formulas. Slope is derived from the covariance

two
data
pairs.
Pairs
containing
NaN
values
are
ignored,
effectively
performing
pairwise
deletion.
The
function
assumes
a
linear
relationship
between
x
and
y.
as
named
attributes:
slope,
intercept,
rvalue,
pvalue,
stderr,
and
intercept_stderr.
The
slope
and
intercept
define
the
best-fit
line.
rvalue
is
the
Pearson
correlation
coefficient
between
x
and
y,
reflecting
the
strength
and
direction
of
the
linear
association.
pvalue
tests
the
null
hypothesis
that
the
slope
is
zero
(no
linear
relationship);
by
default
the
p-value
is
two-sided.
stderr
is
the
standard
error
of
the
slope,
and
intercept_stderr
is
the
standard
error
of
the
intercept,
providing
uncertainty
estimates
for
the
fitted
parameters.
of
x
and
y
relative
to
the
variance
of
x;
intercept
is
adjusted
to
pass
through
the
mean
values.
The
p-value
is
based
on
a
t-statistic
with
n−2
degrees
of
freedom.
The
function
is
not
robust
to
outliers
and
assumes
a
linear
relationship;
results
should
be
interpreted
within
the
context
of
the
data.