Skip to content

Commit aee8895

Browse files
committed
Test_Pedro
1 parent 9599da8 commit aee8895

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

test/test_Chi.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
4+
def test_chi_squared_test():
5+
from Chi import chi_squared_test
6+
import pandas as pd
7+
import scipy.stats as stats
8+
import pytest
9+
import numpy as np
10+
# Create a sample DataFrame
11+
data = {'feature': ['A', 'B', 'C', 'D', 'E'],
12+
'target': np.random.randint(2, size=5)}
13+
df = pd.DataFrame(data)
14+
15+
# Perform the chi-squared test
16+
chi2, p = chi_squared_test(df, 'feature', 'target')
17+
18+
# Verify the results
19+
assert isinstance(chi2, float)
20+
assert isinstance(p, float)
21+
assert chi2 == pytest.approx(5.0, rel=1e-3)
22+
assert p == pytest.approx(0.287, rel=0.2872974951836458)
23+
24+
25+
26+
27+
28+

test/test_balance.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
from balance import balance_binary_target
3+
4+
import pytest
5+
import pandas as pd
6+
import numpy as np
7+
from imblearn.over_sampling import SMOTE
8+
import math
9+
10+
def test_balance_binary_target_min_ratio():
11+
# Create a sample DataFrame with a binary target variable.
12+
data = {'feature1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
13+
'feature2': [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
14+
'target': [1, 1, 1, 1, 0, 0, 0, 0, 0, 0]}
15+
df = pd.DataFrame(data)
16+
17+
# Perform the oversampling using SMOTE and minority_ratio of 0.4
18+
df_resampled = balance_binary_target(df, strategy='smote', minority_ratio=0.4)
19+
20+
# Verify that the resulting DataFrame has the expected ratio of minority samples
21+
ratio = df_resampled['target'].mean()
22+
assert math.isclose(ratio, 0.4, rel_tol=1)

test/test_smoth.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from smoth import _exponential_smooth
2+
import pandas as pd
3+
def test_exponential_smooth():
4+
# Define a sample dataset to test with
5+
data = pd.Series([1, 3, 4, 6, 7, 8, 9, 10])
6+
7+
# Apply the exponential smoothing function with alpha=0.3
8+
smoothed_data = _exponential_smooth(data, alpha=0.65)
9+
10+
# Check that the length of the smoothed data is the same as the original data
11+
assert len(smoothed_data) == len(data)
12+
13+
# Check that the first and last values of the smoothed data are the same as the original data
14+
assert smoothed_data.iloc[0] == data.iloc[0]
15+
assert smoothed_data.iloc[-1] == data.iloc[-1]
16+
17+
# Check that the smoothed data is less 'rigid' than the original data
18+
assert smoothed_data.diff().var() < data.diff().var()

0 commit comments

Comments
 (0)