import LearningModel from './data_model'; describe('LearningModel', () => { let learningModel: LearningModel; beforeEach(() => { learningModel = new LearningModel({ epochs: 10, }); }); it('should add sufficient data and train the model', async () => { // 훈련 데이터 생성 const numSamples = 2000; // 훈련 데이터 샘플 수 for (let i = 0; i < numSamples; i++) { const classLabel = i % 2 === 0 ? 'class1' : 'class2'; // 두 개의 클래스를 번갈아가며 생성 const data = Array.from({ length: 3 }, () => Math.random() * 10); // 임의의 데이터 생성 await learningModel.addData(classLabel, data); } // 모델 훈련 const history = await learningModel.train(); // 훈련 결과 평가 expect(history).toBeDefined(); expect(learningModel.ready()).toBe(true); }, 30000); // 타임아웃을 15초로 설정 it('should make predictions', async () => { // 훈련 데이터 생성 const numSamples = 100; // 훈련 데이터 샘플 수 for (let i = 0; i < numSamples; i++) { const classLabel = i % 2 === 0 ? 'class1' : 'class2'; // 두 개의 클래스를 번갈아가며 생성 const data = Array.from({ length: 3 }, () => Math.random() * 10); // 임의의 데이터 생성 await learningModel.addData(classLabel, data); await learningModel.addData(classLabel, [1,2,4]); } // 모델 훈련 await learningModel.train(); // 테스트 데이터 생성 const testData = [4.0, 3.1, 5.2]; // 테스트할 데이터 생성 // 예측 수행 const result = await learningModel.infer(testData); console.log('result', result); // 결과 평가 expect(result).toBeDefined(); }, 30000); });