first commit

This commit is contained in:
2025-11-12 11:34:34 +03:00
commit 29280f3e50
77 changed files with 272246 additions and 0 deletions
BIN
View File
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,67 @@
import numpy as np
from numpy.testing import assert_allclose
from scalers import StandardScaler, MinMaxScaler
def test_scalers_0():
with open('scalers.py', 'r') as file:
lines = ' '.join(file.readlines())
assert 'import numpy' in lines
assert 'import typing' in lines
assert lines.count('import') == 2
assert 'sklearn' not in lines
def test_scalers_1():
X_1 = np.random.uniform(-10, 20, (10, 20))
scaler = StandardScaler()
scaler.fit(X_1)
X_2 = scaler.transform(X_1)
assert type(X_2) == np.ndarray
assert_allclose(np.mean(X_2, axis=0), np.zeros(20), rtol=1e-05, atol=1e-08)
assert_allclose(np.std(X_2, axis=0), np.ones(20), rtol=1e-05, atol=1e-08)
def test_scalers_2():
X_1 = np.random.uniform(-10, 20, (10, 20))
scaler = MinMaxScaler()
scaler.fit(X_1)
X_2 = scaler.transform(X_1)
assert type(X_2) == np.ndarray
assert_allclose(np.min(X_2, axis=0), np.zeros(20), rtol=1e-05, atol=1e-08)
assert_allclose(np.max(X_2, axis=0), np.ones(20), rtol=1e-05, atol=1e-08)
def test_scalers_3():
X_1 = np.array([[0, 1, 0], [1, 1, 1], [0.3, 0.25, 0.5], [-0.5, -1, 4]])
X_2 = np.array([[0, 1, 0], [1, 1, 1], [0.3, 0.25, 0.5], [-0.5, -1, 4], [0, 0, 0], [2, -1, 0.5]])
scaler = StandardScaler()
scaler.fit(X_1)
X_3 = scaler.transform(X_2)
answer = np.array([[-0.36822985, 0.84119102, -0.88354126],
[ 1.47291939, 0.84119102, -0.2409658 ],
[ 0.18411492, -0.07647191, -0.56225353],
[-1.28880447, -1.60591014, 1.68676059],
[-0.36822985, -0.38235956, -0.88354126],
[ 3.31406862, -1.60591014, -0.56225353]])
assert type(X_3) == np.ndarray
assert_allclose(X_3, answer, rtol=1e-05, atol=1e-08)
def test_scalers_4():
X_1 = np.array([[0, 1, 0], [1, 1, 1], [0.3, 0.25, 0.5], [-0.5, -1, 4]])
X_2 = np.array([[0, 1, 0], [1, 1, 1], [0.3, 0.25, 0.5], [-0.5, -1, 4], [0, 0, 0], [2, -1, 0.5]])
scaler = MinMaxScaler()
scaler.fit(X_1)
X_3 = scaler.transform(X_2)
answer = np.array([[0.33333333, 1. , 0. ],
[1. , 1. , 0.25 ],
[0.53333333, 0.625 , 0.125 ],
[0. , 0. , 1. ],
[0.33333333, 0.5 , 0. ],
[1.66666667, 0. , 0.125 ]])
assert type(X_3) == np.ndarray
assert_allclose(X_3, answer, rtol=1e-05, atol=1e-08)
@@ -0,0 +1,22 @@
catboost==1.2.8
gdown==5.2.0
h5py==3.14.0
hyperopt==0.2.7
ipympl==0.9.7
ipywidgets==7.7.1
lightgbm==4.6.0
matplotlib-inline==0.1.7
matplotlib==3.10.0
numpy
pandas==2.2.2
pep8==1.7.1
plotly==5.24.1
pycodestyle==2.14.0
pytest==8.4.1
scikit-image==0.25.2
scikit-learn==1.6.1
scipy==1.16.1
seaborn==0.13.2
tqdm==4.67.1
umap-learn==0.5.9.post2
xgboost==3.0.4
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
from json import load, dumps
from glob import glob
from os import environ
from os.path import join
from sys import argv, exit
def run_single_test(data_dir, output_dir):
from pytest import main
exit(main(['-vv', '-p', 'no:cacheprovider', join(data_dir, 'test.py')]))
def check_test(data_dir):
pass
def grade(data_path):
results = load(open(join(data_path, 'results.json')))
max_mark = 4
grade_mapping = [4]
total_grade = 0
ok_count = 0
for result, grade in zip(results, grade_mapping):
if result['status'] == 'Ok':
total_grade += grade
ok_count += 1
total_count = len(results)
description = '%02d/%02d' % (ok_count, total_count)
mark = total_grade / sum(grade_mapping) * max_mark
res = {'description': description, 'mark': mark}
if environ.get('CHECKER'):
print(dumps(res))
return res
if __name__ == '__main__':
if environ.get('CHECKER'):
# Script is running in testing system
if len(argv) != 4:
print('Usage: %s mode data_dir output_dir' % argv[0])
exit(0)
mode = argv[1]
data_dir = argv[2]
output_dir = argv[3]
if mode == 'run_single_test':
run_single_test(data_dir, output_dir)
elif mode == 'check_test':
check_test(data_dir)
elif mode == 'grade':
grade(data_dir)
else:
# Script is running locally
if len(argv) != 3:
print(f'Usage: {argv[0]} test/unittest test_name')
exit(0)
mode = argv[1]
test_name = argv[2]
test_dir = glob(f'public_tests/[0-9][0-9]_{mode}_{test_name}_input')
if not test_dir:
print('Test not found')
exit(0)
from pytest import main
exit(main(['-vv', join(test_dir[0], 'test.py')]))
+32
View File
@@ -0,0 +1,32 @@
import numpy as np
import typing
class MinMaxScaler:
def __init__(self):
self.min_vals = None
self.max_vals = None
def fit(self, data: np.ndarray) -> None:
self.min_vals = np.min(data, axis=0)
self.max_vals = np.max(data, axis=0)
return
def transform(self, data: np.ndarray) -> np.ndarray:
return (data - self.min_vals) / (self.max_vals - self.min_vals)
class StandardScaler:
def __init__(self):
self.mean_vals = None
self.std_vals = None
def fit(self, data: np.ndarray) -> None:
self.mean_vals = np.mean(data, axis=0)
self.std_vals = np.std(data, axis=0)
return
def transform(self, data: np.ndarray) -> np.ndarray:
return (data - self.mean_vals) / self.std_vals