๐ค Designing an RAG with search for 10 million documents while minimizing hallucinations ๐
1๏ธโฃ Document ingestion and normalization ๐
Removing duplicates, converting to a single format, extracting metadata, and maintaining versioning. ๐
2๏ธโฃ Hybrid search (BM25 + vector representations) ๐
BM25 handles exact keyword matches, while vector search handles semantic relevance. One approach without the other typically suffers from low accuracy at this scale. ๐
3๏ธโฃ Approximate nearest neighbor search + re-ranking โ๏ธ
Approximate nearest neighbor search quickly retrieves candidates from millions of fragments. Next, a ranking model recalculates relevance through a more rigorous comparison of the query and fragments. ๐ง
4๏ธโฃ Trust scoring for sources ๐ก๏ธ
Each fragment receives an evaluation based on freshness, source reliability, overlap, and consistency with other found results. Data with low trust should not significantly influence the final response. ๐ซ
5๏ธโฃ Generation with strict context constraints ๐ง
The model only operates within the extracted context. Adding knowledge outside the context is prohibited by the pipeline logic. ๐ซ
6๏ธโฃ Answers with source attribution ๐
Every significant statement must refer to a specific fragment, document, or timestamp. โฐ
7๏ธโฃ Fallback for low search confidence ๐
If the total context confidence falls below a threshold, a response like "not enough data" is returned. ๐
8๏ธโฃ Continuous quality checks ๐งช
Running attack queries, measuring search completeness, testing for hallucinations, and monitoring ranking degradation. ๐
9๏ธโฃ Caching and memory layer ๐พ
Frequent queries and search chains are cached to reduce latency and computational cost. โก
๐ Observability at all stages ๐๏ธ
Tracing the query path, fragment ranking, and the impact of tokens and failure points. ๐ ๏ธ
๐ At the scale of 10 million documents, search quality becomes a more critical factor than the choice of generative model.
#RAG #AI #Search #LLM #DataEngineering #Tech
1๏ธโฃ Document ingestion and normalization ๐
Removing duplicates, converting to a single format, extracting metadata, and maintaining versioning. ๐
2๏ธโฃ Hybrid search (BM25 + vector representations) ๐
BM25 handles exact keyword matches, while vector search handles semantic relevance. One approach without the other typically suffers from low accuracy at this scale. ๐
3๏ธโฃ Approximate nearest neighbor search + re-ranking โ๏ธ
Approximate nearest neighbor search quickly retrieves candidates from millions of fragments. Next, a ranking model recalculates relevance through a more rigorous comparison of the query and fragments. ๐ง
4๏ธโฃ Trust scoring for sources ๐ก๏ธ
Each fragment receives an evaluation based on freshness, source reliability, overlap, and consistency with other found results. Data with low trust should not significantly influence the final response. ๐ซ
5๏ธโฃ Generation with strict context constraints ๐ง
The model only operates within the extracted context. Adding knowledge outside the context is prohibited by the pipeline logic. ๐ซ
6๏ธโฃ Answers with source attribution ๐
Every significant statement must refer to a specific fragment, document, or timestamp. โฐ
7๏ธโฃ Fallback for low search confidence ๐
If the total context confidence falls below a threshold, a response like "not enough data" is returned. ๐
8๏ธโฃ Continuous quality checks ๐งช
Running attack queries, measuring search completeness, testing for hallucinations, and monitoring ranking degradation. ๐
9๏ธโฃ Caching and memory layer ๐พ
Frequent queries and search chains are cached to reduce latency and computational cost. โก
๐ Observability at all stages ๐๏ธ
Tracing the query path, fragment ranking, and the impact of tokens and failure points. ๐ ๏ธ
๐ At the scale of 10 million documents, search quality becomes a more critical factor than the choice of generative model.
#RAG #AI #Search #LLM #DataEngineering #Tech
โค6
๐ Master Binary Classification with Neural Networks! ๐ง โจ
Ever wondered how to build a neural network from scratch in Python using NumPy? ๐๐
Binary classification is at the heart of many machine learning applications. ๐ฏ๐ค
Our super-detailed guide walks you through the entire process step by step. ๐๐
๐ก Dive in and start building your own neural network today! ๐๐ฅ
https://tinztwinshub.com/data-science/a-beginners-guide-to-developing-an-artificial-neural-network-from-zero/
#MachineLearning #NeuralNetworks #Python #DataScience #AI #Tech
Ever wondered how to build a neural network from scratch in Python using NumPy? ๐๐
Binary classification is at the heart of many machine learning applications. ๐ฏ๐ค
Our super-detailed guide walks you through the entire process step by step. ๐๐
๐ก Dive in and start building your own neural network today! ๐๐ฅ
https://tinztwinshub.com/data-science/a-beginners-guide-to-developing-an-artificial-neural-network-from-zero/
#MachineLearning #NeuralNetworks #Python #DataScience #AI #Tech
๐4โค2
๐ฅ Awesome open-source project to learn more about Transformer Models! ๐คโจ
We found this interactive website that shows you visually how transformer models work. ๐๐
Transformer Explainer:
https://poloclub.github.io/transformer-explainer/
#TransformerModels #OpenSource #AI #MachineLearning #DataScience #Tech
โจ Join Best TG Channels
https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel
https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
We found this interactive website that shows you visually how transformer models work. ๐๐
Transformer Explainer:
https://poloclub.github.io/transformer-explainer/
#TransformerModels #OpenSource #AI #MachineLearning #DataScience #Tech
โจ Join Best TG Channels
https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel
https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค3๐ฅ3๐2๐ฉ1
๐ A huge open-source course on AI Engineering from scratch
In the repository, we've collected:
โ 435 lessons;
โ 320+ hours of content;
โ Python, TypeScript, and Rust;
โ AI agents, MCP servers, prompts, and AI skills.
Moreover, almost every lesson includes practical tasks, so this isn't just theory, but a full-fledged roadmap for AI Engineering. ๐
โ๏ธ Link to the repository
https://github.com/rohitg00/ai-engineering-from-scratch
#AI #MachineLearning #Python #Rust #OpenSource #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
In the repository, we've collected:
โ 435 lessons;
โ 320+ hours of content;
โ Python, TypeScript, and Rust;
โ AI agents, MCP servers, prompts, and AI skills.
Moreover, almost every lesson includes practical tasks, so this isn't just theory, but a full-fledged roadmap for AI Engineering. ๐
โ๏ธ Link to the repository
https://github.com/rohitg00/ai-engineering-from-scratch
#AI #MachineLearning #Python #Rust #OpenSource #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค6๐1
Transformer implementations for vision, audio, and AI agents ๐ค๐๏ธ๐ต
Repo: https://github.com/Nicolepcx/transformers-the-definitive-guide
#AI #MachineLearning #Vision #Audio #Agents #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Repo: https://github.com/Nicolepcx/transformers-the-definitive-guide
#AI #MachineLearning #Vision #Audio #Agents #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค4๐2
This media is not supported in your browser
VIEW IN TELEGRAM
Someone spent several months manually writing a 200-page guide on mathematics and the basics of machine learning. ๐
No marketing fluff or endless links between articles. Just an attempt to gather all the most important things in one place. ๐ฏ
Inside:
โข neural networks: backpropagation, SGD, Adam, BatchNorm; โ๏ธ
โข classic ML: SVM, Gradient Boosting, K-Means, PCA; ๐
โข hardware for AI: Tensor Cores, Systolic Arrays, CUDA; ๐ฅ๏ธ
โข transformers: Multi-Head Attention, KV Cache, LoRA; ๐ง
โข computer vision: ViT, CNN, MAE, IoU, NMS, VLM; ๐๏ธ
โข agent systems: ReAct, memory, orchestration, OpenClaw. ๐ค
The author describes it as the material he would have wanted to receive himself several years ago. ๐ฐ๏ธ
And yes, the entire guide is distributed free of charge. ๐
https://www.arjunvirk.com/writing/ml-guide
#MachineLearning #AI #DeepLearning #DataScience #NeuralNetworks #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
No marketing fluff or endless links between articles. Just an attempt to gather all the most important things in one place. ๐ฏ
Inside:
โข neural networks: backpropagation, SGD, Adam, BatchNorm; โ๏ธ
โข classic ML: SVM, Gradient Boosting, K-Means, PCA; ๐
โข hardware for AI: Tensor Cores, Systolic Arrays, CUDA; ๐ฅ๏ธ
โข transformers: Multi-Head Attention, KV Cache, LoRA; ๐ง
โข computer vision: ViT, CNN, MAE, IoU, NMS, VLM; ๐๏ธ
โข agent systems: ReAct, memory, orchestration, OpenClaw. ๐ค
The author describes it as the material he would have wanted to receive himself several years ago. ๐ฐ๏ธ
And yes, the entire guide is distributed free of charge. ๐
https://www.arjunvirk.com/writing/ml-guide
#MachineLearning #AI #DeepLearning #DataScience #NeuralNetworks #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค3
๐ A large collection of AI projects for practice
We found a repository that will help you move from theory to real development of AI applications.
Inside are dozens of ready-made projects: AI analytics, RAG systems, OCR applications, code review agents, travel assistants, and much more.
โ๏ธ Link to GitHub: https://github.com/Sumanth077/Hands-On-AI-Engineering
#AI #MachineLearning #Python #DataScience #OpenSource #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
We found a repository that will help you move from theory to real development of AI applications.
Inside are dozens of ready-made projects: AI analytics, RAG systems, OCR applications, code review agents, travel assistants, and much more.
โ๏ธ Link to GitHub: https://github.com/Sumanth077/Hands-On-AI-Engineering
#AI #MachineLearning #Python #DataScience #OpenSource #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค5
Forwarded from Machine Learning with Python
10 GitHub repositories that are worth checking out for an AI engineer ๐ค
1. Hands-On AI Engineering ๐ ๏ธ
A collection of AI applications and agent systems with practical use cases of LLM.
๐ https://github.com/Sumanth077/Hands-On-AI-Engineering
2. Hands-On Large Language Models ๐
Full code from the book Hands-On Large Language Models: from basics to fine-tuning.
๐ https://github.com/HandsOnLLM/Hands-On-Large-Language-Models
3. AI Agents for Beginners ๐
A free course from Microsoft with 11 lessons on creating AI agents.
๐ https://github.com/microsoft/ai-agents-for-beginners
4. GenAI Agents ๐ค
A large collection of tutorials and implementations of agent systems.
๐ https://github.com/NirDiamant/GenAI_Agents
5. Made With ML ๐
About the development, deployment, and support of production-ready ML systems.
๐ https://github.com/GokuMohandas/Made-With-ML
6. Learn Harness Engineering โ๏ธ
A practical course on Harness Engineering for AI agents.
๐ https://github.com/walkinglabs/learn-harness-engineering
7. AutoResearch ๐ฌ
Autonomous cycles of ML experiments from Andrej Karpathy.
๐ https://github.com/karpathy/autoresearch
8. Designing Machine Learning Systems ๐
Notes and materials from Chip Huyen's book.
๐ https://github.com/chiphuyen/dmls-book
9. Awesome LLM Inference โก
A collection of materials on LLM inference: Flash Attention, KV Cache, quantization, and more.
๐ https://github.com/xlite-dev/Awesome-LLM-Inference
10. LLM Course ๐บ๏ธ
A practical course on LLM with a roadmap and Colab notebooks.
๐ https://github.com/mlabonne/llm-course
#AI #MachineLearning #LLM #DataScience #Tech #GitHub
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
1. Hands-On AI Engineering ๐ ๏ธ
A collection of AI applications and agent systems with practical use cases of LLM.
๐ https://github.com/Sumanth077/Hands-On-AI-Engineering
2. Hands-On Large Language Models ๐
Full code from the book Hands-On Large Language Models: from basics to fine-tuning.
๐ https://github.com/HandsOnLLM/Hands-On-Large-Language-Models
3. AI Agents for Beginners ๐
A free course from Microsoft with 11 lessons on creating AI agents.
๐ https://github.com/microsoft/ai-agents-for-beginners
4. GenAI Agents ๐ค
A large collection of tutorials and implementations of agent systems.
๐ https://github.com/NirDiamant/GenAI_Agents
5. Made With ML ๐
About the development, deployment, and support of production-ready ML systems.
๐ https://github.com/GokuMohandas/Made-With-ML
6. Learn Harness Engineering โ๏ธ
A practical course on Harness Engineering for AI agents.
๐ https://github.com/walkinglabs/learn-harness-engineering
7. AutoResearch ๐ฌ
Autonomous cycles of ML experiments from Andrej Karpathy.
๐ https://github.com/karpathy/autoresearch
8. Designing Machine Learning Systems ๐
Notes and materials from Chip Huyen's book.
๐ https://github.com/chiphuyen/dmls-book
9. Awesome LLM Inference โก
A collection of materials on LLM inference: Flash Attention, KV Cache, quantization, and more.
๐ https://github.com/xlite-dev/Awesome-LLM-Inference
10. LLM Course ๐บ๏ธ
A practical course on LLM with a roadmap and Colab notebooks.
๐ https://github.com/mlabonne/llm-course
#AI #MachineLearning #LLM #DataScience #Tech #GitHub
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค4
Forwarded from Machine Learning with Python
Learn AI for free directly from top companies. ๐
1 - Anthropic:
anthropic.skilljar.com
2 - Google:
grow.google/ai
3 - Meta:
ai.meta.com/resources/
4 - NVIDIA:
developer.nvidia.com/cuda
5 - Microsoft:
learn.microsoft.com/en-us/training/
6 - OpenAI:
academy.openai.com
7 - IBM:
skillsbuild.org
8 - AWS:
skillbuilder.aws
9 - DeepLearning.AI:
deeplearning.ai
10 - Hugging Face:
huggingface.co/learn
๐ฌ Comment "Learning" if you find this helpful.
๐ Repost so others can take help.
๐ Must bookmark for future reference.
#AI #MachineLearning #Tech #FreeLearning #DataScience #AIForAll
https://xn--r1a.website/CodeProgrammer
1 - Anthropic:
anthropic.skilljar.com
2 - Google:
grow.google/ai
3 - Meta:
ai.meta.com/resources/
4 - NVIDIA:
developer.nvidia.com/cuda
5 - Microsoft:
learn.microsoft.com/en-us/training/
6 - OpenAI:
academy.openai.com
7 - IBM:
skillsbuild.org
8 - AWS:
skillbuilder.aws
9 - DeepLearning.AI:
deeplearning.ai
10 - Hugging Face:
huggingface.co/learn
๐ฌ Comment "Learning" if you find this helpful.
๐ Repost so others can take help.
๐ Must bookmark for future reference.
#AI #MachineLearning #Tech #FreeLearning #DataScience #AIForAll
https://xn--r1a.website/CodeProgrammer
Grow with Google US
AI Training to Grow Your Career | Google
Learn all about AI & how to supercharge your work or business. We offer AI courses and tools that will help you build essential AI skills.
โค3
A free MIT guide to key computer vision concepts ๐
Link: https://visionbook.mit.edu/ ๐
#ComputerVision #MIT #AI #MachineLearning #Tech #DataScience
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
Link: https://visionbook.mit.edu/ ๐
#ComputerVision #MIT #AI #MachineLearning #Tech #DataScience
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
๐ Level up your AI & Data Science skills with HelloEncyclo โ a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โ 13 courses live + 40+ coming soon
๐ฏ One access, lifetime updates
๐ Use code: PRESALE-BOOK-WAVE-2GFG
๐ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค1
The math.perm() method
The math.perm() method in Python returns the number of ways to select k elements from n elements, with and without repetition. ๐งฎ
Syntax:
Where:
n: The number of elements from which k elements are selected.
k: The number of elements that are selected.
In the first example, the method returns the number of ways to select 3 elements from 5 elements. The result is 60 ways. ๐
In the second example, the method returns the number of ways to select 5 elements from 10 elements. The result is 252 ways. ๐
#Python #Math #Coding #Programming #DataScience #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
The math.perm() method in Python returns the number of ways to select k elements from n elements, with and without repetition. ๐งฎ
Syntax:
math.perm(n, k)
Where:
n: The number of elements from which k elements are selected.
k: The number of elements that are selected.
In the first example, the method returns the number of ways to select 3 elements from 5 elements. The result is 60 ways. ๐
In the second example, the method returns the number of ways to select 5 elements from 10 elements. The result is 252 ways. ๐
#Python #Math #Coding #Programming #DataScience #Tech
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค10
Feature Scaling: Why Feature Scaling Affects Model Training
Feature scaling is often overlooked because it seems like just another data preprocessing step. However, in practice, it often helps models train faster and more stably. Imagine one feature has values ranging from 0 to 1, while another has values ranging from 0 to 10,000. Although both features may be equally important for prediction, it's more difficult for the optimizer to work with such data.
This means it has to take more steps to find a good solution. Additionally, regularization becomes less effective because features with different scales require coefficients of different magnitudes. Let's look at how this looks in a simple example.
Install dependencies:
Import libraries:
Let's create a small synthetic dataset. It will have two features: the first has a normal scale, and the second is about a thousand times larger.
Importantly, both features actually influence the target variable. That is, the only difference between them is the scale.
Now, let's split the data into training and testing sets. We won't scale anything yetโfirst, let's see how the model behaves on the original data.
Let's train a logistic regression model without scaling.
In addition to the model's quality, let's also look at the number of iterations (
Now, let's scale the features to the same scale using
It calculates the mean and standard deviation only for the training set and then uses the same values for the test set. This is important because the model should not "peek" at the test data during training.
After this transformation, both features are approximately on the same scale, and it becomes easier for the optimizer to work with them.
Now, let's retrain the model.
We're using the same model, the same data, and the same parameters. The only difference is that the features are now scaled.
Most often, the ROC-AUC doesn't change much. However, the number of iterations becomes smaller. This means that the optimizer found a solution faster, and the training was more stable.
๐ฅ
โจ #DataScience #MachineLearning #Python #Coding #Tech #AI
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Feature scaling is often overlooked because it seems like just another data preprocessing step. However, in practice, it often helps models train faster and more stably. Imagine one feature has values ranging from 0 to 1, while another has values ranging from 0 to 10,000. Although both features may be equally important for prediction, it's more difficult for the optimizer to work with such data.
This means it has to take more steps to find a good solution. Additionally, regularization becomes less effective because features with different scales require coefficients of different magnitudes. Let's look at how this looks in a simple example.
Install dependencies:
pip install numpy scikit-learn
Import libraries:
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
Let's create a small synthetic dataset. It will have two features: the first has a normal scale, and the second is about a thousand times larger.
Importantly, both features actually influence the target variable. That is, the only difference between them is the scale.
np.random.seed(42)
x_small = np.random.normal(0, 1, 300)
x_large = np.random.normal(0, 1000, 300)
X = np.vstack([x_small, x_large]).T
y = (x_small + 0.001 * x_large > 0).astype(int)
Now, let's split the data into training and testing sets. We won't scale anything yetโfirst, let's see how the model behaves on the original data.
X_train, X_test, y_train, y_test = train_test_split(
X, y,
test_size=0.3,
random_state=42,
stratify=y
)
Let's train a logistic regression model without scaling.
In addition to the model's quality, let's also look at the number of iterations (
n_iter_). This metric shows how much work the optimizer had to do to find the coefficients.model = LogisticRegression()
model.fit(X_train, y_train)
pred = model.predict_proba(X_test)[:, 1]
print("ROC-AUC:", roc_auc_score(y_test, pred))
print("Iterations:", model.n_iter_)
Now, let's scale the features to the same scale using
StandardScaler.It calculates the mean and standard deviation only for the training set and then uses the same values for the test set. This is important because the model should not "peek" at the test data during training.
After this transformation, both features are approximately on the same scale, and it becomes easier for the optimizer to work with them.
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
Now, let's retrain the model.
We're using the same model, the same data, and the same parameters. The only difference is that the features are now scaled.
model = LogisticRegression()
model.fit(X_train_scaled, y_train)
pred = model.predict_proba(X_test_scaled)[:, 1]
print("ROC-AUC (scaled):", roc_auc_score(y_test, pred))
print("Iterations (scaled):", model.n_iter_)
Most often, the ROC-AUC doesn't change much. However, the number of iterations becomes smaller. This means that the optimizer found a solution faster, and the training was more stable.
๐ฅ
Feature scaling is a simple data preprocessing step that, in many cases, allows the model to train faster and more stably. For logistic regression, SVMs, neural networks, and other algorithms that use numerical optimization, it's best not to skip it.โจ #DataScience #MachineLearning #Python #Coding #Tech #AI
โจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Telegram
AI PYTHON ๐
Youโve been invited to add the folder โAI PYTHON ๐โ, which includes 15 chats.
โค4