Data Science | Machine Learning with Python for Researchers
32.5K subscribers
3.09K photos
107 videos
22 files
3.31K links
ads: @HusseinSheikho

The Data Science and Python channel is for researchers and advanced programmers

Buy ads: https://telega.io/c/dataScienceT
Download Telegram
💡 ViT for Fashion MNIST Classification

This lesson demonstrates how to use a pre-trained Vision Transformer (ViT) to classify an image from the Fashion MNIST dataset. ViT treats an image as a sequence of patches, similar to how language models treat sentences, making it a powerful architecture for computer vision tasks. We will use a model from the Hugging Face Hub that is already fine-tuned for this specific dataset.

from transformers import ViTImageProcessor, ViTForImageClassification
from datasets import load_dataset
import torch

# 1. Load a model fine-tuned on Fashion MNIST and its processor
model_name = "abhishek/autotrain-fashion-mnist-283834433"
processor = ViTImageProcessor.from_pretrained(model_name)
model = ViTForImageClassification.from_pretrained(model_name)

# 2. Load the dataset and get a sample image
dataset = load_dataset("fashion_mnist", split="test")
image = dataset[100]['image'] # Get the 100th image

# 3. Preprocess the image and prepare it for the model
inputs = processor(images=image, return_tensors="pt")

# 4. Perform inference to get the classification logits
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits

# 5. Get the predicted class and its label
predicted_class_idx = logits.argmax(-1).item()
predicted_class = model.config.id2label[predicted_class_idx]

print(f"Image is a: {dataset[100]['label']}")
print(f"Model predicted: {predicted_class}")


Code explanation: This script uses the transformers library to load a ViT model specifically fine-tuned for Fashion MNIST classification. It then loads the dataset, selects a single sample image, and uses the model's processor to convert it into the correct input format. The model performs inference, and the script identifies the most likely class from the output logits, printing the final human-readable prediction.

#Python #MachineLearning #ViT #ComputerVision #HuggingFace

━━━━━━━━━━━━━━━
By: @DataScienceT
💡 ViT for Fashion MNIST Classification

This lesson demonstrates how to use a pre-trained Vision Transformer (ViT) to classify an image from the Fashion MNIST dataset. ViT treats an image as a sequence of patches, similar to how language models treat sentences, making it a powerful architecture for computer vision tasks. We will use a model from the Hugging Face Hub that is already fine-tuned for this specific dataset.

from transformers import ViTImageProcessor, ViTForImageClassification
from datasets import load_dataset
import torch

# 1. Load a model fine-tuned on Fashion MNIST and its processor
model_name = "abhishek/autotrain-fashion-mnist-283834433"
processor = ViTImageProcessor.from_pretrained(model_name)
model = ViTForImageClassification.from_pretrained(model_name)

# 2. Load the dataset and get a sample image
dataset = load_dataset("fashion_mnist", split="test")
image = dataset[100]['image'] # Get the 100th image

# 3. Preprocess the image and prepare it for the model
inputs = processor(images=image, return_tensors="pt")

# 4. Perform inference to get the classification logits
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits

# 5. Get the predicted class and its label
predicted_class_idx = logits.argmax(-1).item()
predicted_class = model.config.id2label[predicted_class_idx]

print(f"Image is a: {dataset[100]['label']}")
print(f"Model predicted: {predicted_class}")


Code explanation: This script uses the transformers library to load a ViT model specifically fine-tuned for Fashion MNIST classification. It then loads the dataset, selects a single sample image, and uses the model's processor to convert it into the correct input format. The model performs inference, and the script identifies the most likely class from the output logits, printing the final human-readable prediction.

#Python #MachineLearning #ViT #ComputerVision #HuggingFace

━━━━━━━━━━━━━━━
By: @DataScienceT
🤖🧠 Reflex: Build Full-Stack Web Apps in Pure Python — Fast, Flexible and Powerful

🗓️ 29 Oct 2025
📚 AI News & Trends

Building modern web applications has traditionally required mastering multiple languages and frameworks from JavaScript for the frontend to Python, Java or Node.js for the backend. For many developers, switching between different technologies can slow down productivity and increase complexity. Reflex eliminates that problem. It is an innovative open-source full-stack web framework that allows developers to ...

#Reflex #FullStack #WebDevelopment #Python #OpenSource #WebApps
Top 100 Data Analyst Interview Questions & Answers

#DataAnalysis #InterviewQuestions #SQL #Python #Statistics #CaseStudy #DataScience

Part 1: SQL Questions (Q1-30)

#1. What is the difference between DELETE, TRUNCATE, and DROP?
A:
DELETE is a DML command that removes rows from a table based on a WHERE clause. It is slower as it logs each row deletion and can be rolled back.
TRUNCATE is a DDL command that quickly removes all rows from a table. It is faster, cannot be rolled back, and resets table identity.
DROP is a DDL command that removes the entire table, including its structure, data, and indexes.

#2. Select all unique departments from the employees table.
A: Use the DISTINCT keyword.

SELECT DISTINCT department
FROM employees;


#3. Find the top 5 highest-paid employees.
A: Use ORDER BY and LIMIT.

SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 5;


#4. What is the difference between WHERE and HAVING?
A:
WHERE is used to filter records before any groupings are made (i.e., it operates on individual rows).
HAVING is used to filter groups after aggregations (GROUP BY) have been performed.

-- Find departments with more than 10 employees
SELECT department, COUNT(employee_id)
FROM employees
GROUP BY department
HAVING COUNT(employee_id) > 10;


#5. What are the different types of SQL joins?
A:
(INNER) JOIN: Returns records that have matching values in both tables.
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table.
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table.
FULL (OUTER) JOIN: Returns all records when there is a match in either the left or right table.
SELF JOIN: A regular join, but the table is joined with itself.

#6. Write a query to find the second-highest salary.
A: Use OFFSET or a subquery.

-- Method 1: Using OFFSET
SELECT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1;

-- Method 2: Using a Subquery
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);


#7. Find duplicate emails in a customers table.
A: Group by the email column and use HAVING to find groups with a count greater than 1.

SELECT email, COUNT(email)
FROM customers
GROUP BY email
HAVING COUNT(email) > 1;


#8. What is a primary key vs. a foreign key?
A:
• A Primary Key is a constraint that uniquely identifies each record in a table. It must contain unique values and cannot contain NULL values.
• A Foreign Key is a key used to link two tables together. It is a field (or collection of fields) in one table that refers to the Primary Key in another table.

#9. Explain Window Functions. Give an example.
A: Window functions perform a calculation across a set of table rows that are somehow related to the current row. Unlike aggregate functions, they do not collapse rows.

-- Rank employees by salary within each department
SELECT
name,
department,
salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as dept_rank
FROM employees;


#10. What is a CTE (Common Table Expression)?
A: A CTE is a temporary, named result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement. It helps improve readability and break down complex queries.
1