0% found this document useful (0 votes)
61 views

Machine Learning - Brief

Machine learning algorithms allow computers to learn from data and make predictions. There are different types of machine learning including supervised learning, unsupervised learning, reinforcement learning, and deep learning. Supervised learning uses labeled training data to learn relationships between inputs and outputs and make predictions for new data. Common supervised learning algorithms include k-nearest neighbors, naive Bayes, decision trees, random forests, logistic regression, and support vector machines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Machine Learning - Brief

Machine learning algorithms allow computers to learn from data and make predictions. There are different types of machine learning including supervised learning, unsupervised learning, reinforcement learning, and deep learning. Supervised learning uses labeled training data to learn relationships between inputs and outputs and make predictions for new data. Common supervised learning algorithms include k-nearest neighbors, naive Bayes, decision trees, random forests, logistic regression, and support vector machines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

[ Machine Learning ]

What is Machine Learning?


A set of Algorithms that gives the computers the ability to learn from data,
and then make predictions and decisions.

ML vs DL vs Ai ?
Artificial Intelligence (Ai):
study/process which enables machines
to mimic human behavior,
through particular algorithm.

Machine Learning (ML):


ML is the subset of Ai.
ML is an Ai algorithm which allows system
to learn from data and make decisions

Deep Learning (DL):


DL is the subset of ML.
DL is a ML algorithm that uses deep
(more than one layer) neural networks
to analyze data and provide output

Why Machine Learning ?


• As a part of the Ai revolution, machine learning will transform every business
both online and offline – how decisions are made, how processes improve

• This technology will redefine many industries, such as: Healthcare, Financial services, Energy
and many other fields that directly impact our lives

• The power of machine learning is allowing us to solve more complex problems,


faster than any time before.

How Does it Work ?


What is a machine learning Model ?
• A “model” in machine learning is the output of a machine learning algorithm run on data.
• The best analogy is to think of the machine learning model as a “program.”
• Model == Model Data + Prediction Algorithm

Data Mining:
• The process of extracting useful information from a huge amount of data
• It’s a tool used by humans to discover new, accurate, and useful patterns in the data.

You first identify business goals and data mining goal, then you start this process:

Machine Learning vs Data Mining :


Machine Learning Process Work Flow:
High level ML Workflow Detailed ML Process Workflow

Also called the ML life-cycle,


this high-level workflow gives an
intuition about the overall work
through the ML process.

A more detailed version is present


to give a deeper insight about
the actual steps in each phase.

About Data Cleaning (Scrubbing):


Data cleaning is the process of fixing or removing incorrect, corrupted, incorrectly formatted, duplicate, or
incomplete data within a dataset. When combining multiple data sources, there are many opportunities for
data to be duplicated or mislabeled. garbage in, garbage out!
If data is incorrect, outcomes and algorithms are unreliable, even though they may look correct .

Steps:
1. Duplicate & irrelevant observations
removing duplicated to avoid inaccuracy and skewness.
2. Structural errors (normalize & standardize)
Handling strange naming conventions, typos
incorrect capitalization, inconsistent data formats.
3. Filter unwanted outliers
handling outliers, such as removing them or imputing them
with more reasonable values.
4. Handle missing data
handle them by imputing missing data, dropping the missing data
or leaving it as-is
5. Verify data quality
checking for consistency between different parts of the
dataset, and validating the accuracy of the data against external sources
Types of Machine Learning:

Basic Terminology:
Labels
A label is the thing we're predicting—the dependent y variable in simple linear regression.
The label could be the future price of wheat, the kind of animal shown in a picture… etc.

Features
A feature is an input variable—the independent x variable in simple linear regression.
Features could either be:

• Qualitative: categorical data (genders, nationality, marital status…)


• Quantitative: numerical data, both discrete and continuous (price, temperature …etc.)

Examples
An example is a particular instance of data, x (feature vector). We break examples into two categories:

• labeled examples: includes both feature(s) and the label.


• unlabeled examples: contains features but not the label.
Supervised vs Unsupervised:

Supervised machine learning:


You supervise the machine while training it to work on its own. This requires labeled training data

Unsupervised machine learning


Unsupervised learning: There is training data, but it’s unlabeled
Supervised Learning in Detail:
The goal of supervised machine learning is to learn a mapping function that can accurately
predict the target variable (or output) for new, unseen input data.

1- Step One: Preparing the data (data split)


first of all, the data is divided into 3 sets:
1. Training set: portion of the labeled data
used to train the machine learning model.

2. Validation set: portion of the labeled data


used as a reality check during/after training to:
• Ensure the model can handle new, unseen data
• Choosing the model with minimum loss *
• Tune the model’s hyperparameters**
• Prevent the model from overfitting***

3. Test set: portion of the labeled data,


used after completing the training to check
how generalizable the final chosen model is.

data splitting techniques:


Various data splitting techniques can be used like :

• Random (Holdout method)


the most basic and straight forward method, but it comes with a drawback,
For example, if a dataset has 1000 images, of which 800 belong to the category: “dog” and 200 belong to the
category: “cat,” it might so happen that the training set consists only dog images, while the validation set
consists of only cat images!
• Stratified
dividing the labeled data into subsets based on the distribution of the target variable.
Suppose a dataset consists of 1000 images, of which 600 are dog images and 400 are cat images. In that case,
stratified sampling ensures that 60% of the images are of category “dog” and 40% are of category “cat” in the
training and validation sets. can be used in conjunction with the holdout method or k-fold cross-validation.
• Cross-Validation (k-fold cross validation)
a more robust technique for data splitting, where we divide the labeled data into K equal-sized subsets, or
"folds". The model is trained K times, each time using a different fold as the validation set and the remaining
folds as the training set. The performance of the model is then averaged across the K runs.
When used with “Stratified” method, it creates the Stratified k-fold cross-validation
2- Step Two: Choosing an Algorithm
Based on the task at hand, we can one of two categories of supervised learning:

Regression
Used to predict continuous values such as sales, salary, weight, or temperature.
For example: A dataset containing features of the house such as size, number of bedrooms, number of
baths, neighborhood, etc. and the price of the house, a Regression algorithm can be trained to learn the
relationship between the features and the price of the house.

@ Common Regression Algorithms:

• Linear Regression
• Polynomial Regression
• #Decision Tree Regressor*
• #Random Forest Regressor*
• Neural Networks

Classification
Used for predicting discrete outcomes, if the outcome can take two possible values such as
[True or False], [Dog or Cat], [Yes or No], it is known as Binary Classification. When the outcome contains
more than two possible values [dog, cat, lizard…], it is known as Multiclass Classification.

@ Common Classification Algorithms:

• k-Nearest Neighbor (k-NN)


• Support Vector Machine (SVM)
• Naïve Bayes
• #Decision Tree Classifier*
• #Random Forest Classifier*
• Logistic Regression

@ Evaluation Metrices:

Confusion Matrix

Recall: how many relevant items are retrieved?


Calculated as = TP / (TP + FN).

Precision: how many retrieved items are relevant?


Calculated as = TP / (TP + FP).

F1-Score: The harmonic mean of precision and recall.


‫‪Supervised Algorithms Recap (AR) //‬‬
‫‪k-Nearest Neighbor (k-NN) -1‬‬
‫دى خوارزمية تصنيف (‪ ,)Classification‬الغرض منها بعد ما تدرب المودل بتاعك‬
‫انها تقدر تحدد العينة الجديدة اللى دخلت تقع فى انهى تصنيف من اللى‬
‫المودل اتدرب عليهم ‪...‬‬

‫بنعمل ده عن طريق مقارنة العنصر الجديد باقرب جيرانه من ال ‪data points‬‬


‫اللى حواليه ‪ ,‬والرمز ‪ k‬بيشير لعدد الجيران اللى هنشتغل عليهم ونحسب‬
‫مسافة العنصر الجديد منهم عشان نعرف بينمتى لمين بنسبة اكبر ‪.‬‬

‫‪Naïve Bays -2‬‬


‫خوارزمية تصنيف معتمدة على نظرية ‪ Bays‬فى االحتماالت‬
‫وكلمة ‪ Naïve‬هنا (واللى معناها ساذج) بترمز الفتراض ان‬
‫وجود صفة أ فى شئ ملهاش عالقة بوجود صفة ب فيه !‬
‫بمعنى ان كل صفة "مستقلة" وليها نسبة خاصة بيها انها تكون‬
‫موجودة فى الشئ ده أو أل ‪.‬‬
‫مثال لو عندك قطط وكالب ‪ ,‬وعندك الصفات دى‬
‫(ودان صغيرة‪ ,‬فرو‪ ,‬لون برتقانى‪ ,‬ديل طويل)‪...‬‬
‫فانت بتحسب نسبة وجود كل صفة "لوحدها" عند الكالب و القطط‬

‫ولما يجيلك كائن جديد بتشوف نسبة كل صفة من دول عندو ايه‬
‫وبعدين تحسب "احتمال" كونه كلب او قطة حسب مجموع نسب الصفات دى‪.‬‬

‫‪Logistics Regression -3‬‬


‫خوارزمية تنصيف ثنائية (‪ )Binary Classification‬بتجاوبك بنتيجة من اتنين‬
‫اه‪/‬ال ‪ ,‬ناجح‪/‬راسب ‪ ,‬مقبول‪/‬مرفوض ‪ ...‬الخ‬

‫● فكرة عملها انه الصفة المتغير ( ‪ ) independent variable x‬فى بينها‬


‫وبين النتيجة المراد توقعها ( ‪ ) dependent variable y‬عالقة خطية‬
‫وبناءا عليه نقدر نتوقع النتيجة النهائية حسب درجة الصفة المتغيرة دى‬

‫مثال‪ ,‬لو جالنا شخص عمره ‪ 32‬سنة ‪ ,‬فحسب الموديل ده‬


‫هو سنه اقل من الحد الفاصل ‪40( Threshold Value‬سنة)‬
‫يعنى احتمالية انه يشترى التامين اقل ‪ ,‬فبنصنفه على انه (‪)No‬‬
‫النه اقرب للفئة دى احصائيا‪.‬‬
‫‪Support Victor Machine (SVM) -4‬‬
‫خوارزمية تصنيف فكرتها االساسية قائمة على رسم‬
‫حد فاصل ‪ Hyperplane‬يقسم الداتا لمجموعتين بافضل شكل‬
‫ممكن ‪ ,‬عشان لما تيجى داتا جديدة اقدر اصنفها بسهولة ‪....‬‬

‫● والمقياس الختيار الخط الفاصل ده ان المسافة بين‬


‫الخط بتاعنا وبين اقرب نقط داتا تكون اكبر ما يمكن‬
‫من كال الطرفين وبنسميها ‪. Maximum Margin‬‬

‫● مصطلح ‪ Support Vector‬بيطلق على ال ‪ datapoints‬اللى بتكون على اطراف‬


‫ال ‪ Hyperplane‬واللى بتساعدنى فى التصنيف بحيث لو جاتلى داتا جديدة‬
‫بصنفها تبع المجموعة االقرب لل ‪ Support Vector‬ده ‪.‬‬

‫‪Decision Trees -5‬‬


‫الخوارزمية دى ممكن تستخدم لتوقع تنصيف معين وساعتها‬
‫بنسميها ‪ Classification Tree :‬او لتوقع قيمة معينة وساعتها‬
‫بنسميها ‪. Regression Tree :‬‬

‫الشجرة بتاعتنا عامة بيكون ليها نقطة بداية بنسميها ‪Root Node‬‬
‫و بينزل منها فروع ‪ Branches‬او ‪Decision Nodes‬‬
‫وفى النهاية عندنا ال ‪ Leaves‬واللى بتشاور على تصنيف معين‬

‫👈فى حالة ال ‪ Classification Tree‬اهم حاجة هو ال ‪Split‬‬


‫بمعنى انك تحدد هتبدأ بانهى صفة ك ‪ , Root Node‬والقرار ده‬
‫بيتبنى بكذا طريقة زى‪ Entropy :‬و ‪...Gini Impurity‬‬
‫واالخيرة دى بتتبنى على معيار ال ‪ Impurity‬وهو مستوى‬
‫نقاء و جودة ارتباط الصفة دى بالنتيجة النهائية ‪,‬‬
‫وكل ما كانت قيمة ال‪ impurity‬اقل كل ما كان جودة‬
‫الصفة وارتباطها بالنتيجة النهائية اعلى‪.‬‬

‫● لما نيجى نقرر انهى صفة هتكون هى ال ‪Root Node‬‬


‫بنحسب ال ‪ Gini Impurity‬لكل صفة رئيسية ‪ Feature‬وبعدين‬
‫ناخد الصفة االكثر نقاءا ( اقل ‪ ) impurity‬وتبقى هى رأسه الهرم‬

‫وهكذا بنستمر على نفس الطريقة بحيث ال ‪ Leaf‬النهائية‬


‫تكون قرار حاسم قدر االمكان ( ‪) Impurity =~ 0‬‬
‫‪Random Forest -6‬‬
‫دى كمان خوارزمية بتستخدم لتوقع تصنيف معين‬
‫او قيمة معينة (‪)Classification & Regression‬‬

‫● الخوارزمية دى بتعالج مشكلة التداخل ‪Overfitting‬‬


‫اللى كانت بتحصل فى خوارزمية ال ‪Decision Tree‬‬
‫لما بتقابلك داتا فيها كذا ‪ Feature‬وبتبقى الشجرة‬
‫بتاعتك متشعبة وعميقة جدا (‪)Deep & Complex‬‬

‫● كمان بترفع نسبة الدقة ‪ Accuracy‬بتاعة النتيجة النهائية‬


‫باستخدام مفهوم ال ‪ , Bagging‬وهو ان بتجمع نتيجة كذا‬
‫خوارزمية متشابهه سوى ( كذا ‪ ) Tree‬وفى االخر بتعمل‬
‫اما ‪ Voting‬لو غرضك التصنيف او ‪ Average‬لو غرضك رقم او قيمة عددية‪.‬‬

‫● الخطوة االولى المختلفة هنا انك بتقسم ال ‪ Training data‬لعدد من األجزاء بطريقة اسمها ‪Bootstrap Sampling‬‬
‫وكل جزء بتدخله على شجرة لوحده تتدرب عليه وتديلك نتيجة‪.‬‬
‫● والخطوة االخيرة زى ما قلنا انك بتجمع النتايج دى كلها وبناءا عليها بتاخد قرار نهائى‪.‬‬

‫‪Linear Regression -7‬‬


‫اول وابسط خوارزمية لتوقع قيمة مجهولة بناءا على عالقة ‪Correlation‬‬
‫بينها وبين قيمة ‪ /‬عدة قيم معلومة ‪ ,‬زى مثال العمر والطول هنا‬

‫على محور السينات ‪ independent variable x‬بنحط قراءات الصفة المتغير‬


‫على محور الصادات ‪ dependent variable y‬بنقيس قيمة النتيحة المطلوبة‬
‫المسافة بين اى نقطة وبين الخط المرسوم بتسمى ‪)R( residual‬‬

‫● اول واهم خطوة فى تنفيذ الموديل بعد عرض الداتا على ‪Scatter plot‬‬
‫مثال ‪ ,‬هو اختيار مكان خط االنحدار ‪ Regression line‬اللى هيوضحلنا‬
‫قوة و اتجاه العالقة بين الصفة المتغيرة ‪ x‬والقيمة المراد استنتاجها ‪y‬‬

‫● من اشهر الطرق فى اختيار خط االنحدار هى‬


‫ال ‪ Least Squares‬واللى فيها ببساطة بنحسب‬
‫مجموع ‪ R2‬بتاع النقط لكل خط افتراضى ‪ ,‬وبنختار‬
‫الخط اللى قيمة ‪ R2‬الكلية عنده اصغر قيمة‬

‫● وخالص كدا بعد ما بنحدد الخط بتاعنا والموديل‬


‫يبقى جاهز ‪ ,‬بندخل داتا للصفة ‪ x‬وهو بيتوقع ‪y‬‬
‫‪Unsupervised Algorithms Recap (AR) //‬‬
‫‪Clustering -8‬‬
‫خوارزمية تجميع داتا ‪ ,‬هدفها انها تجمع العينات اللى في بينها صفات مشتركة‬
‫وعندنا كذا اسلوب فى التجميع على حسب حالة الداتا ‪:‬‬

‫‪: (K-Mean) Exclusive Clustering‬‬


‫يا ابيض يا اسود ‪ ,‬مفيش وسط ‪ ...‬العينة الزم تنتمى لمجموعة واحدة بس‬

‫‪: (C-Mean) Overlapping Clustering‬‬


‫ابيض واسود ورمادى ‪ ...‬مفيش مشكلة ان عينة تنتمى الكتر من مجموعة فى نفس الوقت‬

‫● من اشهر الخوارزميات فى التجميع واللى هنركز عليها هى ‪k-Mean Clustering‬‬


‫وطبعا زى ما اخدت بالك هى بتتبع اسلوب ال ‪Exclusive Clustering‬‬

‫فى اربع خطوات بنمشى عليهم عشان نوصل للنتيجة النهائية‪:‬‬

‫‪ -1‬تحديد عدد المجموعات (‪)K‬‬


‫وده ليه طرق رياضية زى ال ‪ Elbow Method‬بس نقدر نبدأ‬
‫برقم عشوائى وليكن ‪ 3‬مثال‬

‫‪ -2‬اختيار مكان المحاور ‪ Centroids‬عشوائيا‬


‫دور المحاور دى انك بتقيس البعد العمودى لكل نقطة‬
‫وتديها لون حسب اقرب محور ليها‬

‫‪ -3‬حساب معدل التقارب ‪ Convergence‬لكل مجموعة‬


‫وده عن طريق حساب متوسط بعد النقط عن المحور‬
‫‪ Mean Distance‬فى المجموعة الواحدة‪ .‬خليك فاكر الرقم ده !‬
‫( كلمة ‪ Mean‬فى االسم جاية من هنا )‬

‫‪ -4‬اختيار مكان جديد للمحاور !‬


‫وهتعيد خطوة رقم ‪ 3‬تانى وتحسب معدل التقارب‬
‫الخطوة دى هتكرر عدد مرات معين (‪ )Iterations‬محدد مسبقا‬
‫او لحد ما توصل الفضل معدل تقارب ممكن !‬
Association Rule -9
Data Mining ‫قاعدة االرتباط هى مفهوم بيستخدم فى ال‬
‫ وبيشير لوجود ارتباط بين عنصرين او اكتر‬Machine Learning ‫وال‬

‫● بتستخدم بشكل واسع فى مجال التجارة لفهم االنماط الشرائية‬


‫ واللى فيها بتدرس ارتباط‬Market Basket Analysis ‫عن طريق‬
‫العناصر اللى اشتراها العمالء ببعض‬

.‫● الغرض االساسى للمتاجر هو عامة زيادة المبيعات‬


:‫وطبعا معلومة زى دى ممكن تفيدهم باكتر من شكل زى‬

‫تنظيم رفوف العرض بحيث المنتجات اللى بتتباع سوىتكون قريبة من بعض فتعلى نسبة المبيعات‬ -
)‫الخ‬.. ‫ بناءا على قوة االرتباط بينهم ( زى منتجات االطفال والعربيات‬,‫تسويق منتجات معينة مع بعضها‬ -
‫استهداف شرائح من العمالء بعروض وخصومات خاصة بناءا على نمطهم الشرائى‬ -

Association Rule Mining ‫● من اشهر الخوارزميات المستخدمة فى ال‬


" Frequency ‫ واللى بتستخدم مبدأ " التكرار‬Apriori Algorithm ‫هى‬
. ‫ بين العناصر المطلوبة‬Association ‫عشان تستنج وجود‬

)Transactions( ‫● بناءا على تحليل عمليات الشراء السابقة للعمالء‬


‫ واللى منها‬frequent itemset ‫نقدر نستخرج المجموعات المتكررة‬
. ‫نقدر نعرف العناصر المرتبط ظهورها ببعض‬

----------------------------------------------------------------------------------------------------------------------------------------

Model Evaluation Metrices


Bias: the difference between the predicted values and the actual values.
high-bias results in underfitting, the model is too simple and can’t capture trends in the dataset.

Variance: the variability of the model's predictions for different training sets.
high-variance results in overfitting, the model is too complex and performs well on the training data
but poorly on new, unseen test data.

The bias-variance trade-off:


As the complexity of the model increases,
the bias decreases but the variance increases, and vice versa.

ROC(Receiver Operating Characteristic) : a graphical plot that shows


the performance of a binary classifier system as its discrimination
threshold is varied. such as logistic regression, decision trees,
random forests, support vector machines.

You might also like