Affichage des articles dont le libellé est Data analysis. Afficher tous les articles
Affichage des articles dont le libellé est Data analysis. Afficher tous les articles

Introduction to Matplotlib

Introduction to Matplotlib

Introduction to Matplotlib

Matplotlib is a Python library for plots. Developers use it to create charts for data analysis, machine learning, and scientific work. It gives full control over lines, labels, titles, and axes. It fits small and large projects.

Why use Matplotlib

  • It supports line charts, bar charts, scatter plots, histograms, and more.
  • It integrates with NumPy and pandas.
  • It works in Jupyter notebooks and Python scripts.
  • It offers stable output for research and industry tasks.

Basic installation

pip install matplotlib

Create your first plot

This example shows a simple line plot.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [2, 4, 6, 8]

plt.plot(x, y)
plt.title("Simple Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.show()

This code creates a window with a chart. It links each x point with each y point. You can adjust labels and style as needed.

Common plot types

  • Line plots for trends.
  • Scatter plots for relations between two variables.
  • Bar charts for comparisons.
  • Histograms for distribution checks.

Tips for clean plots

  • Use short titles.
  • Label axes with clear words.
  • Keep grid lines simple.
  • Focus on readable font sizes.

Conclusion

Matplotlib helps build clear charts with few lines of code. It supports data analysis tasks for students and professionals. It works well in AI projects because it gives quick feedback on data patterns.


Introduction dialecte darija

Matplotlib hiya library f Python li katmken men rasm charts. Tkhdem mzyan f data analysis, machine learning, w t9dir tsayeb biha charts b kontrol kammel. Katshel f notebooks w scripts.

Ash nstafdo men Matplotlib

  • Katsupport line charts, bar charts, scatter plots, w histograms.
  • Katkhddem mzyan m3a NumPy w pandas.
  • Katrun b sor3a f Jupyter.
  • Katsayeb charts stables l research w l projects.

Tansib

pip install matplotlib

Awwel plot

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [2, 4, 6, 8]

plt.plot(x, y)
plt.title("Simple Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.show()

Had code kayrsam line plot basit. Katban window fiha chart. Kitrbat points dyal x m3a y. T9dar tbdel labels w style.

Ash men types

  • Line plot bach nshawfo trends.
  • Scatter plot bach nshawfo l relation bin variableat.
  • Bar chart bach nqarnu values.
  • Histogram bach nfhmou distribution.

Tips bach yban chart n9i

  • Khdem b title s7el.
  • Smi l axes b klam wadi.
  • Khelli grid s7el.
  • Khdem b font size maqbul.

Khitam

Matplotlib kay3awn bzaaf f rasm charts b sr3a. Kayfit l talaba, beginners, w professionals f AI w data. Kayb9a tool mohim f kol project kaytsana visualization.

Pandas Essentials for AI and Data Beginners

Pandas Essentials for AI and Data Beginners

Pandas Essentials for AI and Data Beginners

Pandas is the main library for data handling in Python. It gives you tools to load, clean, explore, and prepare datasets. AI and machine learning depend on clean data, and Pandas makes this process simple.

1. Importing Pandas

import pandas as pd

This is the standard import name. Always use pd.

2. Creating a DataFrame

data = {
    "name": ["Sara", "Ali", "Yassine"],
    "score": [85, 92, 78],
    "age": [21, 23, 22]
}

df = pd.DataFrame(data)
print(df)

A DataFrame is like an excel sheet. Rows and columns.

3. Loading Data From Files

  • CSV.
  • Excel.
  • JSON.
df = pd.read_csv("data.csv")
df = pd.read_excel("file.xlsx")
df = pd.read_json("info.json")

4. Inspecting Data

print(df.head())      
print(df.tail())      
print(df.info())      
print(df.describe())  
  • head. first rows.
  • info. types and null values.
  • describe. stats for numeric columns.

5. Selecting Columns

print(df["name"])
print(df[["name", "score"]])

Always use brackets for lists of columns.

6. Selecting Rows

Use iloc for index based selection. Use loc for label based selection.

print(df.iloc[0])        
print(df.iloc[0:2])      
print(df.loc[0])         

7. Filtering Rows With Conditions

high_scores = df[df["score"] > 80]
print(high_scores)

Filter two conditions.

f = df[(df["score"] > 80) & (df["age"] < 23)]
print(f)

8. Adding and Updating Columns

df["passed"] = df["score"] >= 80
print(df)

You can also update values.

df["score"] = df["score"] + 5

9. Handling Missing Data

Check missing values.

print(df.isnull().sum())

Fill missing values.

df["age"] = df["age"].fillna(df["age"].mean())

Drop rows with missing values.

df = df.dropna()

10. Sorting Data

df_sorted = df.sort_values("score", ascending=False)
print(df_sorted)

11. Grouping Data

Grouping helps with summarization.

grouped = df.groupby("age")["score"].mean()
print(grouped)

You can use many functions.

df.groupby("age").agg({"score": ["mean", "max"]})

12. Merging DataFrames

Pandas supports joins like SQL.

merged = pd.merge(df1, df2, on="id", how="inner")
  • inner.
  • left.
  • right.
  • outer.

13. Removing Columns or Rows

df = df.drop("age", axis=1)  
df = df.drop(0)              

14. Converting Data Types

df["age"] = df["age"].astype(int)

Always check types before model training.

15. Exporting Data

df.to_csv("output.csv", index=False)
df.to_excel("output.xlsx", index=False)

16. Mini Projects With Pandas

Project 1. Sales Analysis

  • Load sales CSV.
  • Group by product.
  • Compute revenue.
  • Sort by top sellers.

Project 2. Student Grades Report

  • Load student data.
  • Fill missing grades.
  • Create pass or fail column.
  • Export results.

Project 3. Data Cleaning Script

  • Load messy dataset.
  • Drop duplicates.
  • Fix types.
  • Handle missing values.

Pandas in Moroccan Darija

Pandas kay3awnk t3alj data b tariqa sahl. Kat load data. Katcleani. Katsort. Katgroupi. W kat7ddarha l machine learning.

  • df.head() bach tchouf data.
  • df["col"] bach tjib column.
  • Filtering bach tselecti rows.
  • groupby bach tdir stats.
  • merge bach tjma3 datasets.

Ila t9der tkhddem b Pandas mzyan, t9der tbni projects dial AI bla t3qid.

Conclusion

Pandas offers strong tools for data loading, cleaning, filtering, and grouping. These essentials prepare your datasets for machine learning and deep learning. Learn them well to build strong AI workflows.

NumPy Essentials Tips with Python

NumPy Essentials Tips With Python

NumPy Essentials Tips With Python

NumPy is the main library for numeric work in Python. AI, data science, and machine learning depend on it. This guide shows essential tips to help you use NumPy with a clean and fast workflow.

1. Creating Arrays

Use np.array() to create arrays.

import numpy as np

a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
  • Use lists for simple arrays.
  • Use nested lists for matrices.

2. Check Shape and Size

Shape tells the structure. Size tells the number of elements.

print(b.shape)   # (2, 2)
print(b.size)    # 4

Always check shape before model training or matrix operations.

3. Useful Array Creation Functions

  • np.zeros(). array of zeros
  • np.ones(). array of ones
  • np.arange(). range of numbers
  • np.linspace(). evenly spaced numbers
  • np.eye(). identity matrix
z = np.zeros((3, 3))
r = np.arange(0, 10, 2)

4. Indexing and Slicing

Indexing helps you access elements. Slicing helps you extract parts of arrays.

x = np.array([10, 20, 30, 40, 50])

print(x[0])       
print(x[1:4])     
print(x[:3])      
print(x[::2])     

Indexing in 2D

m = np.array([[5, 6], [7, 8], [9, 10]])

print(m[0, 1])    
print(m[:, 0])    
print(m[1:, :])   

5. Vectorized Operations

NumPy operations apply to all elements. No need for manual loops.

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

print(a + b)
print(a * b)
print(a ** 2)

Vectorization improves speed and simplifies code.

6. Matrix Operations

Matrix work is common in AI.

A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])

print(A.dot(B))
print(np.matmul(A, B))
  • dot and matmul perform matrix multiplication.

7. Broadcasting

Broadcasting lets NumPy combine arrays with different shapes when possible.

a = np.array([1, 2, 3])
b = 2

print(a * b)      

This reduces code and increases speed.

8. Boolean Masking

Masking filters arrays using conditions.

x = np.array([3, 8, 1, 9, 4])

mask = x > 5
print(x[mask])    

Useful for cleaning data or selecting features.

9. Aggregation Functions

NumPy offers fast summary tools.

arr = np.array([2, 4, 6, 8])

print(arr.sum())
print(arr.mean())
print(arr.min())
print(arr.max())
print(arr.std())

10. Reshape Arrays

Reshape changes array form without changing values.

v = np.array([1, 2, 3, 4, 5, 6])
m = v.reshape(2, 3)

Reshape is important for neural networks, CNNs, and model inputs.

11. Stacking and Concatenation

Stack arrays vertically or horizontally.

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

print(np.vstack([a, b]))
print(np.hstack([a, b]))

12. Random Module

NumPy includes tools for random generation.

np.random.seed(0)
print(np.random.rand(3))
print(np.random.randint(0, 10, size=5))

Useful for model testing and reproducibility.

13. Performance Tips

  • Replace loops with vectorized operations.
  • Use astype() to control data types.
  • Use copy() when needed to avoid shared memory issues.
  • Always confirm shapes before matrix ops.

14. Mini Projects With NumPy

Project 1. Normalize a Dataset

  • Load numeric array.
  • Subtract mean.
  • Divide by standard deviation.

Project 2. Implement Simple Distance Function

  • Create two arrays.
  • Compute Euclidean distance using vector operations.

Project 3. Build a Small Matrix Calculator

  • Take two arrays.
  • Perform multiply, add, subtract, and transpose.

NumPy Essentials in Moroccan Darija

NumPy kay3awnk tkhddem b arrays b speed kbir. F AI daba, NumPy howa base. Had tips kay3awnouk tebni code n9i w rapide.

  • np.array() bach tsawb arrays.
  • .shape bach tchouf structure.
  • Indexing bach taccessi values.
  • Vectorization bach tkhadam bla loops.
  • Matrix ops bach tdir multiplication.
  • Masking bach tfiltri data.
  • Reshape bach tbadal form.

Ila fhamti had essentials, t9der tebni models w data pipelines bla t3qid.

Conclusion

NumPy offers fast numeric work for AI and data tasks. Learn arrays, shapes, indexing, vectorization, and matrix operations. These tips build strong skills for machine learning, neural networks, and data science projects.

Learning Paradigms in Data and Machine Learning

Learning Paradigms in Data and Machine Learning

Learning Paradigms in Data

Learning paradigms describe how models learn from data. Each paradigm uses a different setup. The goal is to choose the right method based on the problem and the type of data you have.

1. Supervised Learning

Supervised learning uses labeled data. Each input has an output. The model learns the link between them.

Examples

  • Spam detection
  • Image classification
  • Price prediction

2. Unsupervised Learning

Unsupervised learning uses data without labels. The model finds patterns or structure.

Examples

  • Clustering
  • Dimensionality reduction
  • Anomaly detection

3. Semi Supervised Learning

Semi supervised learning uses a mix of labeled and unlabeled data. The model uses labeled data to guide its learning.

Examples

  • Text classification with small labeled sets
  • Image labeling with limited annotation

4. Self Supervised Learning

Self supervised learning builds labels from the data itself. The model learns from internal signals inside the dataset.

Examples

  • Masked word prediction
  • Image patch prediction

5. Reinforcement Learning

Reinforcement learning uses interaction. An agent takes actions, gets rewards, and improves its policy.

Examples

  • Robotics
  • Game playing
  • Navigation systems

6. Transfer Learning

Transfer learning takes a model trained on one task and adapts it to another task.

Examples

  • Using a pretrained CNN for new image datasets
  • Using a pretrained transformer for text tasks

7. Online Learning

Online learning updates the model step by step as new data flows in. It handles streaming data.

Examples

  • Real time recommendations
  • Live anomaly detection

Learning Paradigms in Moroccan Darija

Learning paradigms hiyya tariq dial t3llam models mn data. Kul paradigm kayst3mel style mokhtalef.

Supervised

Data m3a labels. Model kayt3llam link.

Unsupervised

Data bla labels. Model kayjber patterns.

Semi Supervised

Mxoj dial labeled w unlabeled.

Self Supervised

Model kayt3llam mn data b labels mkhlouqin mn data.

Reinforcement

Agent kaydir actions w kayakhod reward.

Transfer

Training m task o usage f task okhra.

Online

Model kayupdate m3a data jdid.

Conclusion

Learning paradigms offer different ways to train models. Each paradigm serves a specific type of data and task. Understanding them helps you choose the right method for your project.

Data Imbalance in Machine Learning

Data Imbalance in Machine Learning

Data Imbalance

Data imbalance happens when one class in a dataset has far more samples than another. The model learns more from the dominant class. This creates weak predictions for the minority class.

Why Data Imbalance Is a Problem

  • The model focuses on the majority class.
  • The model ignores rare cases.
  • Accuracy becomes misleading.
  • Predictions lose fairness.

Common Examples

  • Fraud detection. Fraud cases are few.
  • Medical diagnosis. Rare diseases appear with low frequency.
  • Spam detection. Spam or ham counts differ.

Effects of Data Imbalance

  • High accuracy with poor real performance
  • Biased model outputs
  • Weak recall on minority class

Ways to Handle Data Imbalance

1. Undersampling

Reduce samples in the majority class.

2. Oversampling

Increase samples in the minority class by duplication.

3. SMOTE

Create synthetic samples for the minority class.

4. Class Weighting

Give higher weight to minority samples during training.

Evaluation Tips

  • Use precision and recall.
  • Use F1 score.
  • Use confusion matrix.

Data Imbalance in Moroccan Darija

Data imbalance kaykoun mlli class wahed kayn b quantidade kbira w class okhor kayn b quantidade sghira. Model kayt3llam aktar men class l kbir w kaytghafel class sghir.

L Moshkil

  • Model kayfocus 3la majority.
  • Minority kaywalou weak.
  • Accuracy katban mzyana bsah reality la.

L Hal

  • Undersampling.
  • Oversampling.
  • SMOTE.
  • Class weighting.

Conclusion

Data imbalance creates biased models. Fixing it improves fairness and prediction quality.

Data Sampling in Machine Learning

Data Sampling in Machine Learning

Data Sampling

Data sampling is the process of selecting a smaller part of a dataset. The goal is to analyze or train models without using the full data. The sample must represent the main dataset.

Why Data Sampling Is Important

  • Reduces compute time
  • Speeds up testing and experiments
  • Handles large datasets
  • Improves workflow when data is hard to process

Types of Data Sampling

1. Random Sampling

Select items at random. Each item has an equal chance of being chosen.

2. Stratified Sampling

Split data into groups called strata. Take samples from each group. This keeps proportions stable.

3. Systematic Sampling

Select every k th item from a list.

4. Cluster Sampling

Split data into clusters. Pick some clusters and analyze all items in them.

Sampling in Machine Learning

  • Used to balance datasets
  • Used to handle imbalanced classes
  • Used to reduce dataset size
  • Used to speed training

Balancing Methods

Undersampling

Remove samples from the majority class.

Oversampling

Add or duplicate samples from the minority class.

SMOTE

Create synthetic samples for the minority class.

Challenges

  • Bad samples cause bias
  • Small samples reduce accuracy
  • Stratification may be required for fairness

Data Sampling in Moroccan Darija

Data sampling howa ikhraj chi parte sghira men dataset kbir. Kankhdmo biha bach ntestiw models w nser3o l process.

Types

  • Random. Ikhtiyar random.
  • Stratified. Kankhsmo data l groups w kandiro sample men kol group.
  • Systematic. Kandiro selection kola k step.
  • Cluster. Kandiro clusters w kankhtaro chi clusters kamlin.

F ML

  • Balancing.
  • Reduction.
  • Speed training.

Conclusion

Data sampling helps you work with large datasets. It reduces cost, speeds testing, and supports balanced machine learning tasks.

Data Analyst Roadmap

Data Analyst Roadmap

Introduction

This roadmap explains the steps to learn data analysis from the ground up. The goal is simple progress through spreadsheet skills, SQL, Python, visualization, and real projects. Next, you build confidence with consistent practice.

هاد ال roadmap كتعطيك طريقة سهلة باش تولي data analyst. غادي تبدا ب Excel ثم SQL ثم Python و visualization.

1. Learn Spreadsheet Skills

Excel or Google Sheets form the starting point for most analysis tasks. Learn basic operations and cleaning steps.

Core Skills

  • Sorting and filtering
  • Pivot tables
  • Conditional formatting
  • Basic formulas
  • Data cleaning

تعلم Excel. sorting و filtering و pivot tables ضروريين.

2. Learn Basic Statistics

Statistics supports clear decision making. Focus on simple ideas first.

Main Topics

  • Mean and median
  • Variance and standard deviation
  • Correlation
  • Sampling
  • Distribution basics

تعلم mean و variance و correlation باش تفهم data مزيان.

3. Learn SQL

SQL helps you extract, filter, and join data. You will use it in most analysis tasks.

Focus Points

  • Select queries
  • Filtering and ordering
  • Joins
  • Aggregation
  • Subqueries

SQL مهم بزاف. تعلم SELECT و JOIN و GROUP BY.

4. Learn Python for Analysis

Python improves automation and speed. Use it to clean data, merge tables, and create visuals.

Important Libraries

Tasks to Practice

  • Loading datasets
  • Handling missing values
  • Merging datasets
  • Grouping and aggregating
  • Simple plots

تعلم Pandas و Matplotlib باش تخدم على data بسرعة.

5. Learn Data Visualization

Data visuals support insight communication. Build clean charts and dashboards.

Tools

  • Power BI
  • Tableau
  • Looker Studio

Visuals to Build

  • Bar charts
  • Line charts
  • Pie charts
  • Heatmaps
  • Dashboards

Power BI و Tableau مهمين باش دير dashboards واضحة.

6. Learn Business Understanding

Data analysts explain insights for business decisions. Learn how to analyze goals and write simple reports.

Key Skills

  • Understanding KPIs
  • Asking clear questions
  • Explaining results
  • Building reports

فهم KPIs و كيفاش تقدم insights بطريقة واضحة.

7. Build Real Projects

Projects build experience. Work with public datasets and document results.

Project Ideas

  • Sales analysis
  • Marketing performance
  • Customer behavior
  • Product performance
  • Finance dashboards

دير مشاريع بحال sales analysis ولا dashboards ديال finance.

8. Build Your Portfolio

Collect your strongest work. Publish dashboards and reports. Share insights on GitHub or LinkedIn.

دير portfolio فيه مشاريع واضحة وشارك links ديال dashboards.

Syntax or Workflow Example

Below is a simple Python example for loading a dataset and creating a quick summary.

import pandas as pd

df = pd.read_csv("data.csv")
print(df.head())
print(df.describe())

هادا مثال باش تشوف البيانات وتستخرج معلومات أولية.

Exercises

  • Create a pivot table in Excel with sales by region.
  • Write a SQL query that joins two tables.
  • Calculate correlation between two variables.
  • Create a bar chart for product performance.
  • Load a CSV file with Pandas.
  • Clean missing values from a dataset.
  • Group data by category and compute averages.
  • Build a dashboard in Power BI.
  • Create a scatter plot using Matplotlib.
  • Write a short report explaining insights from one dataset.

Conclusion

Follow the steps and practice each skill. Data analysis grows with repetition and real reports.

تبع الخطوات و خدم بزاف على data باش تولي data analyst قوي.