How to Build an Expert System with Prolog | AI Tutorial

How to build an Expert system with Prolog

1 Introduction

An expert system is a rule based program that tries to act like a human expert in a narrow domain. With Prolog you can express rules and facts in a natural logic style, so Prolog fits expert systems well.

Darija: النظام الخبير هو واحد النوع ديال البرامج اللي كيتصرف بحال خبير حقيقي فمجال محدد وصغير. مع Prolog نقدرو نكتبو القواعد والحقائق بطريقة منطقية وبسيطة، وهاد الشي كيجعل Prolog مناسب بزاف للنظم الخبيرة.

In this tutorial you learn how to build a simple expert system with Prolog. You see core ideas, then code examples, then practice exercises.

2 Core Concepts Explained

2.1 What is an expert system

An expert system tries to answer questions or give advice in a domain like medicine, troubleshooting, or recommendation. Main parts:

  • Knowledge base contains facts and rules about the domain
  • Inference engine uses logic to answer questions from the user
  • User interface asks questions and prints results

Darija: النظام الخبير كيحاول يجاوب على الأسئلة ولا يعطي نصائح فمجال معين بحال الطب، إصلاح الأجهزة، ولا الاقتراحات. عندو ثلاثة ديال المكونات الرئيسية

  • قاعدة المعارف فيها الحقائق والقواعد على المجال
  • محرك الاستدلال كييستعمل المنطق باش يخرج أجوبة من القواعد
  • واجهة المستخدم كتطرح الأسئلة على المستخدم وكتوريه النتائج

2.2 Why Prolog for expert systems

  • Prolog is logic based
  • You write facts and rules in a direct way
  • The inference engine of Prolog uses backward chaining
  • You focus on knowledge, not on low level control flow

Darija: Prolog مبني على المنطق، وكيخليك تركز على المعارف والقواعد بلا ما تغرق فالتفاصيل ديال التحكم فالكود. محرك Prolog كيدير الاستنتاج بالرجوع للوراء، يعني كيبدا من الهدف وكيقلب على القواعد اللي توصّلو ليه.

2.3 Key Prolog concepts for expert systems

  • Fact simple statement about the world
  • Rule conclusion that depends on conditions
  • Query question that you ask to the system
  • Variables start with uppercase and stand for unknown values

Darija: الحقائق هي جُمل بسيطة كتوصف العالم القواعد هي استنتاجات مرتبطة بشروط والاستعلام هو السؤال اللي كنسولو للنظام المتغيّرات فـ Prolog كيبداو بحرف كبير وكيعبرو على قيم مجهولة.

3 Prolog Syntax and Structure for Expert Systems

3.1 Facts

Example facts for diseases and symptoms

% disease(Name)
disease(flu).
disease(cold).

% symptom(Disease, Symptom)
symptom(flu, fever).
symptom(flu, cough).
symptom(cold, cough).
symptom(cold, sneezing).

English: Each line is one fact. Darija: كل سطر هنا واحد الحقيقة بسيطة.

3.2 Rules

Rules describe when something holds. Example rule for a disease if a person has some symptoms.

% has_disease(Person, Disease)
has_disease(Person, flu) :-
    has_symptom(Person, fever),
    has_symptom(Person, cough).

has_disease(Person, cold) :-
    has_symptom(Person, cough),
    has_symptom(Person, sneezing).

Here :- reads as "if". On the right side you see conditions separated by commas. Prolog treats comma as logical AND.

Darija: الرمز :- كنقراوه "إلا". الشرطين مفصولين بـ , وهاد الشي كيعبّر على "و" منطقية.

3.3 Queries

You ask the system using queries in the Prolog console.

?- has_disease(ali, flu).
?- has_disease(Who, flu).

First query checks if Ali has flu. Second query asks for all people with flu.

Darija: فأول استعلام كنشوفو واش علي عندو la grippe فالثاني كنطلبو جميع الناس اللي عندهم la grippe.

4 Example 1 – Simple Medical Expert System in Prolog

4.1 Knowledge base

% facts about symptoms of diseases
disease(flu).
disease(cold).

symptom(flu, fever).
symptom(flu, cough).
symptom(flu, body_ache).

symptom(cold, cough).
symptom(cold, sneezing).
symptom(cold, runny_nose).

% user symptom facts
has_symptom(ali, fever).
has_symptom(ali, cough).
has_symptom(sara, cough).
has_symptom(sara, sneezing).

4.2 Reasoning rules

% a person has a disease if person has all symptoms linked to that disease
possible_disease(Person, Disease) :-
    disease(Disease),
    symptom(Disease, Symptom),
    has_symptom(Person, Symptom).

This rule says Person has a possible disease if disease exists, symptom belongs to disease, and person has same symptom. You can ask

?- possible_disease(ali, D).
?- possible_disease(sara, D).

Darija: القاعِدة كتعني إلا كان مرض معيّن وعندو واحد العَرَض وهاد العَرَض موجود عند الشخص النظام كيعتبر هاد المرض احتمال عند هاد الشخص ومن بعد نقدر نسول Prolog على الأمراض المحتملة عند علي ولا سارة.

4.3 Simple interactive question system

Now build a small expert system that asks the user about symptoms.

% ask user about a symptom
ask(Symptom) :-
    write('Do you have '),
    write(Symptom),
    write('? (yes or no) '),
    read(Reply),
    Reply == yes.

% dynamic facts to store user answers
:- dynamic has_symptom_user/1.

% gather symptoms from user
collect_symptoms :-
    symptom(_, Symptom),
    \+ has_symptom_user(Symptom),
    ask(Symptom),
    assertz(has_symptom_user(Symptom)),
    fail.
collect_symptoms.

% reason using user symptoms
user_possible_disease(Disease) :-
    disease(Disease),
    symptom(Disease, Symptom),
    has_symptom_user(Symptom).

run_expert_system :-
    retractall(has_symptom_user(_)),
    collect_symptoms,
    write('Possible diseases '), nl,
    user_possible_disease(D),
    write(D), nl,
    fail.
run_expert_system.

Now in the Prolog console run

?- run_expert_system.

System asks questions then prints possible diseases.

Darija: منين تشغّل run_expert_system النظام كيسوّل المستخدم على الأعراض ومن بعد كيعطيه لائحة ديال الأمراض المحتملة.

5 Example 2 – Animal Classification Expert System

5.1 Facts and rules

% animal facts
animal(dog).
animal(cat).
animal(bird).

has_feature(dog, mammal).
has_feature(dog, four_legs).
has_feature(dog, barks).

has_feature(cat, mammal).
has_feature(cat, four_legs).
has_feature(cat, meows).

has_feature(bird, two_legs).
has_feature(bird, flies).

% rule for classification
classify(Animal, mammal) :-
    has_feature(Animal, mammal).

classify(Animal, quadruped) :-
    has_feature(Animal, four_legs).

classify(Animal, flying_animal) :-
    has_feature(Animal, flies).

You can ask

?- classify(dog, Class).
?- classify(bird, Class).

Darija: هنا عندنا نظام خبير بسيط كيصنّف الحيوانات حسب المميزات ديالهم بحال واش هو mammal ولا كيطرّ فسماء.

6 Example 3 – Simple Course Recommendation Expert System

6.1 Knowledge base

% user preferences
interest(user1, ai).
interest(user1, programming).

course('Intro to AI', ai, beginner).
course('Machine Learning with Python', ai, intermediate).
course('Prolog for AI', ai, intermediate).
course('Python Basics', programming, beginner).
course('Data Structures', programming, intermediate).

% rule to recommend
recommend(Person, Course) :-
    interest(Person, Topic),
    course(Course, Topic, Level),
    Level == beginner.

recommend(Person, Course) :-
    interest(Person, Topic),
    course(Course, Topic, Level),
    Level == intermediate.

Query examples

?- recommend(user1, Course).

Darija: فهاد المثال النظام كيقترح دورات حسب الاهتمامات ديال المستخدم بحال ai ولا programming.

7 Explanation of Key Parts

7.1 Backward chaining in Prolog

Prolog tries to prove a goal by looking for rules where goal appears in the head. Then it tries to satisfy conditions in body step by step. You do not write the inference engine yourself. Prolog handles search and unification.

Darija: منين كتعطي هدف لـ Prolog هو كيقلب على القواعد اللي الرأس ديالها هو نفس الهدف من بعد كيبدا يحقّق الشروط واحد بواحد إنت غير كتركز على الحقائق والقواعد و Prolog كيدير الخدمة ديال الاستنتاج.

7.2 Knowledge base design

You design a good expert system when you:

  • Pick a narrow domain like small medical subproblem or toy diagnostic task
  • List important concepts as predicates
  • Write clear facts with simple arguments
  • Write rules with small bodies and clear logic

Darija: باش تصايب نظام خبير مزيان اختار مجال صغير وواضح حدّد المفاهيم المهمة فشكل predicates ومن بعد كتب الحقائق والقواعد بطريقة بسيطة.

7.3 User interaction part

For real systems you:

  • Ask user questions
  • Store answers as dynamic facts
  • Run inference using those dynamic facts
  • Show results or explanations

Prolog gives assertz and retract for dynamic facts. You saw this in the medical example with has_symptom_user.

Darija: فالنظام الحقيقي كتسول المستخدم كتسجّل الأجوبة فحقائق ديناميكية ومن بعد كتحسب النتائج وكتوري المستخدم التفسير والنتيجة.

8 Step by Step – Build Your Own Expert System in Prolog

Step 1 Choose a domain

Examples:

  • Plant disease hints
  • Computer network troubleshooting
  • Car starting problems
  • Study path advice for AI

Darija: أول خطوة هي تختار مجال مثلا أمراض النباتات أو مشاكل الحاسوب أو اقتراحات الدراسة فمجال الذكاء الاصطناعي.

Step 2 Define predicates

Decide names for:

  • Facts about entities, for example problem/1, symptom/2, has_feature/2
  • Derived knowledge, for example diagnose/2, recommend/2, classify/2

Darija: اختار الأسماء ديال الـ predicates بحال symptom للأعراض ولا recommend للاقتراحات.

Step 3 Write facts

Enter fixed knowledge as facts.

problem(bad_battery).
problem(no_fuel).

symptom_problem(bad_battery, engine_clicks).
symptom_problem(no_fuel, engine_silent).

Step 4 Write rules

diagnose(Problem) :-
    symptom_problem(Problem, Symptom),
    has_symptom_user(Symptom).

Then later you add rules for recommendation or explanations.

Step 5 Add simple question interface

Reuse pattern from previous ask and collect_symptoms predicates. Adapt names for your domain, for example question_feature instead of symptom.

Step 6 Test and extend

Run many queries. Check if answers match expert expectations. Adjust rules and add more facts.

Darija: جرّب النظام مع بزاف ديال الأمثلة شوف واش النتائج قريبة من رأي خبير حقيقي إلا لقيتي خطأ بدّل القواعد وزيد حقائق جديدة.

9 Practice Exercises – Prolog Expert Systems

Use these exercises to strengthen your understanding of expert systems in Prolog. Try to write full Prolog files and test in a Prolog interpreter like SWI Prolog.

  1. Build an expert system for recommending a drink Inputs temperature (hot or cold), time of day, and caffeine preference Output drink like tea, coffee, juice Use facts for properties and rules for recommendation.
  2. Create an animal expert system Ask about features like has_fur, lays_eggs, lives_in_water Infer animal group like mammal, bird, fish.
  3. Extend the medical example Add new disease and symptoms Add rule for high risk case when user has certain combination of symptoms.
  4. Design a laptop selection expert system Facts about laptops and properties like ram_16gb, gpu_midrange Rules that recommend laptops for gaming or for study.
  5. Implement explanation feature When system suggests a disease or recommendation Add predicate explain/1 that prints reasons using rules.
  6. Add certainty levels Store facts symptom_weight(Disease, Symptom, Weight) Compute a score per disease based on user symptoms Print diseases sorted by score or at least print scores.
  7. Build a course advisor for AI learning Inputs background (math, programming) and goals (research, industry) Output learning path or next course suggestion.
  8. Make a simple troubleshooting expert system for Wi Fi Ask user questions about lights, distance, other devices Output advice step to try next.
  9. Add persistence Use file predicates like tell and told or modern equivalents Save user answers or logs to a file then read them back in a new session.
  10. Combine two expert systems First part diagnoses car battery issue Second part recommends next action such as call mechanic or charge battery Connect them with shared facts.
  11. Bonus in Darija صايب نظام خبير صغير كيعطي نصيحة على شنو تقرا فمجال الذكاء الاصطناعي دخّل مستوى المستخدم مبتدئ ولا متوسط واهتمام ديالو vision ولا NLP ولا reinforcement learning وخليه يقترح ليه واحد الكورس ولا كتاب.

Darija: حاول تحل هاد التمارين بوحدك كتب الكود فملف Prolog وجرّبو فـ SWI Prolog ولا أي مفسّر آخر كل مرة شوف النتيجة وعدّل القواعد حتى توصل لنظام خبير معقول.

Darija: من بعد هاد الدرس تقدّر تنتاقل لدروس أخرى بحال Machine Learning Neural Networks ولا Intro to Prolog for AI باش تكمل رحلة التعلم فمجال الذكاء الاصطناعي.

Data Types in Machine Learning

Data Types in Machine Learning

English Version

Machine learning works with specific data types. Each type guides how you clean data, choose models, and build features. Here are the main groups.

1. Numerical Data

Values that represent quantities. You can apply math operations on them.

  • Continuous. Any value in a range. Example height and temperature.
  • Discrete. Whole numbers. Example counts and items.

2. Categorical Data

Values that represent groups. Models need encoding to use them.

  • Nominal. No order. Example colors and cities.
  • Ordinal. Has order. Example ratings.

3. Binary Data

Values with two states. Example yes or no. Many classification models use this format.

4. Text Data

Sentences or documents. You convert text into tokens or vectors before training.

5. Image Data

Pixels stored in arrays. Used in vision tasks. Needs preprocessing and augmentation.

6. Audio Data

Waveforms or spectrograms. Used in speech tasks. Needs feature extraction.

7. Time Series Data

Values ordered by time. Used in forecasting and anomaly detection. Needs sequence handling.

8. Tabular Data

Rows and columns. Common in business and analytics. Supports mixed types.

Why This Matters

Each type needs its own preparation steps. Your model choice depends on the data format and structure.


Moroccan Darija Version

Machine learning kaykhdm b data mkhtlfa. Kol type kay7dd tariqa dyal cleaning, models, w features. Hna l types l m3rfin.

1. Numerical Data

Qiyam nssabiya. T9dr tdir 3lihom operations.

  • Continuous. Qiyam bin range. Bhal temperature.
  • Discrete. A3dad kamla. Bhal counts.

2. Categorical Data

Qiyam dyal groups. Kay7taj encoding bach ykhdm f models.

  • Nominal. Bla tartib. Bhal colors.
  • Ordinal. Fih tartib. Bhal ratings.

3. Binary Data

Qiyam b jouj states. Bhal yes w no.

4. Text Data

Nass w sentences. Khass conversion l tokens ola vectors.

5. Image Data

Pixels f arrays. Msta3mla f vision. Khass preprocessing.

6. Audio Data

Waveforms ola spectrograms. Msta3mla f speech. Khass extraction.

7. Time Series Data

Qiyam mrrtba b time. Msta3mla f forecasting.

8. Tabular Data

Rows w columns. Msta3mla f analytics. Kayjma3 types mkhtlfin.

3lach hadi mohemma

Kol type kay7taj steps mokhtlfin. Model choice kaybdel 3la hsab data format.

Where to Start in Machine Learning?

Where to Start in Machine Learning

English Version

1. Learn the Core Math

Start with linear algebra, probability, and basic calculus. You need these topics to understand models. Keep the focus on vectors, matrices, derivatives, and distributions.

2. Learn Python

Python is the main language for machine learning. Learn variables, loops, functions, and modules. Then learn NumPy and Pandas. These libraries handle data and arrays.

3. Understand Data Handling

Learn how to load data, clean data, and prepare data. Learn missing values, encoding, normalization, and splitting. Clean data improves model results.

4. Start With Supervised Learning

Begin with simple models. Learn linear regression, logistic regression, decision trees, and k nearest neighbors. Build small projects and test them.

5. Learn Model Evaluation

Learn accuracy, precision, recall, F1, RMSE, and confusion matrices. Evaluation helps you understand model performance.

6. Move to Advanced Models

After the basics, study random forests, gradient boosting, SVMs, and neural networks. These models give stronger results for many tasks.

7. Practice With Real Projects

Pick small datasets. Build simple pipelines. Train, test, and evaluate. Improve the workflow step by step.

8. Learn ML Tools

Learn scikit learn first. Then explore TensorFlow and PyTorch. These tools help you build deep learning systems.

9. Read Research and Documentation

Read official docs for libraries. Follow updates and study tutorials. This keeps your skills fresh.

10. Stay Consistent

Set a clear schedule. Build often. Test ideas. Small steps push you forward in ML.


Moroccan Darija Version

1. Bda b Math l Asasiya

Bda b linear algebra, probability, w calculus. Hadi l core bach tfham models. Sir l vectors, matrices, derivatives, w distributions.

2. T3llam Python

Python hiya l language l msta3mla f ML. T3llam basics. B3d t3llam NumPy w Pandas bach t7km f data.

3. Fham Data Handling

T3llam kifash tloadi data, tnqqiha, w tjiheziha. Fham missing values, encoding, normalization, w splitting.

4. Bda b Supervised Learning

Bda b linear regression, logistic regression, decision trees, w k nearest neighbors. Diri small projects.

5. T3llam Evaluation

Fham accuracy, precision, recall, F1, RMSE, w confusion matrix. Hadi katwerik performance.

6. Zid l Models Mtwrin

B3d basics, qra random forests, gradient boosting, SVM, w neural networks.

7. Diri Projects 3lihom Data Bssita

Khddm 3la datasets sgharin. Sna3 pipeline. Train, test, w evaluate.

8. T3llam Tools dyal ML

Bda b scikit learn. B3d sir l TensorFlow w PyTorch.

9. Qra Docs w Tutorials

Tb3a docs dyal libraries. Qra examples w updates.

10. Dwam 3la tta3allom

Dir schedule. Khddm b niyma. Qder t3awd. L consistency katbni skills.

Top 10 Tools for Data Analysis

Top 10 Tools for Data Analysis

English Version

Top 10 Tools for Data Analysis

Data analysis needs clear tools that help you explore data, clean data, and build insights. Here are ten strong options used in industry and education.

  1. Python. Flexible language with strong libraries like Pandas and NumPy. Works for cleaning, processing, and modeling.
  2. Pandas. Python library for tables and data manipulation. Supports filtering, grouping, and transformation.
  3. NumPy. Core library for numerical operations in Python. Works with arrays and scientific tasks.
  4. R. Strong language for statistics and data visualization. Popular in academia and research.
  5. SQL. Core skill for working with databases. Helps you query, filter, and join data.
  6. Excel. Common tool for fast analysis. Supports formulas, pivot tables, and charts.
  7. Tableau. Visualization tool for dashboards and reports. Helps you present insights.
  8. Power BI. Microsoft tool for interactive dashboards. Connects to many data sources.
  9. Apache Spark. Distributed system for large datasets. Helps with big data processing.
  10. Jupyter Notebook. Environment for code, text, and experiments. Supports Python and other languages.

How to Pick the Right Tool

Pick a tool based on dataset size, analysis goals, and workflow needs. Use Python or R for full control. Use Excel for quick tasks. Use Tableau or Power BI for dashboards.


Moroccan Darija Version

Top 10 Tools dyal Data Analysis

Data analysis kayhtaj tools wadhin bach t9ra data, tnqqa data, w tjib insights. Hna ashno l tools li katsst3mlhum ktar.

  1. Python. Language fleksibl. Kay3awnk b Pandas w NumPy l processing w modeling.
  2. Pandas. Library dyal Python bach t3ml m3a tables. Kay3awnk f filtering w grouping.
  3. NumPy. Library dyal operations nssabiya. Kaykhddm m3a arrays.
  4. R. Language qwiya f statistics w visualization.
  5. SQL. Tool l databases. Kay3awn f queries w joins.
  6. Excel. Tool m3ruf bach tdir analysis s3iba b sor3a. Fih formulas w pivot tables.
  7. Tableau. Tool dyal dashboards w charts.
  8. Power BI. Tool dyal Microsoft bach tdir dashboards mokhtalfin.
  9. Apache Spark. System l big data. Kay3awn f processing kbir.
  10. Jupyter Notebook. Environment bach tktb code w tdir tests.

Kif tkhatar l tool

Khatar 3la hsab size dyal data, hadf dyal analysis, w workflow. Python w R mzyanin l control. Excel mzyan l tasks s3iba w sghira. Tableau w Power BI mzyanin l dashboards.

Top 10 Tools for Web Scraping

Top 10 Tools for Web Scraping

English Version

Top 10 Tools for Web Scraping

Web scraping helps you collect data from websites in a structured way. These tools support automation, parsing, and data extraction. Here are ten strong options.

  1. BeautifulSoup. Python library that parses HTML and XML. Simple and fast for small projects.
  2. Scrapy. Python framework built for large scraping workflows. Offers spiders, pipelines, and strong control.
  3. Selenium. Automates browsers. Helps scrape dynamic pages that use JavaScript.
  4. Playwright. Modern browser automation tool. Stable, fast, and supports multiple languages.
  5. Puppeteer. Headless Chrome automation for Node.js. Strong for dynamic site scraping.
  6. Requests. Python library for HTTP calls. Works well with BeautifulSoup for simple tasks.
  7. Apify. Cloud platform for scraping and automation. Offers ready templates and scalable runs.
  8. Octoparse. No code scraping tool. Good for beginners who want fast setup.
  9. ParseHub. Visual scraper for dynamic content. Exports data in clean formats.
  10. Diffbot. AI powered extraction API. Converts pages into structured data without manual selectors.

How to Pick the Right Tool

Pick a tool based on project size, site complexity, and coding comfort. Use browser automation for dynamic pages. Use lightweight parsers for static pages. Use cloud tools for large workloads.


Moroccan Darija Version

Top 10 Tools l Web Scraping

Web scraping kay3awnk tjma3 data men sites b tariqa mrtaba. Hna ashno l tools li kaynaw w kif y3awnouk.

  1. BeautifulSoup. Library dyal Python li kat parse HTML. Sahl w mzyan l projects sgharin.
  2. Scrapy. Framework dyal Python. Kay3awn f projects kbar w workflows.
  3. Selenium. Kayhark browser w kay scrape pages li fihom JavaScript.
  4. Playwright. Tool jdid w stable. Kaykhddm b Python, Node, w languages okhrin.
  5. Puppeteer. Automation dyal Chrome l Node.js. Kaykhddm mzyan m3a dynamic sites.
  6. Requests. Library dyal Python l HTTP calls. Kaytkamal m3a BeautifulSoup.
  7. Apify. Platform cloud bach tdir scraping w automation. Kayn fih templates w scalability.
  8. Octoparse. Tool bla code. Mzyan l beginners.
  9. ParseHub. Visual scraper li kaykhddm m3a content dynamic.
  10. Diffbot. API b AI. Kayhwel pages l data mrtaba bla selectors.

Kif tkhatar l tool ssi7

Khatar l tool 3la hsab size dyal project, complexity dyal site, w comfort dyal code. Ila site dynamic st3ml browser automation. Ila static st3ml tools khfafin. Ila project kbir st3ml cloud tools.

Difference Between Pretraining and Fine Tuning in LLMs

Difference Between Pretraining and Fine Tuning in LLMs

English Version

What Is Pretraining

Pretraining builds the core knowledge of a large language model. The model learns from large text datasets. It learns grammar, facts, reasoning patterns, and general language skills. It learns next word prediction during this phase. Pretraining shapes the base model behavior.

What Is Fine Tuning

Fine tuning adjusts the pretrained model for a specific task. It uses a smaller dataset. It shapes the model toward targeted outputs like support answers, coding help, or medical text analysis. Fine tuning changes the model goals to match the task.

Main Differences

  • Goal: Pretraining builds general language ability. Fine tuning adapts this ability to a task.
  • Data size: Pretraining uses huge datasets. Fine tuning uses focused datasets.
  • Cost: Pretraining is heavy and expensive. Fine tuning is lighter.
  • Output behavior: Pretrained models respond in a generic way. Fine tuned models behave in a controlled way.
  • Training signals: Pretraining uses next token prediction. Fine tuning uses labeled data or preference data.

Why This Matters

Understanding both steps helps you design better AI systems. You know when to use a base model. You know when to fine tune for accuracy, control, or reliability.


Moroccan Darija Version

Ash kayn f Pretraining

Pretraining kaybni l asasi dyal l model. L model kayt3llam men dbara dyal nass kbira. Kayt3llam l grammar, l info, w l patterns dyal reasoning. Kayt3llam kifash ykml l kalma jaya. Pretraining kaydir l base dyal l model.

Ash kayn f Fine Tuning

Fine tuning kaywajja l model l chi task mo3ayan. Kayst3ml data sghira w mkhasssa. Kaykhelli l model yjib jawabat mkhasssin b7al support, code, ola tahlil dyal nass tibi. Fine tuning kaybdl hadaf l model bach yntawej l task.

Farqu binathom

  • Goal: Pretraining kaydir l skills l 3amma. Fine tuning kaywajja had skills l task.
  • Data: Pretraining kayst3ml data kbira. Fine tuning kayst3ml data mkhasssa.
  • Cost: Pretraining ghali. Fine tuning ahwan.
  • Behavior: Model pretrained kayjib jawab 3amm. Model fine tuned kayjib jawab mkhassas.
  • Training: Pretraining kayst3ml next token prediction. Fine tuning kayst3ml data labeled ola preference.

3lach hadi mohemma

Ila fhamti pretraining w fine tuning ghat3rf kifash tsawb systems zwinin f AI. Ghatsst3ml base model f wa9t mo3ayan. W ghatt fine tune ila bghiti accuracy w control kbar.

Feature Engineering for AI Beginners

Feature Engineering for AI Beginners

What Is Feature Engineering

Feature engineering is the process of creating inputs that help a model learn patterns. Raw data often needs transformation. Strong features improve accuracy and stability.

Why feature engineering is important

  • It improves model performance.
  • It reduces noise in the dataset.
  • It highlights useful patterns.
  • It prepares data for algorithms that expect structured inputs.

Main feature engineering actions

  • Create new columns from existing ones.
  • Encode text or categorical data.
  • Scale numerical values.
  • Normalize distributions.
  • Extract time features like hour or weekday.
  • Group rare categories.

Simple Python example

import pandas as pd

df = pd.read_csv("data.csv")

# Create a new feature
df["bmi"] = df["weight"] / (df["height"] ** 2)

# Encode category
df = pd.get_dummies(df, columns=["city"])

# Scale a value
df["age_scaled"] = (df["age"] - df["age"].mean()) / df["age"].std()

Tips for strong features

  • Use simple transformations.
  • Check correlation between new features and the target.
  • Remove features that bring no value.
  • Keep track of each transformation.
  • Test features with a baseline model.

Conclusion

Feature engineering creates clear inputs for machine learning tasks. It supports AI students and practitioners in reaching stable results. It forms a core skill in every project.


Feature Engineering b Darija

Feature engineering huwa lprocess li katsayeb inputs jdadin bach lmodel ytfham data mzyan. Data raw kats7taj tbdil. Features mqaddmin kayrfa3o performance dyal model.

Ash bhal faida dyalo

  • Kayhssen accuracy.
  • Kayn9i noise.
  • Kaybayyen patterns mhemmin.
  • Kayywajjid data l algorithms.

Steps m3roufin f feature engineering

  • Tsayeb columns jdadin.
  • Encode text w categories.
  • Scale values numeriques.
  • Normalize distributions.
  • Tsayeb time features bhal hour w weekday.
  • Tjam3 categories nqallin.

Exemple b Python

import pandas as pd

df = pd.read_csv("data.csv")

df["bmi"] = df["weight"] / (df["height"] ** 2)

df = pd.get_dummies(df, columns=["city"])

df["age_scaled"] = (df["age"] - df["age"].mean()) / df["age"].std()

Tips

  • Khdem b steps s7la.
  • Chouf correlation m3a target.
  • Hayed features li mafihom faida.
  • Sjjel kull bdl.
  • Testi features b model basique.

Khitam

Feature engineering kaywajjid inputs wadiin. Kay3awn talaba w practitioners f AI. Kayb9a skill mhemma f kol project.