Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct SVM Use #346

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/AnomalyDetectors/OneClassSVM.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ public function train(Dataset $dataset) : void

$data = [];

foreach ($dataset->samples() as $i => $sample) {
$data[] = array_merge([1], $sample);
foreach ($dataset->samples() as $sample) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So did array_unshift() turn out to be faster?

Is it necessary to assign the sample to an intermediate variable or would

foreach ($dataset->samples() as $sample) {
    array_unshift($sample, 1);

    $data[] = $sample;
}

work here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is faster yes. And the rest works also, please see the next commit

$sample_array = $sample;
array_unshift($sample_array, 1);
$data[] = $sample_array;
}

$this->model = $this->svm->train($data);
Expand Down
Loading