Skip to content

Commit 3214c28

Browse files
committed
docs: set random_state for "introductory" k-means (Data Science)
1 parent 9328da7 commit 3214c28

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/data-science/algorithms/index.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,16 @@ X = [
183183
]
184184

185185
# use k-means to find customer segments
186-
model = KMeans(n_clusters=2)
186+
model = KMeans(n_clusters=2, random_state=42) # (1)!
187187
segments = model.fit_predict(X)
188188

189189
print(segments)
190190
```
191191

192+
1. Setting the `random_state` parameter ensures that you get the same results
193+
when executing the code. Reproducibility is discussed more in-depth in
194+
upcoming chapters.
195+
192196
```title=">>> Output"
193197
[1 0 1 0 1]
194198
```

0 commit comments

Comments
 (0)