accountService = $accountService; $this->logger = $logger; $this->classifier = $classifier; $this->config = $config; } protected function configure(): void { $this->setName('mail:account:run-meta-estimator'); $this->setDescription('Run the meta estimator for an account'); $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); $this->addOption(self::ARGUMENT_SHUFFLE, null, null, 'Shuffle data set before training'); } public function isEnabled(): bool { return $this->config->getSystemValueBool('debug'); } protected function execute(InputInterface $input, OutputInterface $output): int { $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); $shuffle = (bool)$input->getOption(self::ARGUMENT_SHUFFLE); try { $account = $this->accountService->findById($accountId); } catch (DoesNotExistException $e) { $output->writeln("Account $accountId does not exist"); return 1; } $consoleLogger = new ConsoleLoggerDecorator( $this->logger, $output ); $estimator = static function () use ($consoleLogger) { $params = [ [5, 10, 15, 20, 25, 30, 35, 40], // Neighbors [true, false], // Weighted? [new Euclidean(), new Manhattan(), new Jaccard()], // Kernel ]; $estimator = new GridSearch( KNearestNeighbors::class, $params, new FBeta(), new KFold(5) ); $estimator->setLogger($consoleLogger); $estimator->setBackend(new Amp()); return $estimator; }; $pipeline = $this->classifier->train( $account, $consoleLogger, $estimator, $shuffle, false, ); /** @var GridSearch $metaEstimator */ $metaEstimator = $pipeline?->getEstimator(); if ($metaEstimator !== null) { $output->writeln("Best estimator: {$metaEstimator->base()}"); } $mbs = (int)(memory_get_peak_usage() / 1024 / 1024); $output->writeln('' . $mbs . 'MB of memory used'); return 0; } }