Complete beginner's guide to ML concepts – click a topic to jump
What is Machine Learning? Machine Learning (ML) is a subset of artificial intelligence (AI) that enables systems to learn and improve from experience without being explicitly programmed. ML algorithms build mathematical models based on training data to make predictions or decisions.
Why ML? It helps in finding patterns in large datasets, making predictions, automating tasks, and continuously improving performance.
मशीन लर्निंग क्या है? यह AI का एक भाग है, जिसमें सिस्टम बिना स्पष्ट प्रोग्रामिंग के डेटा से सीखता है और अनुभव से बेहतर होता है। ML एल्गोरिदम ट्रेनिंग डेटा के आधार पर मॉडल बनाते हैं ताकि भविष्यवाणी या निर्णय किए जा सकें।
# Simple ML pipeline: Data -> Train Model -> Evaluate -> Predict
# Example: Supervised learning with scikit-learn from sklearn.ensemble import RandomForestClassifier model = RandomForestClassifier() model.fit(X_train, y_train)
# Typical ML code structure X = dataset[['feature1', 'feature2']] y = dataset['target'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
Raw data often needs cleaning and transformation: handling missing values, scaling/normalization, encoding categorical variables, feature selection. Common libraries: pandas, numpy, scikit-learn.
कच्चे डेटा को साफ करना जरूरी है: लापता मान भरना, फीचर्स को एक पैमाने पर लाना, श्रेणियों (categories) को संख्याओं में बदलना आदि।
import pandas as pd from sklearn.preprocessing import StandardScaler, LabelEncoder # Handle missing values df.fillna(df.mean(), inplace=True) # Encode categorical le = LabelEncoder() df['gender'] = le.fit_transform(df['gender']) # Scale features scaler = StandardScaler() X_scaled = scaler.fit_transform(X)
Linear regression models the relationship between a dependent variable (y) and one or more independent variables (X) by fitting a linear equation: y = β0 + β1x1 + ... + βnxn + ε. Used for predicting continuous values (e.g., house prices).
लीनियर रिग्रेशन दो या अधिक चरों के बीच रैखिक संबंध स्थापित करता है। इसका उपयोग निरंतर मान (जैसे घर की कीमत) का अनुमान लगाने में होता है।
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print("Coefficients:", model.coef_)
Classification predicts a categorical label. Examples: spam detection, image recognition. Evaluation metrics: accuracy, precision, recall, F1-score, ROC-AUC.
क्लासिफिकेशन में श्रेणी का अनुमान लगाया जाता है (जैसे ईमेल स्पैम है या नहीं)। सटीकता, प्रेसिजन, रिकॉल आदि से मॉडल का मूल्यांकन करते हैं।
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
clf = RandomForestClassifier()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
Despite its name, logistic regression is used for binary classification. It models the probability that an instance belongs to a particular class using the logistic (sigmoid) function. Output is between 0 and 1.
लॉजिस्टिक रिग्रेशन दो श्रेणियों (binary) में वर्गीकरण के लिए प्रयोग होता है। यह सिग्मॉइड फंक्शन की मदद से प्रायिकता (0 से 1) देता है।
from sklearn.linear_model import LogisticRegression logreg = LogisticRegression() logreg.fit(X_train, y_train) y_prob = logreg.predict_proba(X_test) # probabilities
Decision trees are flowchart-like structures where each internal node tests a feature, each branch represents outcome, and each leaf holds a class label or value. Easy to interpret, prone to overfitting.
डिसीजन ट्री एक फैसले का पेड़ होता है – हर नोड पर एक शर्त, और हर पत्ती पर परिणाम। इसे समझना आसान है, लेकिन यह ओवरफिटिंग का शिकार हो सकता है।
from sklearn.tree import DecisionTreeClassifier dt = DecisionTreeClassifier(max_depth=5) dt.fit(X_train, y_train)
k-NN is a simple, instance-based learning algorithm. It classifies a point based on majority vote of its k nearest neighbors in feature space. No explicit training; all computation happens during prediction.
k-NN में नए डेटा बिंदु को उसके k निकटतम पड़ोसियों के बहुमत से वर्गीकृत किया जाता है। यह इंस्टेंस-बेस्ड लर्निंग है, ट्रेनिंग के दौरान कुछ नहीं सीखता।
from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=3) knn.fit(X_train, y_train)
k-Means is an unsupervised learning algorithm that partitions data into k clusters. Each point belongs to the cluster with the nearest mean. Used for customer segmentation, image compression, etc.
k-Means बिना लेबल वाले डेटा को k समूहों में बाँटता है। हर बिंदु उस समूह में जाता है जिसके केंद्र के सबसे पास होता है। ग्राहक वर्गीकरण, छवि संपीड़न आदि में उपयोग।
from sklearn.cluster import KMeans kmeans = KMeans(n_clusters=3, random_state=42) kmeans.fit(X) labels = kmeans.labels_ centers = kmeans.cluster_centers_
Regression metrics: Mean Absolute Error (MAE), Mean Squared Error (MSE), R-squared.
Classification metrics: Accuracy, Precision, Recall, F1-score, Confusion Matrix, ROC curve.
Always evaluate on a separate test set or using cross-validation.
रिग्रेशन के लिए MAE, MSE, R-squared। क्लासिफिकेशन के लिए सटीकता, प्रेसिजन, रिकॉल, F1, कन्फ्यूजन मैट्रिक्स। हमेशा टेस्ट सेट या क्रॉस-वैलिडेशन से मूल्यांकन करें।
from sklearn.metrics import classification_report, confusion_matrix print(confusion_matrix(y_test, y_pred)) print(classification_report(y_test, y_pred))
Overfitting: Model learns training data too well, including noise, and performs poorly on new data. (high variance)
Underfitting: Model is too simple and fails to capture patterns in training data. (high bias)
Solutions: cross-validation, regularization, more data, simpler/complex models.
Overfitting: मॉडल ट्रेनिंग डेटा को बहुत अच्छे से सीख लेता है, लेकिन नए डेटा पर खराब प्रदर्शन करता है।
Underfitting: मॉडल बहुत सरल है, पैटर्न नहीं सीख पाता।
# Regularization example (Ridge/Lasso) from sklearn.linear_model import Ridge ridge = Ridge(alpha=1.0) ridge.fit(X_train, y_train)
Bias: Error due to wrong assumptions (underfitting). Variance: Error due to sensitivity to fluctuations in training data (overfitting). The tradeoff is finding the optimal model complexity to minimize total error.
Bias: गलत धारणाओं से उत्पन्न त्रुटि (अंडरफिटिंग)। Variance: ट्रेनिंग डेटा में बदलाव से उत्पन्न त्रुटि (ओवरफिटिंग)। सही संतुलन बनाना होता है।
# Visualizing with learning curves (example) from sklearn.model_selection import learning_curve
Creating new features from existing data to improve model performance. Includes: polynomial features, interaction terms, binning, domain-specific features, feature selection techniques (PCA, feature importance).
मौजूदा डेटा से नए फीचर बनाना ताकि मॉडल बेहतर हो। जैसे दो फीचर का गुणा, पॉलिनोमियल फीचर, डोमेन ज्ञान से नए फीचर।
from sklearn.preprocessing import PolynomialFeatures poly = PolynomialFeatures(degree=2, include_bias=False) X_poly = poly.fit_transform(X)
Neural networks are inspired by the human brain. They consist of layers of interconnected neurons (nodes). Each connection has a weight. Activation functions (ReLU, sigmoid) introduce non-linearity. Simple feedforward networks can learn complex patterns.
न्यूरल नेटवर्क मानव मस्तिष्क से प्रेरित हैं। इनमें परतों में न्यूरॉन्स होते हैं, हर कनेक्शन का वज़न होता है। एक्टिवेशन फंक्शन (ReLU, sigmoid) गैर-रैखिकता लाते हैं।
# Simple NN with TensorFlow/Keras
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(64, activation='relu', input_shape=(n_features,)),
keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy')
Deep learning is a subset of ML using neural networks with many layers (deep architectures). It excels at tasks like image recognition, NLP, speech recognition. Requires large data and computational power. Frameworks: TensorFlow, PyTorch.
डीप लर्निंग ML का एक भाग है जिसमें कई परतों वाले न्यूरल नेटवर्क का उपयोग होता है। छवि पहचान, भाषा अनुवाद जैसे कार्यों में बेहतर। बड़े डेटा और कंप्यूट संसाधन चाहिए।
# Convolutional Neural Network (CNN) snippet
model = keras.Sequential([
keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(28,28,1)),
keras.layers.MaxPooling2D(2,2),
keras.layers.Flatten(),
keras.layers.Dense(10, activation='softmax')
])
# Install essential libraries pip install numpy pandas matplotlib scikit-learn tensorflow
ML models can perpetuate or amplify biases present in training data, leading to unfair outcomes. Important considerations: fairness, accountability, transparency, privacy. Techniques: bias detection, explainable AI (XAI), differential privacy.
ML मॉडल डेटा में मौजूद पूर्वाग्रहों को बढ़ा सकते हैं, जिससे अनुचित परिणाम हो सकते हैं। निष्पक्षता, पारदर्शिता, और गोपनीयता पर ध्यान देना जरूरी है।
# Example: Check for demographic parity in predictions # (conceptual) import fairlearn