@@ -1135,7 +1135,7 @@ def linear_regression(x, y, /, *, proportional=False):
1135
1135
>>> noise = NormalDist().samples(5, seed=42)
1136
1136
>>> y = [3 * x[i] + 2 + noise[i] for i in range(5)]
1137
1137
>>> linear_regression(x, y) #doctest: +ELLIPSIS
1138
- LinearRegression(slope=3.09078914170 ..., intercept=1.75684970486 ...)
1138
+ LinearRegression(slope=3.17495 ..., intercept=1.00925 ...)
1139
1139
1140
1140
If *proportional* is true, the independent variable *x* and the
1141
1141
dependent variable *y* are assumed to be directly proportional.
@@ -1148,7 +1148,7 @@ def linear_regression(x, y, /, *, proportional=False):
1148
1148
1149
1149
>>> y = [3 * x[i] + noise[i] for i in range(5)]
1150
1150
>>> linear_regression(x, y, proportional=True) #doctest: +ELLIPSIS
1151
- LinearRegression(slope=3.02447542484 ..., intercept=0.0)
1151
+ LinearRegression(slope=2.90475 ..., intercept=0.0)
1152
1152
1153
1153
"""
1154
1154
n = len (x )
@@ -1279,9 +1279,11 @@ def from_samples(cls, data):
1279
1279
1280
1280
def samples (self , n , * , seed = None ):
1281
1281
"Generate *n* samples for a given mean and standard deviation."
1282
- gauss = random .gauss if seed is None else random .Random (seed ).gauss
1283
- mu , sigma = self ._mu , self ._sigma
1284
- return [gauss (mu , sigma ) for _ in repeat (None , n )]
1282
+ rnd = random .random if seed is None else random .Random (seed ).random
1283
+ inv_cdf = _normal_dist_inv_cdf
1284
+ mu = self ._mu
1285
+ sigma = self ._sigma
1286
+ return [inv_cdf (rnd (), mu , sigma ) for _ in repeat (None , n )]
1285
1287
1286
1288
def pdf (self , x ):
1287
1289
"Probability density function. P(x <= X < x+dx) / dx"
0 commit comments