Enable ruff NPY002 rule (#11336)

This commit is contained in:
Maxim Smolskiy
2024-04-01 22:39:31 +03:00
committed by GitHub
parent 39daaf8248
commit f8a948914b
9 changed files with 32 additions and 25 deletions

View File

@@ -187,7 +187,8 @@ def main():
tree = DecisionTree(depth=10, min_leaf_size=10)
tree.train(x, y)
test_cases = (np.random.rand(10) * 2) - 1
rng = np.random.default_rng()
test_cases = (rng.random(10) * 2) - 1
predictions = np.array([tree.predict(x) for x in test_cases])
avg_error = np.mean((predictions - test_cases) ** 2)

View File

@@ -55,12 +55,12 @@ TAG = "K-MEANS-CLUST/ "
def get_initial_centroids(data, k, seed=None):
"""Randomly choose k data points as initial centroids"""
if seed is not None: # useful for obtaining consistent results
np.random.seed(seed)
# useful for obtaining consistent results
rng = np.random.default_rng(seed)
n = data.shape[0] # number of data points
# Pick K indices from range [0, N).
rand_indices = np.random.randint(0, n, k)
rand_indices = rng.integers(0, n, k)
# Keep centroids as dense format, as many entries will be nonzero due to averaging.
# As long as at least one document in a cluster contains a word,

View File

@@ -289,12 +289,13 @@ class SmoSVM:
if cmd is None:
return
for i2 in np.roll(self.unbound, np.random.choice(self.length)):
rng = np.random.default_rng()
for i2 in np.roll(self.unbound, rng.choice(self.length)):
cmd = yield i1, i2
if cmd is None:
return
for i2 in np.roll(self._all_samples, np.random.choice(self.length)):
for i2 in np.roll(self._all_samples, rng.choice(self.length)):
cmd = yield i1, i2
if cmd is None:
return