Machine Learning with Python – Telegram
Machine Learning with Python
68.8K subscribers
1.34K photos
109 videos
175 files
1.01K links
Learn Machine Learning with hands-on Python tutorials, real-world code examples, and clear explanations for researchers and developers.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
Coefficient: 1.0


#97. LogisticRegression()
Implements Logistic Regression for classification.

from sklearn.linear_model import LogisticRegression
X = [[-1], [0], [1], [2]]
y = [0, 0, 1, 1]
clf = LogisticRegression().fit(X, y)
print(f"Prediction for [[-2]]: {clf.predict([[-2]])}")

Prediction for [[-2]]: [0]


#98. KMeans()
K-Means clustering algorithm.

from sklearn.cluster import KMeans
X = [[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]]
kmeans = KMeans(n_clusters=2, n_init='auto').fit(X)
print(kmeans.labels_)

[0 0 0 1 1 1]
(Note: Cluster labels may be flipped, e.g., [1 1 1 0 0 0])


#99. accuracy_score()
Calculates the accuracy classification score.

from sklearn.metrics import accuracy_score
y_true = [0, 1, 1, 0]
y_pred = [0, 1, 0, 0]
print(accuracy_score(y_true, y_pred))

0.75


#100. confusion_matrix()
Computes a confusion matrix to evaluate the accuracy of a classification.

from sklearn.metrics import confusion_matrix
y_true = [0, 1, 0, 1]
y_pred = [1, 1, 0, 1]
print(confusion_matrix(y_true, y_pred))

[[1 1]
[0 2]]


━━━━━━━━━━━━━━━
By: @CodeProgrammer
7🆒4👍2
Forwarded from Kaggle Data Hub
Unlock premium learning without spending a dime! ⭐️ @DataScienceC is the first Telegram channel dishing out free Udemy coupons daily—grab courses on data science, coding, AI, and beyond. Join the revolution and boost your skills for free today! 📕

What topic are you itching to learn next? 😊
https://news.1rj.ru/str/DataScienceC 🌟
Please open Telegram to view this post
VIEW IN TELEGRAM
2
💡 Top 50 Pillow Operations for Image Processing
👇👇👇👇👇
Please open Telegram to view this post
VIEW IN TELEGRAM
3
💡 Top 50 Pillow Operations for Image Processing

I. File & Basic Operations

• Open an image file.
from PIL import Image
img = Image.open("image.jpg")

• Save an image.
img.save("new_image.png")

• Display an image (opens in default viewer).
img.show()

• Create a new blank image.
new_img = Image.new("RGB", (200, 100), "blue")

• Get image format (e.g., 'JPEG').
print(img.format)

• Get image dimensions as a (width, height) tuple.
width, height = img.size

• Get pixel format (e.g., 'RGB', 'L' for grayscale).
print(img.mode)

• Convert image mode.
grayscale_img = img.convert("L")

• Get a pixel's color value at (x, y).
r, g, b = img.getpixel((10, 20))

• Set a pixel's color value at (x, y).
img.putpixel((10, 20), (255, 0, 0))


II. Cropping, Resizing & Pasting

• Crop a rectangular region.
box = (100, 100, 400, 400)
cropped_img = img.crop(box)

• Resize an image to an exact size.
resized_img = img.resize((200, 200))

• Create a thumbnail (maintains aspect ratio).
img.thumbnail((128, 128))

• Paste one image onto another.
img.paste(another_img, (50, 50))


III. Rotation & Transformation

• Rotate an image (counter-clockwise).
rotated_img = img.rotate(45, expand=True)

• Flip an image horizontally.
flipped_img = img.transpose(Image.FLIP_LEFT_RIGHT)

• Flip an image vertically.
flipped_img = img.transpose(Image.FLIP_TOP_BOTTOM)

• Rotate by 90, 180, or 270 degrees.
img_90 = img.transpose(Image.ROTATE_90)

• Apply an affine transformation.
transformed = img.transform(img.size, Image.AFFINE, (1, 0.5, 0, 0, 1, 0))


IV. ImageOps Module Helpers

• Invert image colors.
from PIL import ImageOps
inverted_img = ImageOps.invert(img)

• Flip an image horizontally (mirror).
mirrored_img = ImageOps.mirror(img)

• Flip an image vertically.
flipped_v_img = ImageOps.flip(img)

• Convert to grayscale.
grayscale = ImageOps.grayscale(img)

• Colorize a grayscale image.
colorized = ImageOps.colorize(grayscale, black="blue", white="yellow")

• Reduce the number of bits for each color channel.
posterized = ImageOps.posterize(img, 4)

• Auto-adjust image contrast.
adjusted_img = ImageOps.autocontrast(img)

• Equalize the image histogram.
equalized_img = ImageOps.equalize(img)

• Add a border to an image.
bordered = ImageOps.expand(img, border=10, fill='black')


V. Color & Pixel Operations

• Split image into individual bands (e.g., R, G, B).
r, g, b = img.split()

• Merge bands back into an image.
merged_img = Image.merge("RGB", (r, g, b))

• Apply a function to each pixel.
brighter_img = img.point(lambda i: i * 1.2)

• Get a list of colors used in the image.
colors = img.getcolors(maxcolors=256)

• Blend two images with alpha compositing.
# Both images must be in RGBA mode
blended = Image.alpha_composite(img1_rgba, img2_rgba)


VI. Filters (ImageFilter)
5
• Apply a simple blur filter.
from PIL import ImageFilter
blurred_img = img.filter(ImageFilter.BLUR)

• Apply a box blur with a given radius.
box_blur = img.filter(ImageFilter.BoxBlur(5))

• Apply a Gaussian blur.
gaussian_blur = img.filter(ImageFilter.GaussianBlur(radius=2))

• Sharpen the image.
sharpened = img.filter(ImageFilter.SHARPEN)

• Find edges.
edges = img.filter(ImageFilter.FIND_EDGES)

• Enhance edges.
edge_enhanced = img.filter(ImageFilter.EDGE_ENHANCE)

• Emboss the image.
embossed = img.filter(ImageFilter.EMBOSS)

• Find contours.
contours = img.filter(ImageFilter.CONTOUR)


VII. Image Enhancement (ImageEnhance)

• Adjust color saturation.
from PIL import ImageEnhance
enhancer = ImageEnhance.Color(img)
vibrant_img = enhancer.enhance(2.0)

• Adjust brightness.
enhancer = ImageEnhance.Brightness(img)
bright_img = enhancer.enhance(1.5)

• Adjust contrast.
enhancer = ImageEnhance.Contrast(img)
contrast_img = enhancer.enhance(1.5)

• Adjust sharpness.
enhancer = ImageEnhance.Sharpness(img)
sharp_img = enhancer.enhance(2.0)


VIII. Drawing (ImageDraw & ImageFont)

• Draw text on an image.
from PIL import ImageDraw, ImageFont
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", 36)
draw.text((10, 10), "Hello", font=font, fill="red")

• Draw a line.
draw.line((0, 0, 100, 200), fill="blue", width=3)

• Draw a rectangle (outline).
draw.rectangle([10, 10, 90, 60], outline="green", width=2)

• Draw a filled ellipse.
draw.ellipse([100, 100, 180, 150], fill="yellow")

• Draw a polygon.
draw.polygon([(10,10), (20,50), (60,10)], fill="purple")


#Python #Pillow #ImageProcessing #PIL #CheatSheet

━━━━━━━━━━━━━━━
By: @CodeProgrammer
17🔥6👍2🎉2
Core Python Cheatsheet.pdf
173.3 KB
Python is a high-level, interpreted programming language known for its simplicity, readability, and
 versatility. It was first released in 1991 by Guido van Rossum and has since become one of the most
 popular programming languages in the world.
 Python’s syntax emphasizes readability, with code written in a clear and concise manner using whitespace and indentation to define blocks of code. It is an interpreted language, meaning that
 code is executed line-by-line rather than compiled into machine code. This makes it easy to write and test code quickly, without needing to worry about the details of low-level hardware.
 Python is a general-purpose language, meaning that it can be used for a wide variety of applications, from web development to scientific computing to artificial intelligence and machine learning. Its simplicity and ease of use make it a popular choice for beginners, while its power and flexibility make it a favorite of experienced developers.
 Python’s standard library contains a wide range of modules and packages, providing support for
 everything from basic data types and control structures to advanced data manipulation and visualization. Additionally, there are countless third-party packages available through Python’s package manager, pip, allowing developers to easily extend Python’s capabilities to suit their needs.
 Overall, Python’s combination of simplicity, power, and flexibility makes it an ideal language for a wide range of applications and skill levels.


https://news.1rj.ru/str/CodeProgrammer ⚡️
Please open Telegram to view this post
VIEW IN TELEGRAM
10👍3👎2
🏆 Unlock Data Analysis: 150 Tips, Practical Code

📢 Unlock data analysis mastery! Explore 150 essential tips, each with clear explanations and practical code examples to boost your skills.

⚡️ Tap to unlock the complete answer and gain instant insight.

━━━━━━━━━━━━━━━
By: @CodeProgrammer 💛
Please open Telegram to view this post
VIEW IN TELEGRAM
4👍2👏2
This media is not supported in your browser
VIEW IN TELEGRAM
This combination is perhaps as low as we can get to explain how the Transformer works

#Transformers #LLM #AI

https://news.1rj.ru/str/CodeProgrammer 👍
2🔥1
python-interview-questions.pdf
1.2 MB
100 Python Interview Questions and Answers

This book is a practical guide to mastering Python interview preparation. It contains 100 carefully curated questions with clear, concise answers designed in a quick-reference style.

#Python #PythonTips #PythonProgramming

https://news.1rj.ru/str/CodeProgrammer
7🔥2
Python Interview Codes Cheatsheet
7
🏆 Python NumPy Tips

📢 Unlock the power of NumPy! Get essential Python tips for creating and manipulating arrays effectively for data analysis and scientific computing.

Tap to unlock the complete answer and gain instant insight.

━━━━━━━━━━━━━━━
By: @CodeProgrammer
8👏2🎉2👍1
🤖🧠 The Transformer Architecture: How Attention Revolutionized Deep Learning

🗓️ 11 Nov 2025
📚 AI News & Trends

The field of artificial intelligence has witnessed a remarkable evolution and at the heart of this transformation lies the Transformer architecture. Introduced by Vaswani et al. in 2017, the paper “Attention Is All You Need” redefined the foundations of natural language processing (NLP) and sequence modeling. Unlike its predecessors – recurrent and convolutional neural networks, ...

#TransformerArchitecture #AttentionMechanism #DeepLearning #NaturalLanguageProcessing #NLP #AIResearch
5
🏆 Streamline Your Email Sending

📢 Effortlessly send emails to large audiences! This guide unlocks the power of email automation for your information and promotional campaigns.

Tap to unlock the complete answer and gain instant insight.

━━━━━━━━━━━━━━━
By: @CodeProgrammer
8🎉1
Media is too big
VIEW IN TELEGRAM
The easiest way to write documentation for code

The open Davia project allows you to generate neat internal documentation with visual diagrams for any code.

Just install it on your system, follow the steps in their documentation, run the command in the project folder, and voila, it will generate complete documentation with structured visuals that you can view and edit 💯

👉 https://github.com/davialabs/davia

https://news.1rj.ru/str/CodeProgrammer 🩵
Please open Telegram to view this post
VIEW IN TELEGRAM
9
This media is not supported in your browser
VIEW IN TELEGRAM
Brought an awesome repo for those who love learning from real examples. It contains over a hundred open-source clones of popular services: from Airbnb to YouTube

Each project is provided with links to the source code, demos, stack denoscription, and the number of stars on GitHub. Some even have tutorials on how to create them

Grab it on GitHub 🍯: https://github.com/gorvgoyl/clone-wars

👉 https://news.1rj.ru/str/CodeProgrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
13👍2🎉1
Tip for clean code in Python:

Use Dataclasses for classes that primarily store data. The @dataclass decorator automatically generates special methods like __init__(), __repr__(), and __eq__(), reducing boilerplate code and making your intent clearer.

from dataclasses import dataclass

# --- BEFORE: Using a standard class ---
# A lot of boilerplate code is needed for basic functionality.

class ProductOld:
def __init__(self, name: str, price: float, sku: str):
self.name = name
self.price = price
self.sku = sku

def __repr__(self):
return f"ProductOld(name='{self.name}', price={self.price}, sku='{self.sku}')"

def __eq__(self, other):
if not isinstance(other, ProductOld):
return NotImplemented
return (self.name, self.price, self.sku) == (other.name, other.price, other.sku)

# Example Usage
product_a = ProductOld("Laptop", 1200.00, "LP-123")
product_b = ProductOld("Laptop", 1200.00, "LP-123")

print(product_a) # Output: ProductOld(name='Laptop', price=1200.0, sku='LP-123')
print(product_a == product_b) # Output: True


# --- AFTER: Using a dataclass ---
# The code is concise, readable, and less error-prone.

@dataclass(frozen=True) # frozen=True makes instances immutable
class Product:
name: str
price: float
sku: str

# Example Usage
product_c = Product("Laptop", 1200.00, "LP-123")
product_d = Product("Laptop", 1200.00, "LP-123")

print(product_c) # Output: Product(name='Laptop', price=1200.0, sku='LP-123')
print(product_c == product_d) # Output: True


#Python #CleanCode #ProgrammingTips #SoftwareDevelopment #Dataclasses #CodeQuality

━━━━━━━━━━━━━━━
By: @CodeProgrammer
7🎉1
Stochastic and deterministic sampling methods in diffusion models produce noticeably different trajectories, but ultimately both reach the same goal.

Diffusion Explorer allows you to visually compare different sampling methods and training objectives of diffusion models by creating visualizations like the one in the 2 videos.

Additionally, you can, for example, train a model on your own dataset and observe how it gradually converges to a sample from the correct distribution.

Check out this GitHub repository:
https://github.com/helblazer811/Diffusion-Explorer

👉 https://news.1rj.ru/str/CodeProgrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
11👍3🔥2🏆1
Forwarded from Machine Learning
📌 PyTorch Tutorial for Beginners: Build a Multiple Regression Model from Scratch

🗂 Category: DEEP LEARNING

🕒 Date: 2025-11-19 | ⏱️ Read time: 14 min read

Dive into PyTorch with this hands-on tutorial for beginners. Learn to build a multiple regression model from the ground up using a 3-layer neural network. This guide provides a practical, step-by-step approach to machine learning with PyTorch, ideal for those new to the framework.

#PyTorch #MachineLearning #NeuralNetwork #Regression #Python
5