Epython Lab
6.11K subscribers
680 photos
31 videos
104 files
1.31K links
Welcome to Epython Lab, where you can get resources to learn, one-on-one trainings on machine learning, business analytics, and Python, and solutions for business problems.

Buy ads: https://telega.io/c/epythonlab
Download Telegram
Your model can look excellent and still be wrong.

One of the first things I check when evaluating an ML dataset is data leakage. ๐Ÿ”

Data leakage happens when information that would not actually be available at prediction time gets into the training data.

For example:

๐Ÿฅ Healthcare
You are predicting whether a patient will be admitted, but your dataset includes a field recorded after admission.

๐Ÿ’ณ Fraud detection
You are predicting fraud, but one of the features is created after the transaction has already been investigated.

๐Ÿ“ฆ Customer churn
You are predicting who will leave, but the training data contains information that only becomes available after the customer leaves.

The result?

Your model may show:

๐Ÿ“ˆ 98% accuracy
๐Ÿ“ˆ Excellent validation results
๐Ÿ“ˆ Great performance during testing

Then you put it into production...

And the performance drops.

The problem was not necessarily the model.

The model had access to information it would never have in the real world.

That is why I don't look at model performance alone.

I also ask:

๐Ÿ”Ž Where did each feature come from?
โฑ๏ธ When was it created?
๐ŸŽฏ Would this information actually be available when making the prediction?

A high score is not always a good score.

Sometimes, it is a warning sign.

Check out data quality issues
https://youtube.com/playlist?list=PL0nX4ZoMtjYHTtowSzzB2gVH2AuuoF9WW&si=EhLKvJCVlYQXknOs

Also checkout data quality checker tool https://datasetdoctor.fastapicloud.dev

#MachineLearning #DataScience #AI #DataLeakage #MLOps #Python
The hardest part of building AI applications isn't writing the prompt or calling the model. In the last two weeks, I learned that keeping the backend from turning into spaghetti code once you move past the tutorial phase.

When you're wiring up an AI document pipeline in FastAPI, a few things quickly become non-negotiable:



โ€ข Payload Guardrails: If your Pydantic schemas aren't catching malformed JSON, missing nested fields, or bad Enums at the door, your AI service will fail unpredictably downstream.



โ€ข Route Isolation: Mixing your raw API endpoints with validation logic and business rules makes refactoring a nightmare by week three.



โ€ข The Persistence Gap: Transitioning from mock in-memory data structures to a real relational database and a vector store for RAG is where most clean prototypes start to break down.



If you're building production backends for AI and ML features, where do you usually draw the line between keeping things simple and over-engineering your architecture?



You can learn about FastAPI: https://www.youtube.com/playlist?list=PLQNCas8_eikM



#FastAPI #Python #BackendEngineering #SoftwareArchitecture #APIs #Pydantic #ArtificialIntelligence #MachineLearning #RAG
FastAPI Episode 7: Advanced Pydentic Model Design
https://www.youtube.com/watch?v=j4lLM6tWKKk
โค4
When building a FastAPI application, I pay close attention to how data is validated before it reaches the business logic.

That is where Pydantic becomes particularly useful.

Pydantic lets us define the structure and rules for the data our application accepts, instead of scattering validation checks throughout the codebase.

I use it to define and enforce the data contract at the application boundary.

For example:

๐‘๐‘™๐‘Ž๐‘ ๐‘  ๐‘ƒ๐‘Ÿ๐‘œ๐‘๐‘’๐‘ ๐‘ ๐‘–๐‘›๐‘”๐ถ๐‘œ๐‘›๐‘“๐‘–๐‘”(๐ต๐‘Ž๐‘ ๐‘’๐‘€๐‘œ๐‘‘๐‘’๐‘™):

๐‘โ„Ž๐‘ข๐‘›๐‘˜_๐‘ ๐‘–๐‘ง๐‘’: ๐‘–๐‘›๐‘ก = ๐น๐‘–๐‘’๐‘™๐‘‘(๐‘”๐‘ก=0)

๐‘œ๐‘ฃ๐‘’๐‘Ÿ๐‘™๐‘Ž๐‘: ๐‘–๐‘›๐‘ก = ๐น๐‘–๐‘’๐‘™๐‘‘(๐‘”๐‘’=0)

@๐‘š๐‘œ๐‘‘๐‘’๐‘™_๐‘ฃ๐‘Ž๐‘™๐‘–๐‘‘๐‘Ž๐‘ก๐‘œ๐‘Ÿ(๐‘š๐‘œ๐‘‘๐‘’="๐‘Ž๐‘“๐‘ก๐‘’๐‘Ÿ")

๐‘‘๐‘’๐‘“ ๐‘ฃ๐‘Ž๐‘™๐‘–๐‘‘๐‘Ž๐‘ก๐‘’_๐‘๐‘œ๐‘›๐‘“๐‘–๐‘”(๐‘ ๐‘’๐‘™๐‘“):

๐‘–๐‘“ ๐‘ ๐‘’๐‘™๐‘“.๐‘œ๐‘ฃ๐‘’๐‘Ÿ๐‘™๐‘Ž๐‘ >= ๐‘ ๐‘’๐‘™๐‘“.๐‘โ„Ž๐‘ข๐‘›๐‘˜_๐‘ ๐‘–๐‘ง๐‘’:

๐‘Ÿ๐‘Ž๐‘–๐‘ ๐‘’ ๐‘‰๐‘Ž๐‘™๐‘ข๐‘’๐ธ๐‘Ÿ๐‘Ÿ๐‘œ๐‘Ÿ("๐‘œ๐‘ฃ๐‘’๐‘Ÿ๐‘™๐‘Ž๐‘ ๐‘š๐‘ข๐‘ ๐‘ก ๐‘๐‘’ ๐‘ ๐‘š๐‘Ž๐‘™๐‘™๐‘’๐‘Ÿ ๐‘กโ„Ž๐‘Ž๐‘› ๐‘โ„Ž๐‘ข๐‘›๐‘˜_๐‘ ๐‘–๐‘ง๐‘’")

๐‘Ÿ๐‘’๐‘ก๐‘ข๐‘Ÿ๐‘› ๐‘ ๐‘’๐‘™๐‘“

Both fields can be individually valid, while their combination is not.

That is the difference between:

Field validation โ†’ Is this value valid?

Model validation โ†’ Is this combination valid?

With Pydantic, ๐™๐™ž๐™š๐™ก๐™™(), ๐™›๐™ž๐™š๐™ก๐™™_๐™ซ๐™–๐™ก๐™ž๐™™๐™–๐™ฉ๐™ค๐™ง(), ๐™–๐™ฃ๐™™ ๐™ข๐™ค๐™™๐™š๐™ก_๐™ซ๐™–๐™ก๐™ž๐™™๐™–๐™ฉ๐™ค๐™ง() let us keep these rules close to the schema.

The result is a cleaner boundary:

๐™๐™š๐™ฆ๐™ช๐™š๐™จ๐™ฉ โ†’ ๐™‘๐™–๐™ก๐™ž๐™™๐™–๐™ฉ๐™ž๐™ค๐™ฃ โ†’ ๐˜ฝ๐™ช๐™จ๐™ž๐™ฃ๐™š๐™จ๐™จ ๐™‡๐™ค๐™œ๐™ž๐™˜ โ†’ ๐˜ฟ๐™–๐™ฉ๐™–๐™—๐™–๐™จ๐™š / ๐˜ผ๐™„

For production AI applications, this matters. Document metadata, processing parameters, search filters, and structured AI outputs all need predictable contracts.

Good schemas do more than describe data. They protect the rest of the system.


You can explore more: https://www.youtube.com/playlist?list=PLQNCas8_eikM


#Python #Pydantic #PydanticV2 #FastAPI #BackendEngineering #AIEngineering
While moving from other web frameworks to ๐…๐š๐ฌ๐ญ๐€๐๐ˆ, one question came to my mind:



๐–๐ก๐ฒ ๐๐จ ๐ˆ ๐ง๐ž๐ž๐ ๐€๐๐ˆ๐‘๐จ๐ฎ๐ญ๐ž๐ซ ๐ฐ๐ก๐ž๐ง ๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐š๐ฅ๐ซ๐ž๐š๐๐ฒ ๐ฅ๐ž๐ญ๐ฌ ๐ฆ๐ž ๐๐ž๐Ÿ๐ข๐ง๐ž ๐ซ๐จ๐ฎ๐ญ๐ž๐ฌ ๐๐ข๐ซ๐ž๐œ๐ญ๐ฅ๐ฒ?



For a small project, this is enough:



@๐’‚๐’‘๐’‘.๐’ˆ๐’†๐’•("/๐’…๐’๐’„๐’–๐’Ž๐’†๐’๐’•๐’”")

๐’‚๐’”๐’š๐’๐’„ ๐’…๐’†๐’‡ ๐’ˆ๐’†๐’•_๐’…๐’๐’„๐’–๐’Ž๐’†๐’๐’•๐’”():

...

So why introduce APIRouter?



The answer became clearer when I started thinking about a real application.



As the project grows, I may have authentication, users, documents, search, AI processing, and many more endpoints.



Keeping all of these routes in one place can quickly become difficult to maintain.

Thatโ€™s where APIRouter becomes useful.



It allows me to organize routes by feature and keep the application structure clean.



So my takeaway is simple:



๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐ฅ๐ž๐ญ๐ฌ ๐ฆ๐ž ๐๐ž๐Ÿ๐ข๐ง๐ž ๐ญ๐ก๐ž ๐ซ๐จ๐ฎ๐ญ๐ž๐ฌ.

๐€๐๐ˆ๐‘๐จ๐ฎ๐ญ๐ž๐ซ ๐ก๐ž๐ฅ๐ฉ๐ฌ ๐ฆ๐ž ๐จ๐ซ๐ ๐š๐ง๐ข๐ณ๐ž ๐ญ๐ก๐ž๐ฆ.



Itโ€™s not required to make FastAPI work. It becomes useful when I want the application to stay organized and maintainable as it grows.



This was one of those small FastAPI concepts that made much more sense once I started looking at the bigger picture.



๐‡๐š๐ฏ๐ž ๐ฒ๐จ๐ฎ ๐ก๐š๐ ๐ญ๐ก๐ž ๐ฌ๐š๐ฆ๐ž ๐ช๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง ๐ฐ๐ก๐ž๐ง ๐ฆ๐จ๐ฏ๐ข๐ง๐  ๐ญ๐จ ๐…๐š๐ฌ๐ญ๐€๐๐ˆ?



๐Ÿ”— ๐†๐ข๐ญ๐‡๐ฎ๐›: https://github.com/epythonlab2/ai-document-api



๐ŸŽฅ ๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž: https://www.youtube.com/watch?v=0SLLG2Z_Htw&list=PLQNCas8_eikM



#FastAPI #Python #APIRouter #BackendDevelopment #SoftwareArchitecture #APIDevelopment #PythonDeveloper
๐Ÿ‘2
The FastAPI Course Github (AI Document API) Project is just updated
Add database connection setup and document model definition
- Implement database connection using SQLAlchemy and environment variables
- Create Document model with fields for title, description, category, and priority
- Update .gitignore to include .env file
- Add required dependencies in pyproject.toml and uv.lock


๐Ÿ”— ๐†๐ข๐ญ๐‡๐ฎ๐›: https://github.com/epythonlab2/ai-document-api

๐ŸŽฅ ๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž: https://www.youtube.com/watch?v=0SLLG2Z_Htw&list=PLQNCas8_eikM
While learning FastAPI, I came across another question: ๐–๐ก๐ฒ ๐๐จ ๐ˆ ๐ง๐ž๐ž๐ ๐๐ฒ๐๐š๐ง๐ญ๐ข๐œ ๐ฐ๐ก๐ž๐ง ๐๐ฒ๐ญ๐ก๐จ๐ง ๐š๐ฅ๐ซ๐ž๐š๐๐ฒ ๐ก๐š๐ฌ ๐ญ๐ฒ๐ฉ๐ž ๐ก๐ข๐ง๐ญ๐ฌ?

For example, I can write:

๐‘‘๐‘’๐‘“ ๐‘๐‘Ÿ๐‘’๐‘Ž๐‘ก๐‘’_๐‘ข๐‘ ๐‘’๐‘Ÿ(๐‘›๐‘Ž๐‘š๐‘’: ๐‘ ๐‘ก๐‘Ÿ, ๐‘Ž๐‘”๐‘’: ๐‘–๐‘›๐‘ก):
...

Python already tells me that name should be a string and age should be an integer.

So what does ๐๐ฒ๐๐š๐ง๐ญ๐ขc add?

The difference became clear when working with API request data.
An API receives data from outside the application, and I need more than just type hints. I need to validate that the data has the expected structure and values.

Thatโ€™s where Pydantic becomes useful.

With FastAPI, I can define a model:

๐‘๐‘™๐‘Ž๐‘ ๐‘  ๐‘ˆ๐‘ ๐‘’๐‘Ÿ๐ถ๐‘Ÿ๐‘’๐‘Ž๐‘ก๐‘’(๐ต๐‘Ž๐‘ ๐‘’๐‘€๐‘œ๐‘‘๐‘’๐‘™):

๐‘›๐‘Ž๐‘š๐‘’: ๐‘ ๐‘ก๐‘Ÿ ๐‘Ž๐‘”๐‘’: ๐‘–๐‘›๐‘ก

FastAPI can then use that model to validate incoming request data automatically.

So my takeaway is:

๐๐ฒ๐ญ๐ก๐จ๐ง ๐ญ๐ฒ๐ฉ๐ž ๐ก๐ข๐ง๐ญ๐ฌ ๐๐ž๐ฌ๐œ๐ซ๐ข๐›๐ž ๐ฐ๐ก๐š๐ญ ๐ˆ ๐ž๐ฑ๐ฉ๐ž๐œ๐ญ.

๐๐ฒ๐๐š๐ง๐ญ๐ข๐œ ๐ก๐ž๐ฅ๐ฉ๐ฌ ๐ฏ๐š๐ฅ๐ข๐๐š๐ญ๐ž ๐ฐ๐ก๐š๐ญ ๐ˆ ๐š๐œ๐ญ๐ฎ๐š๐ฅ๐ฅ๐ฒ ๐ซ๐ž๐œ๐ž๐ข๐ฏ๐ž.

This is another small concept that became much clearer once I started building a real FastAPI application.

๐–๐ก๐š๐ญ ๐ฐ๐š๐ฌ ๐ฒ๐จ๐ฎ๐ซ ๐Ÿ๐ข๐ซ๐ฌ๐ญ ๐ข๐ฆ๐ฉ๐ซ๐ž๐ฌ๐ฌ๐ข๐จ๐ง ๐จ๐Ÿ ๐๐ฒ๐๐š๐ง๐ญ๐ข๐œ ๐ฐ๐ก๐ž๐ง ๐ฒ๐จ๐ฎ ๐ฌ๐ญ๐š๐ซ๐ญ๐ž๐ ๐ฎ๐ฌ๐ข๐ง๐  ๐…๐š๐ฌ๐ญ๐€๐๐ˆ?

๐Ÿ”— ๐†๐ข๐ญ๐‡๐ฎ๐›: https://github.com/epythonlab2/ai-document-api

๐ŸŽฅ ๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž: https://www.youtube.com/watch?v=0SLLG2Z_Htw&list=PLQNCas8_eikM
As I build my ๐€๐ˆ ๐ƒ๐จ๐œ๐ฎ๐ฆ๐ž๐ง๐ญ ๐€๐๐ˆ ๐ฐ๐ข๐ญ๐ก ๐…๐š๐ฌ๐ญ๐€๐๐ˆ, Iโ€™m realizing that building an API is about much more than writing endpoints.


Getting an endpoint to work is just the beginning. A real application needs a solid structure and several pieces working together.

That means thinking about:

- Validating incoming data

- Organizing routes and business logic

- Connecting to a database

- Handling errors properly

- Implementing authentication and permissions

- Testing and deploying the application


Each step introduces a new challenge and a new concept to learn.

Thatโ€™s why Iโ€™m building this project step by step as part of my ๐…๐š๐ฌ๐ญ๐€๐๐ˆ ๐ฌ๐ž๐ซ๐ข๐ž๐ฌ. My goal is to go beyond isolated examples and demonstrate how these concepts come together in a practical AI application.


๐๐ž๐œ๐š๐ฎ๐ฌ๐ž ๐ฅ๐ž๐š๐ซ๐ง๐ข๐ง๐  ๐š ๐Ÿ๐ซ๐š๐ฆ๐ž๐ฐ๐จ๐ซ๐ค ๐ข๐ฌ ๐จ๐ง๐ž ๐ญ๐ก๐ข๐ง๐ . ๐Š๐ง๐จ๐ฐ๐ข๐ง๐  ๐ก๐จ๐ฐ ๐ญ๐จ ๐ฎ๐ฌ๐ž ๐ข๐ญ ๐ญ๐จ ๐›๐ฎ๐ข๐ฅ๐ ๐š ๐ซ๐ž๐š๐ฅ ๐š๐ฉ๐ฉ๐ฅ๐ข๐œ๐š๐ญ๐ข๐จ๐ง ๐ข๐ฌ ๐š๐ง๐จ๐ญ๐ก๐ž๐ซ.

๐Ÿ”— GitHub repository: https://github.com/epythonlab2/ai-document-api

๐ŸŽฅ Explore the full course series: https://www.youtube.com/watch?v=0SLLG2Z_Htw&list=PLQNCas8_eikM


๐–๐ก๐š๐ญ ๐๐จ ๐ฒ๐จ๐ฎ ๐Ÿ๐ข๐ง๐ ๐ฆ๐จ๐ฌ๐ญ ๐œ๐ก๐š๐ฅ๐ฅ๐ž๐ง๐ ๐ข๐ง๐  ๐ฐ๐ก๐ž๐ง ๐ญ๐ฎ๐ซ๐ง๐ข๐ง๐  ๐š ๐ฌ๐ข๐ฆ๐ฉ๐ฅ๐ž ๐€๐๐ˆ ๐ข๐ง๐ญ๐จ ๐š ๐œ๐จ๐ฆ๐ฉ๐ฅ๐ž๐ญ๐ž ๐š๐ฉ๐ฉ๐ฅ๐ข๐œ๐š๐ญ๐ข๐จ๐ง?


#FastAPI #Python #APIDevelopment #BackendDevelopment #AIEngineering
๐Ÿ‘3
As I continue building my AI Document API with FastAPI, Iโ€™m reminding myself to look beyond the happy path.

Itโ€™s easy to test an endpoint with valid data and celebrate when everything works.

But what happens when:

- The client sends invalid data?

- The requested document doesn't exist?

- A database operation fails?

- A user tries to access something they aren't authorized to access?

For me, the goal isnโ€™t simply to make each endpoint work. Itโ€™s to understand how it behaves when things go wrong, too.

Thatโ€™s one of the things Iโ€™m exploring as I build this project step by step with FastAPI.

A good API should handle the expected path well and fail predictably when things go wrong.

As developers, we should test more than whether our code works. We should also test how it fails.

When reviewing an API endpoint, what do you check first: input validation, error handling, or authorization?

๐Ÿ”— GitHub project: https://github.com/epythonlab2/ai-document-api

๐ŸŽฅ Follow the FastAPI course series: https://www.youtube.com/watch?v=0SLLG2Z_Htw&list=PLQNCas8_eikM


#FastAPI #Python #APIDevelopment #BackendDevelopment #SoftwareEngineering
Stop Accepting AI Code Without Reading It | Review AI-Generated Code
https://youtu.be/mfqI3w4Npsc
AI-Generated Python Code Is Not Always Correct | Code Review
https://youtu.be/mJLwFf0dHSA
Speed Up Pandas: 3 Performance Tips for Faster Dataframes https://youtu.be/3vX1S2qxDu8
๐Ÿ‘3
๐Ÿš€ Iโ€™m Open to New Opportunities in Python, Machine Learning, and Data Engineering!

Iโ€™m looking to connect with individuals, teams, and organizations where I can use my technical skills to solve real-world problems, share knowledge, and create meaningful impact.

Here are three areas where Iโ€™d love to contribute:

๐Ÿ”น Content Creation & Technical Education
Creating practical, engaging tutorials on Python, Machine Learning, and Data Engineering to help developers learn, build, and grow.

๐Ÿ”น Backend Development & AI Engineering
Building reliable backend systems, ML-powered applications, and APIs using Python, FastAPI, and modern AI/ML technologies.

๐Ÿ”น Mentoring & Knowledge Sharing
Helping aspiring developers strengthen their Python, Machine Learning, and Data Engineering skills through practical guidance and project-based learning.

๐Ÿ’ก What am I looking for?
Opportunities to collaborate on exciting projects, contribute to impactful teams, create educational content, and mentor the next generation of developers.

If youโ€™re hiring, building something interesting, or know someone looking for these skills, Iโ€™d love to connect!

๐Ÿ“ฉ Feel free to send me a message or tag someone who might be interested. Letโ€™s build something meaningful together.

#Python #MachineLearning #DataEngineering #FastAPI #AI #BackendDevelopment #Mentorship #ContentCreation #OpenToOpportunities
๐Ÿ‘3๐ŸŽ‰1