0Pricing
MLOps Academy · درس

التسلسل باستخدام Pickle وJoblib

احفظ نماذج sklearn وحمّلها بالطريقة الآمنة.

التسلسل باستخدام Pickle وJoblib درس مجاني في MLOps Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MLOps Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MLOps Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why Serialize a Model?

A trained model lives in memory and vanishes when your script ends. Serialization saves it to a file so you can load it again later. 💾

Meet Pickle

Python's built-in pickle module turns almost any object into bytes you can store on disk and rebuild later, exactly as it was.

Dump a Model to Disk

You open a file in binary write mode and call pickle.dump to write the trained model into it.

import pickle
with open('model.pkl', 'wb') as f:
    pickle.dump(model, f)

Load It Back

To restore the model, open the file in binary read mode and call pickle.load. You get the same object back, ready to predict.

with open('model.pkl', 'rb') as f:
    model = pickle.load(f)

Why Joblib Exists

Scikit-learn ships big NumPy arrays inside models. joblib stores those arrays far more efficiently than plain pickle does. 🚀

Save with Joblib

joblib gives you a clean one-liner: joblib.dump takes the object and a filename, no manual file handle needed.

import joblib
joblib.dump(model, 'model.joblib')

Load with Joblib

Loading mirrors saving. Call joblib.load with the same filename and you get your trained estimator back.

model = joblib.load('model.joblib')
model.predict(X_test)

Pickle's Big Warning

Never unpickle a file from an untrusted source. A malicious pickle can run arbitrary code the moment you load it. ⚠️

Versions Must Match

A pickle is tied to library versions. Loading a model under a different scikit-learn version can break or silently misbehave.

Pin What You Saved

Always record the exact library versions next to the file. Pinning your requirements means the saved model loads the same way tomorrow.

import sklearn
print(sklearn.__version__)

Pickle or Joblib?

For scikit-learn models reach for joblib; for small, array-free Python objects, plain pickle is perfectly fine.

Quick Check

Time to test what you learned about serializing models.

Recap

You can now save and reload models with pickle and joblib, prefer joblib for sklearn, never load untrusted files, and pin versions. 🎉

الأسئلة الشائعة

هل درس «التسلسل باستخدام Pickle وJoblib» مجاني؟

نعم — نص درس «التسلسل باستخدام Pickle وJoblib» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MLOps Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MLOps Academy 4 دروس في المجموع.

ماذا ستتعلم في «التسلسل باستخدام Pickle وJoblib»؟

احفظ نماذج sklearn وحمّلها بالطريقة الآمنة. تتمرن على MLOps Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MLOps Academy؟

لا تُشترط خبرة سابقة. MLOps Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «التسلسل باستخدام Pickle وJoblib»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MLOps Academy هذا؟

نعم. كل درس في MLOps Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. التسلسل باستخدام Pickle وJoblib
  2. صيغة نموذج MLflow
  3. التصدير إلى ONNX لإتاحة النقل
  4. تحديد توقيع النموذج ومخططه
← العودة إلى MLOps Academy