0Pricing
NLP Academy · درس

التدريب على سمات TF-IDF

درّب مصنّفًا باستخدام scikit-learn

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

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

From Text to Numbers First

A model cannot read raw sentences. You first convert documents into TF-IDF vectors, then train logistic regression on those numbers. 🔢

Fit the Vectorizer

The TfidfVectorizer learns your vocabulary and weighting from the training texts. One call turns a list of strings into a feature matrix.

from sklearn.feature_extraction.text import TfidfVectorizer
vec = TfidfVectorizer()
X = vec.fit_transform(train_texts)

Labels Stay Separate

Your features X come from the text, but your labels y come from you. Each document needs its correct class, like spam or not-spam.

Split Before You Train

Hold out a test set so you can judge fairly. train_test_split keeps some data unseen until the very end of evaluation.

from sklearn.model_selection import train_test_split
X_tr, X_te, y_tr, y_te = train_test_split(X, y)

Fit Means Learn

Calling fit tells logistic regression to find the word weights that best separate your classes on the training data.

from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(max_iter=1000)
clf.fit(X_tr, y_tr)

Raise max_iter If It Warns

Text has many features, so the solver may need more steps. Bumping max_iter clears the common convergence warning you will see.

Predict on New Vectors

To classify fresh text, transform it with the same fitted vectorizer, then call predict. Never refit the vectorizer on test data.

preds = clf.predict(X_te)

Transform, Do Not Fit, on Test

Test text uses transform, not fit_transform. Refitting would leak test information and quietly inflate your scores.

Check the Accuracy

A quick score call gives accuracy on the held-out set. It is your first signal that training actually worked.

print(clf.score(X_te, y_te))

Same Steps Stay in Sync

Train and prediction must share the exact same vocabulary. Using one fitted vectorizer everywhere keeps feature columns aligned.

A Pipeline Saves You

Wrapping the vectorizer and model in a Pipeline chains transform and predict automatically, so you never forget a step.

from sklearn.pipeline import make_pipeline
pipe = make_pipeline(TfidfVectorizer(), LogisticRegression())

Quick Check

How should you prepare test text before predicting?

Recap: Vectorize Then Fit

Vectorize text with TF-IDF, split, then fit logistic regression. Reuse the same vectorizer for test data, ideally inside a pipeline. ✅

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

هل درس «التدريب على سمات TF-IDF» مجاني؟

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

ماذا ستتعلم في «التدريب على سمات TF-IDF»؟

درّب مصنّفًا باستخدام scikit-learn تتمرن على NLP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

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

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

كم من الوقت يستغرق درس «التدريب على سمات TF-IDF»؟

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

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

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

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

  1. لماذا ينجح Logistic Regression مع النصوص
  2. التدريب على سمات TF-IDF
  3. فحص أقوى المعاملات
  4. ضبط قوة التنظيم
← العودة إلى NLP Academy