pip install my_package
pip install https://github.com/DHI/{repo}/archive/main.zip
"""K-means clustering."""
class KMeans(_BaseKMeans):
"""K-Means clustering.
Parameters
----------
n_clusters : int, default=8
The number of clusters to form as well as the number of
centroids to generate.
Examples
--------
>>> X = np.array([[1, 2], [1, 4], [1, 0],
... [10, 2], [10, 4], [10, 0]])
>>> kmeans = KMeans(n_clusters=2, random_state=0, n_init="auto").fit(X)
>>> kmeans.labels_
array([1, 1, 1, 0, 0, 0], dtype=int32)
>>> from sklearn.cluster import KMeans
>>> help(KMeans)
class KMeans(_BaseKMeans)
| KMeans(n_clusters=8, *, init='k-means++', n_init='warn')
|
| K-Means clustering.
|
| Parameters
| ----------
| n_clusters : int, default=8
. . .
From Python 3.6, type hints can be used in addition to the type in the docstring.
def remove_outlier(data:pd.DataFrame, column:str, threshold:float=3) -> pd.DataFrame:
"""Remove outliers from a dataframe.
Parameters
----------
data : pd.DataFrame
Dataframe to remove outliers from.
column : str
Column to remove outliers from.
threshold : float, optional
Number of standard deviations to use as threshold, by default 3
Using code without documentation is hard, but using code with wrong documentation is even harder.
How can you make sure that the documentation is correct?
The answer is the doctest
module built in to the Python standard library.
Tip
The extensive standard library is why Python is described as a language with “batteries included!”
Input, output examples in docstrings are run as tests.
install mkdocstrings
$ pip install mkdocstrings[python]
Install theme, e.g. material
$ pip install mkdocs-material
Add plugin to mkdocs.yml (see above)
Create index.md
in docs folder
Run mkdocs serve
to view locally
https://dhi.github.io/<repository>/
robots.txt
file to the root of the websitemkdocs
to generate API documentationPython package development