더 나은 PHP 개발 도구 및 기술을 읽어서 더 나은 개발자가 되십시오!
키 포인트
질문
<code>{ "name": "amacgregor/phpml-exercise", "description": "Example implementation of a Tweet sentiment analysis with PHP-ML", "type": "project", "require": { "php-ai/php-ml": "^0.4.1" }, "license": "Apache License 2.0", "authors": [ { "name": "Allan MacGregor", "email": "amacgregor@allanmacgregor.com" } ], "autoload": { "psr-4": {"PhpmlExercise\": "src/"} }, "minimum-stability": "dev" }</code>
<code>composer install </code>
샘플
는 파일에 의해 제공된 모든 특성을 포함하고 대상은 알려진 값 (음수, 양수 또는 중립)을 포함합니다.<code class="language-php"><?php namespace PhpmlExercise; require __DIR__ . '/vendor/autoload.php'; use Phpml\Dataset\CsvDataset; $dataset = new CsvDataset('datasets/raw/Tweets.csv',1); foreach ($dataset->getSamples() as $sample) { print_r($sample); } </code>
<code>Array( [0] => 569587371693355008 ) Array( [0] => 569587242672398336 ) Array( [0] => 569587188687634433 ) Array( [0] => 569587140490866689 ) </code>이제 reviewDataset.php 스크립트를 깨끗한 데이터 세트에 지적합시다 :
bam! 이것은 우리가 사용할 수있는 데이터입니다! 지금까지 데이터 조작을위한 간단한 스크립트를 만들었습니다. 다음으로 SRC/Classification/SentimentAnalysis.php에서 새로운 클래스를 만들기 시작합니다.
<code class="language-php"><?php public function __construct(string $filepath, int $features, bool $headingRow = true) { if (!file_exists($filepath)) { throw FileException::missingFile(basename($filepath)); } if (false === $handle = fopen($filepath, 'rb')) { throw FileException::cantOpenFile(basename($filepath)); } if ($headingRow) { $data = fgetcsv($handle, 1000, ','); $this->columnNames = array_slice($data, 0, $features); } else { $this->columnNames = range(0, $features - 1); } while (($data = fgetcsv($handle, 1000, ',')) !== false) { $this->samples[] = array_slice($data, 0, $features); $this->targets[] = $data[$features]; } fclose($handle); } </code>
우리는 이미 이전 예제에서 CSV를 데이터 세트 객체에로드하는 데 사용할 수있는 코드가 이미 있습니다. 우리는 동일한 코드를 사용하고 약간의 조정을 할 것입니다 : <li>
</li>
<ate> 이것은 분류기를 훈련시키는 데 사용할 기능 (이 경우 트윗 텍스트) 만 포함 된 평평한 배열을 생성합니다. </ate>
회전 추정이라고도하는 교차 검증은 통계 분석 결과가 독립적 인 데이터 세트로 일반화되는 방법을 평가하는 데 사용되는 모델 검증 기술입니다. 주로 예측 목표 설정에 사용되며 실제로 예측 모델의 정확도를 추정하려고합니다. - wikipedia.com
<code>{ "name": "amacgregor/phpml-exercise", "description": "Example implementation of a Tweet sentiment analysis with PHP-ML", "type": "project", "require": { "php-ai/php-ml": "^0.4.1" }, "license": "Apache License 2.0", "authors": [ { "name": "Allan MacGregor", "email": "amacgregor@allanmacgregor.com" } ], "autoload": { "psr-4": {"PhpmlExercise\": "src/"} }, "minimum-stability": "dev" }</code>4 단계 : 분류기 훈련
<code>composer install </code>천연 베이
이 연습의 경우, 우리는 가장 간단한 운동 인 순진한 베이 에스 분류기를 사용하므로 열차 방법을 구현하기 위해 클래스를 계속 업데이트하십시오.
<code>{ "name": "amacgregor/phpml-exercise", "description": "Example implementation of a Tweet sentiment analysis with PHP-ML", "type": "project", "require": { "php-ai/php-ml": "^0.4.1" }, "license": "Apache License 2.0", "authors": [ { "name": "Allan MacGregor", "email": "amacgregor@allanmacgregor.com" } ], "autoload": { "psr-4": {"PhpmlExercise\": "src/"} }, "minimum-stability": "dev" }</code>마찬가지로, PHP-ML은 우리를 도와 주었고 우리를 위해 모든 무거운 리프팅을했습니다. 다음에 따라 ClassifyTweets 클래스를 업데이트합시다
<code>composer install </code>
결론 이 게시물은 조금 길다. 그래서 지금까지 배운 내용을 검토해 봅시다 :
<code class="language-php"><?php namespace PhpmlExercise; require __DIR__ . '/vendor/autoload.php'; use Phpml\Dataset\CsvDataset; $dataset = new CsvDataset('datasets/raw/Tweets.csv',1); foreach ($dataset->getSamples() as $sample) { print_r($sample); } </code>감독 학습과 감독되지 않은 학습의 차이점.
<code>Array( [0] => 569587371693355008 ) Array( [0] => 569587242672398336 ) Array( [0] => 569587188687634433 ) Array( [0] => 569587140490866689 ) </code>
위 내용은 PHP 머신 러닝으로 트윗 감정을 분석하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!