/
tarasovxx
/
AAA
Обзор
Документация
Войти
/
tarasovxx
/
AAA
Код
Запросы
6
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
class2
test_count_vectorizer.py
38 строк
1 KB
Tarasov Artyom
hw done for class
16 янв 2025, 20:51
16 янв 2025, 20:51
3d617b3
Код
Авторство
О чём код?
from count_vectorizer import CountVectorizer def test_simple_example(): corpus = [ 'Crock Pot Pasta Never boil pasta again', 'Pasta Pomodoro Fresh ingredients Parmesan to taste' ] vectorizer = CountVectorizer() count_matrix = vectorizer.fit_transform(corpus) expected_features = [ 'again', 'boil', 'crock', 'fresh', 'ingredients', 'never', 'parmesan', 'pasta', 'pomodoro', 'pot', 'taste', 'to' ] assert vectorizer.get_feature_names() == expected_features, ( f"Ожидался словарь {expected_features}, " f"получен {vectorizer.get_feature_names()}" ) expected_matrix = [ [1, 1, 1, 0, 0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1] ] assert count_matrix == expected_matrix, ( f"Ожидалась матрица {expected_matrix}, " f"получена {count_matrix}" ) print("Тест пройден!") def main(): test_simple_example() if __name__ == "__main__": main()