- How do I install the naive-bayes package in a Laravel app?
- Install it with composer require assisted-mindfulness/naive-bayes. The service provider is auto-discovered, so no manual registration is normally required, and you can publish the package config if you need to override defaults. From there you train the classifier on labeled text and call predict on new documents. There is no external service, credentials, or migration implied by the package itself, so a first spike should take days rather than weeks.
- Which Laravel and PHP versions does this package support?
- It follows standard Laravel package mechanics and the current release line is 2.0.x, with 2.0.2 being the latest patch. The PHP floor is not fixed by the classifier alone because the brick/math dependency can resolve to 0.18 or 0.20, and 0.20 may require a newer PHP minor. Verify both the Laravel constraint and the resolved brick/math PHP requirement against your support matrix rather than assuming compatibility.
- How do I train the classifier and classify a new document?
- Training means feeding the classifier labeled text samples so it can build token and class frequency statistics. After training you call predict on a new document and get back a class guess, which you can map to labels such as spam or ham, sentiment buckets, or ticket categories. Keep the call sites thin so training and prediction can later move from the request path into a queue worker if corpora grow.
- Where is the trained model stored, and is that storage safe for concurrent train and predict calls?
- The package is a self-contained classifier, so the trained model has to live somewhere your application controls, such as the filesystem, a database, or the cache. The evaluation explicitly flags storage location and concurrent access as open questions rather than documented guarantees. Confirm the persistence mechanism in the source for 2.0.x, and check whether simultaneous train and predict operations can corrupt or read partially written state. For multi-worker deployments, wrap persistence behind your own locking or a dedicated model store.
- Does the package support Laplace or additive smoothing for unseen tokens?
- Zero-frequency handling is make-or-break for sparse text, because a single unseen token can otherwise zero out a class probability. The evaluation calls out smoothing and its configurability as a question to resolve before commitment rather than a confirmed feature. Inspect the 2.0.x source or tests for additive smoothing and whether its alpha value is configurable. If smoothing is absent or hard-coded, add a fallback such as token filtering or your own probability adjustment.
- Why does this package depend on brick/math?
- Naive Bayes multiplies many small token probabilities together, and native PHP floats underflow quickly on long documents. brick/math provides arbitrary-precision arithmetic so those products stay usable instead of collapsing to zero. The dependency is narrow and widely used, meaning arithmetic correctness is inherited from a maintained library rather than hand-rolled code. The tradeoff is that classifier precision and rounding behavior are tied to the resolved brick/math version.
- Why could identical package code behave differently between staging and production after 2.0.2?
- Release 2.0.2 widened the brick/math constraint from ^0.18 to ^0.18 || ^0.20, which is a dependency resolution change rather than a functional code change to the classifier. Two environments with different lockfile ages and PHP versions can therefore resolve different brick/math releases with different precision or rounding behavior. On borderline documents, predictions could differ between staging and production. Pin brick/math explicitly in your lockfile and run a regression check on a labeled sample set after every dependency update.
- Can I use this package for spam detection, ticket routing, or sentiment analysis in production?
- Yes, as a lightweight baseline for explainable text classification inside the PHP process, covering spam and abuse triage, ticket routing, intent tagging, sentiment bucketing, and similar tokenized fields. It is not a replacement for hosted inference services or anything needing embeddings, deep models, or GPU throughput. Put it behind a thin internal Classifier interface so a future 2.1 or 3.0 release does not ripple through domain code. For large corpora, prefer running training and batch prediction in queue workers instead of the request path.
- What are the accuracy limits of naive Bayes for text classification?
- Naive Bayes assumes conditional independence of features, which is false for natural language, so expect decent precision but mediocre calibration. It performs poorly on small or heavily imbalanced corpora and is best treated as a strong baseline rather than a ceiling. Use a representative labeled sample to measure precision and recall per class before trusting it for automated decisions. Where confidence matters, combine the score with thresholds or a manual review step.
- Is the package actively maintained, and what are the alternatives if it is abandoned?
- Maintenance is effectively one maintainer plus dependency automation, which is a real continuity risk for a component in the classification path. Mitigate by keeping the integration surface small enough to reimplement, or by forking and vendoring the package internally. The code is pure PHP and the algorithm is well understood, so a replacement or in-house version is feasible. Alternatives include other PHP naive Bayes implementations and, if you already run Python services, a scikit-learn based sidecar classifier.