Total Pageviews

Thursday, August 13, 2026

matplotlib

SciPy

 SciPy

NumPy

 NumPy

scikit-learn

 Scikit-Learn provides core machine learning tools. These include model evaluation functions like accuracy_score, data preparation tools like StandardScaler, and model selection helpers like train_test_split. It also features clustering algorithms like KMeans, classification models like SVC, and regression models like LinearRegression.

Evaluation and Preprocessing
  • Measures accuracy and error with accuracy_score and mean_squared_error
  • Builds confusion matrices with confusion_matrix
  • Scales data using StandardScaler and MinMaxScaler
  • Encodes labels with LabelEncoder
  • Fills missing data via SimpleImputer 
Selection and Clustering
  • Splits data using train_test_split
  • Tunes parameters with GridSearchCV
  • Validates models using cross_val_score
  • Groups data with KMeans
  • Uses hierarchical groups via AgglomerativeClustering 
Classification and Regression
  • Predicts classes with KNeighborsClassifier and SVC
  • Uses trees and Bayes via DecisionTreeClassifier and GaussianNB
  • Fits linear equations with LinearRegression and Lasso
  • Predicts values using RandomForestRegressor 

4. image input and display (gray scale)

 


8. Image Thresholding using OpenCV (or Image Binarization).








 

7. Image Thresholding using OpenCV (or Image Binarization).








 

6. OpenCV image reading and writing

 


5. OpenCV image reading and writing

 5. 





3. Get number of pixel, dimension of image

 import cv2


img = cv2.imread('im1.jpg')


cv2.imshow("Cute Kitens", img)

print("Image Properties")

print("- Number of Pixels: " + str(img.size))

print("- Shape/Dimensions: " + str(img.shape))



OUTPUT:

Image Properties
- Number of Pixels: 489402
- Shape/Dimensions: (318, 513, 3)


2. image input and display (color)

 import cv2

img = cv2.imread("im.jpeg", cv2.IMREAD_COLOR)

cv2.imshow("Cute Kitens", img)

cv2.waitKey(0)

cv2.destroyAllWindows()

output:






1. image input and display



CODE :


 import cv2

img = cv2.imread("im.jpeg")

cv2.imshow("Cute Kitens", img)

cv2.waitKey(0)

cv2.destroyAllWindows()



Monday, August 10, 2026

MACHINE LEARNING USING PYTHON


1. scikit-learn   
2.   NumPy    CLICK
3. SciPy  CLICK
4. matplotlib 
5. pandas


Training data is processed using three primary machine learning frameworks: 
1. supervised learning (using labeled data to predict outcomes), 
2.unsupervised learning (finding hidden patterns in unlabeled data), and 
3. reinforcement learning (learning via trial, error, and rewards).


Supervised Learning Models

Supervised models use input data paired with known output labels to learn the relationship between them.

  • Regression models: Predict continuous numeric values like prices or temperatures (e.g., Linear Regression, Ridge, Lasso).
  • Classification models: Predict discrete categories or classes (e.g., Logistic Regression, Support Vector Machines, Naive Bayes).
  • Decision Trees & Ensembles: Combine multiple decision rules or trees to boost accuracy (e.g., Random Forest).

 

Unsupervised Learning Models

Unsupervised models process data without predefined labels, allowing the system to discover structural properties on its own. 

    • Clustering: Groups similar data points together based on shared traits (e.g., K-Means, Hierarchical clustering).
    • Dimensionality Reduction: Simplifies complex datasets while retaining vital patterns (e.g., Principal Component Analysis). Specialized and Advanced Models

 

Semi-Supervised Learning: Trains on a small amount of labeled data combined with a large pool of unlabeled data to save labeling costs. 

Reinforcement Learning: Uses an agent that takes actions in an environment and optimizes behavior based on cumulative rewards or penalties rather than static training datasets. 

Deep Learning (Neural Networks): Multi-layered artificial neural networks capable of parsing complex unstructured inputs like images, speech, and text.

 1. Predicting a Number (Regression)

If your goal is to forecast a continuous, numerical value, you will use Supervised Regression models.
  • Example Use Case: Predicting home prices, forecasting stock trends, or estimating delivery times.
  • Common Models: Linear Regression, Random Forest Regressor, or Gradient Boosting (XGBoost).
2. Sorting Categories (Classification)
If your goal is to assign data points into distinct, predefined buckets, you will use Supervised Classification models
  • Example Use Case: Sorting emails into "Spam" or "Inbox", identifying if an image shows a cat or a dog, or predicting if a transaction is fraudulent.
  • Common Models: Logistic Regression, Support Vector Machines (SVM), Random Forest Classifier, or Neural Networks. 
3. Grouping Data (Clustering)
If your goal is to find hidden patterns and group data together without knowing the categories in advance, you will use Unsupervised Clustering models
  • Example Use Case: Segmenting customers by purchasing behavior, grouping similar news articles together, or finding anomalies in network traffic.
  • Common Models: K-Means Clustering, Hierarchical Clustering, or DBSCAN.


Feature / CapabilityScikit-learnPyTorchTensorFlow
Primary FocusTraditional ML & Tabular DataDeep Learning & ResearchProduction Deep Learning
HardwareCPU OnlyGPU & TPU AccelerationGPU & TPU Acceleration
Data ScalingSmall to Medium (Spreadsheets/CSVs)Massive (Images, Audio, Text)Massive (Big Data pipelines)
Graph TypeStatic Execution (Pre-built APIs)Dynamic Graph (Pythonic/Flexible)Static Graph (Highly Optimized)
Code ComplexityLow (model.fit() & model.predict())Medium to High (Custom training loops)Medium (via high-level Keras API)







Model FamilyInterpretabilityHandles High Dimensions?Training SpeedPrimary Weakness
Linear Models
(e.g., Logistic Regression)
High
(Direct feature weights)
No
(Prone to underfitting)
FastCannot capture complex nonlinear rules
Tree/Ensemble Models
(e.g., Random Forest)
Medium
(Feature importance scores)
ModerateMediumLarge memory footprint for deep trees
Distance-Based Models
(e.g., K-Nearest Neighbors)
Low
(Instance-dependent)
No
(Suffers from "curse of dimensionality")
Instant
(No active training phase)
Inference slows down heavily as dataset grows
Kernel/Matrix Methods
(e.g., Support Vector Machines)
Low
(Black-box decision boundaries)
YesSlow on large dataComputationally expensive tuning (O(n³) scaling)
Neural Networks
(Deep Learning)
None
(Millions of abstract weights)
YesVery Slow
(Requires epochs on GPUs)
Prone to overfitting without massive training data









Models Uset to train:




1. Regression Models (Predicting Numbers)
These models are used when your target variable is a continuous numerical value.
python
# Linear Regression (Simple baseline)
from sklearn.linear_model import LinearRegression

# Ridge and Lasso (Linear regression with regularization to prevent overfitting)
from sklearn.linear_model import Ridge, Lasso

# Random Forest Regressor (Tree-based ensemble)
from sklearn.ensemble import RandomForestRegressor

# Gradient Boosting Regressor (Advanced, high-performance ensemble)
from sklearn.ensemble import GradientBoostingRegressor


2. Classification Models (Sorting Categories)

These models are used when your target variable consists of discrete classes or labels.
python
# Logistic Regression (Standard baseline for binary classification)
from sklearn.linear_model import LogisticRegression

# Support Vector Classifier (Effective in high-dimensional spaces)
from sklearn.svm import SVC

# Random Forest Classifier (Robust tree-based classification)
from sklearn.ensemble import RandomForestClassifier

# Naive Bayes (Fast, commonly used for text classification/spam filtering)
from sklearn.naive_bayes import GaussianNB

3. Clustering Models (Grouping Unlabeled Data)

These unsupervised models group data based on feature similarity without relying on pre-existing labels.
python
# K-Means Clustering (Groups data into a predefined 'K' number of clusters)
from sklearn.cluster import KMeans

# DBSCAN (Density-based clustering; great for finding noise and anomalies)
from sklearn.cluster import DBSCAN

# Agglomerative Clustering (Hierarchical tree-based clustering)
from sklearn.cluster import AgglomerativeClustering


4. Deep Learning Frameworks (Neural Networks)

For complex unstructured data (images, text, audio), you build custom network layouts using these foundational imports.
python
# --- PyTorch Architecture Headers ---
import torch
import torch.nn as nn          # Contains neural network layers (Linear, Conv2d)
import torch.optim as optim    # Contains optimization math (Adam, SGD)

# --- TensorFlow / Keras Architecture Headers ---
import tensorflow as tf
from tensorflow.keras import layers, models # Tools to build structured layers
















1. Classification
Classification predicts categorical outputs, meaning it assigns data into predefined classes like spam/non-spam emails or disease risk categories. These algorithms learn to map input features to discrete labels. Here are some classification algorithms:

Logistic Regression
Decision Tree
Random Forest
K-Nearest Neighbors (KNN)
Naive Bayes
Support Vector Machine


2. Regression
Regression, predicts continuous values, such as house prices or product sales. It learns the relationship between input features and a numerical target variable. Here are some regression algorithms:

Linear Regression
Polynomial Regression
Ridge Regression
Lasso Regression
Decision tree
Random Forest


1. Clustering
Clustering is the process of grouping data points into clusters based on their similarity. This technique is useful for identifying patterns and relationships in data without the need for labeled examples. Common techniques include:

K-Means
DBSCAN
Mean-shift
2. Dimensionality Reduction Techniques
Dimensionality reduction helps reduce the number of features while preserving important information. Common techniques include:

Principal Component Analysis
Independent Component Analysis
3. Association Rule Learning
Association rule learning is a technique for discovering relationships between items in a dataset. It identifies rules that indicate the presence of one item implies the presence of another item with a specific probability. Common techniques include:

Apriori
FP-growth
Eclat





Here are some of most common reinforcement learning algorithms:

Q-learning: Learns the best action for each state based on expected rewards.
SARSA (State-Action-Reward-State-Action): Similar to Q-learning but updates values for the action actually taken.
Deep Q-learning: Uses neural networks to handle complex state-action relationships
Types of Reinforcement Learning
Positive Reinforcement: Rewards desired behavior (e.g., giving points for correct answers).
Negative Reinforcement: Removes negative outcomes to encourage good actions (e.g., turning off a buzzer after the right move).








Scikit-Learn (Traditional Machine Learning)
  • LinearRegression: Basic regression for continuous data.
  • LogisticRegression: Standard baseline for binary classification.
  • RandomForestClassifier / RandomForestRegressor: Powerful ensemble tree models.
  • GradientBoostingClassifier: Sequential tree building for high accuracy.
  • SVC: Support Vector Classifier for complex boundaries.
  • KMeans: Unsupervised clustering algorithm.
XGBoost & LightGBM (Gradient Boosting)
  • XGBClassifier / XGBRegressor: High-performance, scalable gradient boosting.
  • LGBMClassifier / LGBMRegressor: Fast, leaf-wise tree growth models.
PyTorch (Deep Learning Ecosystem)
  • torchvision.models.resnet50: Industry standard for image classification.
  • torchvision.models.vit_b_16: Vision Transformer for advanced image tasks.
  • torchaudio.models.wave2vec2_model: Architecture for speech processing.
  • torch.nn.Transformer: Raw building block for sequence-to-sequence tasks.
TensorFlow / Keras (Deep Learning Ecosystem)
  • keras.applications.ResNet50: Pre-trained deep residual network for vision.
  • keras.applications.MobileNetV3Large: Lightweight, mobile-optimized vision model.
  • keras.applications.EfficientNetB0: State-of-the-art scaling for image tasks.
  • keras.layers.LSTM: Recurrent layer stringed together for text/time-series.
Hugging Face Transformers (NLP & GenAI)
  • bert-base-uncased: Baseline for text classification and extraction.
  • roberta-base: Improved, harder-trained version of BERT.
  • gpt2: Standard starting point for causal text generation.
  • meta-llama/Meta-Llama-3-8B: State-of-the-art large language model for fine-tuning.
  • google/vit-base-patch16-224: Vision transformer adapted for Hugging Face pipelines. 
Statsmodels (Statistical & Time Series)
  • OLS: Ordinary Least Squares regression with deep statistical summaries.
  • ARIMA: Autoregressive Integrated Moving Average for time-series forecasting.
  • Logit: Logistic regression specialized for statistical inference.