Forwarded from Machine Learning with Python
from SQL to pandas.pdf
1.3 MB
#DataScience #SQL #pandas #InterviewPrep #Python #DataAnalysis #CareerGrowth #TechTips #Analytics
Please open Telegram to view this post
VIEW IN TELEGRAM
π7β€3π₯1
# Real-World Case Study: E-commerce Product Pipeline
import boto3
from PIL import Image
import io
def process_product_image(s3_bucket, s3_key):
# 1. Download from S3
s3 = boto3.client('s3')
response = s3.get_object(Bucket=s3_bucket, Key=s3_key)
img = Image.open(io.BytesIO(response['Body'].read()))
# 2. Standardize dimensions
img = img.convert("RGB")
img = img.resize((1200, 1200), Image.LANCZOS)
# 3. Remove background (simplified)
# In practice: use rembg or AWS Rekognition
img = remove_background(img)
# 4. Generate variants
variants = {
"web": img.resize((800, 800)),
"mobile": img.resize((400, 400)),
"thumbnail": img.resize((100, 100))
}
# 5. Upload to CDN
for name, variant in variants.items():
buffer = io.BytesIO()
variant.save(buffer, "JPEG", quality=95)
s3.upload_fileobj(
buffer,
"cdn-bucket",
f"products/{s3_key.split('/')[-1].split('.')[0]}_{name}.jpg",
ExtraArgs={'ContentType': 'image/jpeg', 'CacheControl': 'max-age=31536000'}
)
# 6. Generate WebP version
webp_buffer = io.BytesIO()
img.save(webp_buffer, "WEBP", quality=85)
s3.upload_fileobj(webp_buffer, "cdn-bucket", f"products/{s3_key.split('/')[-1].split('.')[0]}.webp")
process_product_image("user-uploads", "products/summer_dress.jpg")
By: @DataScienceM π
#Python #ImageProcessing #ComputerVision #Pillow #OpenCV #MachineLearning #CodingInterview #DataScience #Programming #TechJobs #DeveloperTips #AI #DeepLearning #CloudComputing #Docker #BackendDevelopment #SoftwareEngineering #CareerGrowth #TechTips #Python3
β€1
In Python, building AI-powered Telegram bots unlocks massive potential for image generation, processing, and automationβmaster this to create viral tools and ace full-stack interviews! π€
Learn more: https://hackmd.io/@husseinsheikho/building-AI-powered-Telegram-bots
https://t.me/DataScienceMπ¦Ύ
# Basic Bot Setup - The foundation (PTB v20+ Async)
from telegram.ext import Application, CommandHandler, MessageHandler, filters
async def start(update, context):
await update.message.reply_text(
"β¨ AI Image Bot Active!\n"
"/generate - Create images from text\n"
"/enhance - Improve photo quality\n"
"/help - Full command list"
)
app = Application.builder().token("YOUR_BOT_TOKEN").build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
# Image Generation - DALL-E Integration (OpenAI)
import openai
from telegram.ext import ContextTypes
openai.api_key = os.getenv("OPENAI_API_KEY")
async def generate(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not context.args:
await update.message.reply_text("β Usage: /generate cute robot astronaut")
return
prompt = " ".join(context.args)
try:
response = openai.Image.create(
prompt=prompt,
n=1,
size="1024x1024"
)
await update.message.reply_photo(
photo=response['data'][0]['url'],
caption=f"π¨ Generated: *{prompt}*",
parse_mode="Markdown"
)
except Exception as e:
await update.message.reply_text(f"π₯ Error: {str(e)}")
app.add_handler(CommandHandler("generate", generate))
Learn more: https://hackmd.io/@husseinsheikho/building-AI-powered-Telegram-bots
#Python #TelegramBot #AI #ImageGeneration #StableDiffusion #OpenAI #MachineLearning #CodingInterview #FullStack #Chatbots #DeepLearning #ComputerVision #Programming #TechJobs #DeveloperTips #CareerGrowth #CloudComputing #Docker #APIs #Python3 #Productivity #TechTips
https://t.me/DataScienceM
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1
π How to Use GPT-5 Effectively
π Category: LARGE LANGUAGE MODELS
π Date: 2025-11-07 | β±οΈ Read time: 8 min read
Master the next generation of AI with this guide on using GPT-5 effectively. Explore its advanced features and settings to learn how to optimally apply the model's power to your specific workflows and use cases, maximizing its potential and impact on your projects.
#GPT5 #AI #LargeLanguageModels #TechTips
π Category: LARGE LANGUAGE MODELS
π Date: 2025-11-07 | β±οΈ Read time: 8 min read
Master the next generation of AI with this guide on using GPT-5 effectively. Explore its advanced features and settings to learn how to optimally apply the model's power to your specific workflows and use cases, maximizing its potential and impact on your projects.
#GPT5 #AI #LargeLanguageModels #TechTips
β€2
Data leakage is one of the main reasons why ML demos look impressive... and then fail in production. π
The model didn't become smarter.
It just happened to see the correct answers in advance.
In 4 minutes, you'll understand where data leaks hide. π
Let's break it down below: π
1. Data Leakage π³οΈ
Data leakage occurs when information that won't be available at the time of actual prediction is used during the model training process.
Because of this, metrics on the validation stage can look much better than the actual quality of the model on new, previously unseen data.
2. Model Evaluation βοΈ
The test set isn't just "additional data".
It's a simulation of the future.
Only train the model on the information that would have been available to you at the time of prediction.
Evaluate it on examples that the model couldn't have influenced during training.
3. Direct Leakage π¨
This is the most obvious type of leakage.
Examples:
- a field with information from the future;
- an ID that encodes the target variable;
- a variable that appears only after an event has occurred;
- duplicate records in both the training and test sets.
If a feature doesn't exist at the time of inference (prediction), then it's likely a source of data leakage.
4. Indirect Leakage π΅οΈ
This is the type of leakage that most often traps teams.
You perform normalization, imputation, feature selection, outlier removal, or dimensionality reduction before splitting the data into a training and test set.
The model didn't directly see the data from the test set.
But your preprocessing pipeline already saw it.
5. Train/Test Split βοΈ
Wrong:
Right:
The same idea applies to imputers, encoders, feature selection, PCA, and any preprocessing step that is trained on the data.
6. Cross-Validation π
Each fold is a mini-experiment with a training and test set.
Therefore, preprocessing should be performed within each fold.
If you prepared the entire dataset once and then ran cross-validation, each fold would already have had access to its held-out data.
7. Pipelines π οΈ
A pipeline isn't just a way to make the code cleaner.
It's also a defense against data leakage.
Combine preprocessing, feature selection, and the model into a single pipeline, and then pass this pipeline to cross-validation or hyperparameter search (grid search).
8. AI Engineering Version π€
Data leaks also occur in RAG systems and when evaluating LLMs.
Leakage occurs when you tune chunks, prompts, re-rankers, thresholds, or examples on the same evaluation dataset that you later present as "held-out".
As a result, your benchmark turns into training data.
9. Leakage Checklist β
Before trusting the obtained metric, ask yourself:
- Could this feature exist at the time of prediction?
- Was any transformation (transform) step trained (fit) on the test data?
- Did cross-validation include the entire pipeline?
- Were we tuning parameters on the final evaluation dataset?
If the answer is "yes", then the metric likely doesn't reflect the actual quality of the model.
#MachineLearning #DataScience #MLOps #DataLeakage #ArtificialIntelligence #TechTips
β¨ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk
βοΈ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
The model didn't become smarter.
It just happened to see the correct answers in advance.
In 4 minutes, you'll understand where data leaks hide. π
Let's break it down below: π
1. Data Leakage π³οΈ
Data leakage occurs when information that won't be available at the time of actual prediction is used during the model training process.
Because of this, metrics on the validation stage can look much better than the actual quality of the model on new, previously unseen data.
2. Model Evaluation βοΈ
The test set isn't just "additional data".
It's a simulation of the future.
Only train the model on the information that would have been available to you at the time of prediction.
Evaluate it on examples that the model couldn't have influenced during training.
3. Direct Leakage π¨
This is the most obvious type of leakage.
Examples:
- a field with information from the future;
- an ID that encodes the target variable;
- a variable that appears only after an event has occurred;
- duplicate records in both the training and test sets.
If a feature doesn't exist at the time of inference (prediction), then it's likely a source of data leakage.
4. Indirect Leakage π΅οΈ
This is the type of leakage that most often traps teams.
You perform normalization, imputation, feature selection, outlier removal, or dimensionality reduction before splitting the data into a training and test set.
The model didn't directly see the data from the test set.
But your preprocessing pipeline already saw it.
5. Train/Test Split βοΈ
Wrong:
fit the scaler on all data β split the data β evaluate
Right:
split the data β fit the scaler only on the training set β apply it to both the training and test sets
The same idea applies to imputers, encoders, feature selection, PCA, and any preprocessing step that is trained on the data.
6. Cross-Validation π
Each fold is a mini-experiment with a training and test set.
Therefore, preprocessing should be performed within each fold.
If you prepared the entire dataset once and then ran cross-validation, each fold would already have had access to its held-out data.
7. Pipelines π οΈ
A pipeline isn't just a way to make the code cleaner.
It's also a defense against data leakage.
Combine preprocessing, feature selection, and the model into a single pipeline, and then pass this pipeline to cross-validation or hyperparameter search (grid search).
8. AI Engineering Version π€
Data leaks also occur in RAG systems and when evaluating LLMs.
Leakage occurs when you tune chunks, prompts, re-rankers, thresholds, or examples on the same evaluation dataset that you later present as "held-out".
As a result, your benchmark turns into training data.
9. Leakage Checklist β
Before trusting the obtained metric, ask yourself:
- Could this feature exist at the time of prediction?
- Was any transformation (transform) step trained (fit) on the test data?
- Did cross-validation include the entire pipeline?
- Were we tuning parameters on the final evaluation dataset?
If the answer is "yes", then the metric likely doesn't reflect the actual quality of the model.
#MachineLearning #DataScience #MLOps #DataLeakage #ArtificialIntelligence #TechTips
β¨ Join Best TG Channels https://t.me/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 14 chats.
β€3π3