home
arrow_upward

AI MLOps

My notes

[ work in progress ]


Groundwork, Concepts, Pre-requisites


Things to get ready before jumping into AI/ML.



Basic concepts to understand before working with AI, ML

  1. While classic programming is getting answers by applying rules to data, machine learning as a process is combining data and existing answers to generate 'rules' that can then be applied to new data to derive answers.
  2. Data Science, Deep Learning, Machine Learning, AI are (wrongly) used interchangeably. These are separate, albeit overlapping concepts. Data Science is the umbrella term. Machine Learning is one application of AI. Deep Learning is a machine learning category.
    There can be AI outside the Data Science umbrella, but most applications of AI in IT are in the Data Science realm.
  3. Regression vs. Neural Network models. If you are trying to uncover patterns / rules in a structured dataset, use regression models like GBRT. If you you are trying to identify patterns / rules in an image or text input, then Neural Networks are used.


Common terminology in ML (or How to sound like an AI ML expert)



Top priority areas in ML

XGBoost : for tabular data problems.
Convolutional models: image problems.
Transformer models: text problems.


Hyperparameters





Math

Dev Env

Models, practice

Popular Gradient Boost model: XGBoost
Popular CNN models:

Thumb-rules, good practices, tips, recommendations

These are not rules, just suggestions and observations from people with experience

Awesome references

The AI-MLOps course by IISc (coordinated by Talentsprint) is a deep dive into applied AI, ML. Excellent for practitioners.

The Neural Network Playground lets you play with four datasets. Try out different learning rates, activation functions, classifications and regularization. Useful to visually understand the effect of each parameter on the neural network.

The book Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow by Aurélien Géron (Author)




Machine Learning - the process

The high level process is:
  1. Data collection and processing
  2. Feature engineering
  3. Data splitting
  4. Model selection
  5. Model training
  6. Model evaluation
  7. Final model selection
  8. Deployment
  9. Documentation and reporting
  10. Iterative improvement

XGBoost model training and evaluation Example

After you finish loading the dataframe, understanding the 'shape' of the data and checking out the records, remove the outliers.

Then install and import xgboost:
pip install xgboost 
import xgboost as xgb


Next, initialize and train the model using XGBClassifier:
xgb_classifier = xgb.XGBClassifier(
	objective='binary:logistic',
 n_estimators=100,    
max_depth=3,max_depth=3, 
learning_rate=0.1)
	
xgb_classifier.fit(X_train, y_train)
	


Math foundation for AI ML development

Linear algebra and calculus help with the data science part of AI MLOps implementations. An understanding of probability and statistics is useful for model implementation. For example, if you want to predict the probability of rain or likelyhood of reaching a place through dense traffic, you need to understand probability and stats. Similarly if you want to predict the chances of a batsman scoring a century or being bowled out.

Basic math concepts and terms worth understanding before jumping into AI: Important terms:
Feature engineering. Example - converting 1-5 rating scale to Negative, Neutral, Positive ratings. Helps in turning a dataset into a uniform distribution.
One hot encoding.
Label encoding. Converting categories into numberic representations.
Statistical estimation.
Normal (Gaussian) distribution.
A scaled histogram of a scaled variable is the PDF of that variable.
How to find out how many records should be selected for sampling? Distribution does not change much by adding another data point.
Mean absolute deviation (M.A.D.)
Mean of square deviation (M.S.D. or variance)
Standard normal table


ML Models deep-dive, practice

Good reference:
Decision Tree
Data driven models for classification and regression. Decision tree models will give zero error on training data set. Powerful model for fitting capable dataset. Trained by greedy optimization algo called Classification and regression tree algorithm (CART). Decision trees work like recursive if-else conditions, eliminating branches based on the criteria separating one decision from another. For example to decide the specie of a flower, the data points considered mybe petal length, petal width, color. A decision tree will check for petal length condition, then go down a branch for which petal length matches, then check for petal width and go down the sub-branch. At one point the decision branches are exhausted and a final prediction is available.

Terms used in DT

Confusion matrix. Precision.Recall.F1 score. F2 score.
Root mean square error. Mean absolute error. Relative error. R2=1-MSE/Variance
K-fold cross validation. Hyper parameter tuning.


Logistic regression is the simplest neural network we can build, uses Sigmoid activation function.

What is a loss function?
Gradient descent algorith. Stochastic Gradient Descent Algorithm.
Activation functions - ReLU for dense layers. Sigmoid/softmax for classification. No activation for regression.
Good rules of thumb : use ReLU, five layers, all neurons available (validate this)