-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b18670
commit 3935015
Showing
2 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
from numpy.typing import NDArray | ||
|
||
from lkmeans import LKMeans | ||
|
||
p_values = [0.5, 1, 2, 5] | ||
|
||
|
||
def get_data() -> NDArray: | ||
return np.random.uniform(-10,10, size=(100, 50)) | ||
|
||
|
||
@pytest.mark.api | ||
@pytest.mark.parametrize("p", p_values) | ||
def test_segment_slsqp_calculation(p) -> None: | ||
data = np.random.uniform(-10,10, size=(100, 50)) | ||
@pytest.mark.parametrize('p', p_values) | ||
def test_general_processing(p: float | int) -> None: | ||
data = get_data() | ||
|
||
lkmeans = LKMeans(n_clusters=2, p=p) | ||
lkmeans.fit_predict(data) | ||
print('Inertia', lkmeans.inertia_) | ||
print('Centers', lkmeans.cluster_centers_) | ||
|
||
|
||
def convert_from_ndarray(data: NDArray, type: str) -> list | pd.DataFrame | pd.Series: | ||
if type == 'list': | ||
return data.tolist() | ||
if type == 'frame': | ||
return pd.DataFrame(data.tolist()) | ||
if type == 'series': | ||
return pd.Series(data.tolist()) | ||
|
||
|
||
@pytest.mark.api | ||
@pytest.mark.parametrize('type', ['list', 'frame', 'series']) | ||
def test_input_data_conversion(type: str) -> None: | ||
data = get_data() | ||
data = convert_from_ndarray(data, type) | ||
|
||
lkmeans = LKMeans(n_clusters=2, p=2) | ||
lkmeans.fit_predict(data) | ||
print('Inertia', lkmeans.inertia_) | ||
print('Centers', lkmeans.cluster_centers_) |