Загрузка...

Django and HTMX #18 - Automated Spam Filtering / Machine Learning with Scikit-Learn

In this video, we'll build an automated spam filter that can help admin users detect and delete spam comments on your Django site.

To start, we will build a machine learning model using pandas and scikit-learn. We'll keep it simple, using a K-Nearest Neighbors model and vectorizing the text with a TfidfVectorizer.

After building and evaluating the model, we will apply it to our Django application by creating a Comment model, and running the text for each comment through our ML model. We'll use HTMX to update our front-end with a partial indicating whether or not a given comment is marked as potential spam, and will allow admin users to delete comments with HTMX requests.

We'll also quickly look at how HTMX can be used as a scripting tool, similar to jQuery. We'll use HTMX's scripting capabilities to delete the row from the DOM when a comment is removed, rather than returning a separate partial.

Starter code can be found here: https://github.com/bugbytes-io/django-htmx-spamfilter

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
04:00 Preprocessing Text
07:08 Vectorizing text with Scikit-Learn TfidfVectorizer
09:10 Splitting data into train and test sets
10:28 Training Scikit-Learn KNN Classifier
12:00 Saving the model to a file
13:18 Adding Comment Django Model
15:22 Adding Comments with Django Admin
18:40 Adding Spam Detection with HTMX
28:14 Removing Posts with HTMX
31:42 Deleting row using HTMX scripting tools

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: https://www.bugbytes.io/posts/
👾 Github: https://github.com/bugbytes-io/django-htmx-spamfilter
🐦 Twitter: https://twitter.com/bugbytesio

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Dataset: https://www.kaggle.com/datasets/karthickveerakumar/spam-filter?resource=download
KNN: https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html
TF-IDF: https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html
Model Persistence: https://scikit-learn.org/stable/modules/model_persistence.html
Precision & Recall: https://en.wikipedia.org/wiki/Precision_and_recall
TailwindCSS Cards: https://tailwind-elements.com/docs/standard/components/cards/
HTMX 204 No Content: https://htmx.org/docs/#requests
HTMX Scripting & JS API: https://htmx.org/reference/#api

#python #django #machinelearning #sklearn #htmx #pandas

Видео Django and HTMX #18 - Automated Spam Filtering / Machine Learning with Scikit-Learn канала BugBytes
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять