{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "478d9ad3-eb52-4622-bea7-ac89984fae21", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "887779ca-c01e-48c5-b165-75d6544dcd26", "metadata": {}, "outputs": [], "source": [ "df=pd.read_csv(\"CompanyReviews.csv\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "ad94225b-f7da-4f14-ae6d-071c10e2e1b2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0review_descriptionratingcompany
00رائع1talbat
11برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...1talbat
22التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...-1talbat
33لماذا لا يمكننا طلب من ماكدونالدز؟-1talbat
44البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...-1talbat
...............
40041128تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب...0swvl
40042129انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال...-1swvl
40043130جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه...0swvl
40044131جيدا جدا ...ولكن الاسعار عاليه جدا\\n0swvl
40045132التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا...0swvl
\n", "

40046 rows × 4 columns

\n", "
" ], "text/plain": [ " Unnamed: 0 review_description rating \\\n", "0 0 رائع 1 \n", "1 1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... 1 \n", "2 2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... -1 \n", "3 3 لماذا لا يمكننا طلب من ماكدونالدز؟ -1 \n", "4 4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... -1 \n", "... ... ... ... \n", "40041 128 تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب... 0 \n", "40042 129 انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال... -1 \n", "40043 130 جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه... 0 \n", "40044 131 جيدا جدا ...ولكن الاسعار عاليه جدا\\n 0 \n", "40045 132 التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا... 0 \n", "\n", " company \n", "0 talbat \n", "1 talbat \n", "2 talbat \n", "3 talbat \n", "4 talbat \n", "... ... \n", "40041 swvl \n", "40042 swvl \n", "40043 swvl \n", "40044 swvl \n", "40045 swvl \n", "\n", "[40046 rows x 4 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 4, "id": "9e667bc0-7cbb-4d84-a268-988dcb73e833", "metadata": {}, "outputs": [], "source": [ "df = df[[\"review_description\", \"rating\"]].copy()" ] }, { "cell_type": "code", "execution_count": 5, "id": "c991e6ed-6102-4827-89f7-912dd97906d1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائع1
1برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...1
2التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...-1
3لماذا لا يمكننا طلب من ماكدونالدز؟-1
4البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...-1
.........
40041تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب...0
40042انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال...-1
40043جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه...0
40044جيدا جدا ...ولكن الاسعار عاليه جدا\\n0
40045التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا...0
\n", "

40046 rows × 2 columns

\n", "
" ], "text/plain": [ " review_description rating\n", "0 رائع 1\n", "1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... 1\n", "2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... -1\n", "3 لماذا لا يمكننا طلب من ماكدونالدز؟ -1\n", "4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... -1\n", "... ... ...\n", "40041 تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب... 0\n", "40042 انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال... -1\n", "40043 جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه... 0\n", "40044 جيدا جدا ...ولكن الاسعار عاليه جدا\\n 0\n", "40045 التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا... 0\n", "\n", "[40046 rows x 2 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 6, "id": "83df5c97-b49b-4431-8b0a-7a0f73219259", "metadata": {}, "outputs": [], "source": [ "df[\"rating\"] = df[\"rating\"].replace({1: \"إيجابي\",-1: \"سلبي\",0: \"محايد\"})\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "d4011ad3-17b0-401b-8f6b-03d5e6c8bb9c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائعإيجابي
1برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...إيجابي
2التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...سلبي
3لماذا لا يمكننا طلب من ماكدونالدز؟سلبي
4البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...سلبي
5أصبح غالي جداًسلبي
6جميل جدا رائع. . .إيجابي
7للأسف الواحد ينصدم بعد زيادة الاسعار و للاسف ب...سلبي
8برنامج توترز توصيل احلى من برنامجكم فاشلسلبي
9كتير في تحسن خدمة العملاء لطفين في بعض الاخطاء...إيجابي
\n", "
" ], "text/plain": [ " review_description rating\n", "0 رائع إيجابي\n", "1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... إيجابي\n", "2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... سلبي\n", "3 لماذا لا يمكننا طلب من ماكدونالدز؟ سلبي\n", "4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... سلبي\n", "5 أصبح غالي جداً سلبي\n", "6 جميل جدا رائع. . . إيجابي\n", "7 للأسف الواحد ينصدم بعد زيادة الاسعار و للاسف ب... سلبي\n", "8 برنامج توترز توصيل احلى من برنامجكم فاشل سلبي\n", "9 كتير في تحسن خدمة العملاء لطفين في بعض الاخطاء... إيجابي" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head(10)" ] }, { "cell_type": "code", "execution_count": 8, "id": "b443e76d-5d83-4369-93d1-d38441fdc5a5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'مافيش إشارة برسالة الطيار ياريت وده شيء سيئ جدًا 👎'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"review_description\"][100]" ] }, { "cell_type": "code", "execution_count": 9, "id": "c742d9de-5fa3-41f5-9f80-9de2e310482a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'نننقمىنررنركرململنيمرزرتبملنلدملنلللنااظاظلظل'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"review_description\"][500]" ] }, { "cell_type": "code", "execution_count": 10, "id": "6e4c3bb7-39e0-4ca7-8483-0d714a87ea3d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "review_description 1\n", "rating 0\n", "dtype: int64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.isna().sum()" ] }, { "cell_type": "code", "execution_count": 11, "id": "416ce6ec-e545-4af4-af89-429a35ccc9ab", "metadata": {}, "outputs": [], "source": [ "df = df.dropna()" ] }, { "cell_type": "code", "execution_count": 12, "id": "eb41f4e7-9371-4f8f-b6d7-9f48464965a6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.int64(941)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.duplicated().sum()" ] }, { "cell_type": "code", "execution_count": 13, "id": "cc590346-8f67-418a-b490-c56313272006", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
count4004540045
unique390033
topممتازإيجابي
freq1623921
\n", "
" ], "text/plain": [ " review_description rating\n", "count 40045 40045\n", "unique 39003 3\n", "top ممتاز إيجابي\n", "freq 16 23921" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.describe()" ] }, { "cell_type": "code", "execution_count": 14, "id": "c674b4a5-0a94-497f-b493-32a699a8ddec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "rating\n", "إيجابي 23921\n", "سلبي 14199\n", "محايد 1925\n", "Name: count, dtype: int64" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"rating\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 15, "id": "2969cae4-97e7-4099-a26e-ab4e7aaabfce", "metadata": {}, "outputs": [], "source": [ "df = df.drop_duplicates(subset=[\"review_description\"])" ] }, { "cell_type": "code", "execution_count": 16, "id": "d6ad9068-38ca-4f0c-9cdf-fd6676487095", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.int64(0)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.duplicated().sum()" ] }, { "cell_type": "code", "execution_count": 17, "id": "bea25222-18ad-4f46-954c-29755ebd9e9d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "review_description\n", "من 6890\n", "جدا 5879\n", "في 5579\n", "و 4181\n", "تطبيق 3766\n", " ... \n", "القطب 1\n", "مروعة 1\n", "حافلات 1\n", "الحافلات 1\n", "بتخلينى 1\n", "Name: count, Length: 55351, dtype: int64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"review_description\"].str.split().explode().value_counts()" ] }, { "cell_type": "code", "execution_count": 18, "id": "22c539c5-fd44-4cba-b426-699f9b0e3d37", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: camel-tools in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (1.6.0)\n", "Requirement already satisfied: cachetools>=6.0.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (7.2.7)\n", "Requirement already satisfied: dill>=0.4.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.4.1)\n", "Requirement already satisfied: docopt in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.6.2)\n", "Requirement already satisfied: editdistance in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.8.1)\n", "Requirement already satisfied: emoji in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2.16.0)\n", "Requirement already satisfied: future in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (1.0.0)\n", "Requirement already satisfied: muddler in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.1.3)\n", "Requirement already satisfied: numpy>=2.0.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2.1.3)\n", "Requirement already satisfied: pandas in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2.2.3)\n", "Requirement already satisfied: pyrsistent in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.20.0)\n", "Requirement already satisfied: regex in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2026.9.29)\n", "Requirement already satisfied: requests in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2.32.3)\n", "Requirement already satisfied: scikit-learn>=1.8.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (1.9.1)\n", "Requirement already satisfied: scipy in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (1.15.3)\n", "Requirement already satisfied: six in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (1.17.0)\n", "Requirement already satisfied: tabulate in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (0.9.0)\n", "Requirement already satisfied: torch>=2.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (2.15.0)\n", "Requirement already satisfied: tqdm in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (4.67.1)\n", "Requirement already satisfied: transformers>=4.44.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from camel-tools) (5.22.1)\n", "Requirement already satisfied: joblib>=1.4.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from scikit-learn>=1.8.0->camel-tools) (1.4.2)\n", "Requirement already satisfied: narwhals>=2.0.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from scikit-learn>=1.8.0->camel-tools) (2.28.0)\n", "Requirement already satisfied: threadpoolctl>=3.5.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from scikit-learn>=1.8.0->camel-tools) (3.5.0)\n", "Requirement already satisfied: filelock in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (3.17.0)\n", "Requirement already satisfied: typing-extensions>=4.13.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (4.16.0)\n", "Requirement already satisfied: setuptools>=77.0.3 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (84.2.1)\n", "Requirement already satisfied: sympy>=1.13.3 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (1.13.3)\n", "Requirement already satisfied: networkx>=2.5.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (3.4.2)\n", "Requirement already satisfied: jinja2 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (3.1.6)\n", "Requirement already satisfied: fsspec>=0.8.5 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from torch>=2.0->camel-tools) (2025.3.2)\n", "Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from sympy>=1.13.3->torch>=2.0->camel-tools) (1.3.0)\n", "Requirement already satisfied: huggingface-hub<3.0,>=1.31.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (2.4.0)\n", "Requirement already satisfied: packaging>=20.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (24.2)\n", "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (6.0.2)\n", "Requirement already satisfied: tokenizers<0.24.0,>=0.23.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (0.23.3)\n", "Requirement already satisfied: typer in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (0.9.0)\n", "Requirement already satisfied: safetensors>=0.8.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from transformers>=4.44.0->camel-tools) (0.8.0)\n", "Requirement already satisfied: click<9.0.0,>=8.4.2 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (8.5.0)\n", "Requirement already satisfied: hf-xet<2.0.0,>=1.6.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (1.8.0)\n", "Requirement already satisfied: httpx2<3,>=2.0.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (2.16.0)\n", "Requirement already satisfied: anyio>=4.10 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from httpx2<3,>=2.0.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (4.15.1)\n", "Requirement already satisfied: httpcore2==2.16.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from httpx2<3,>=2.0.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (2.16.0)\n", "Requirement already satisfied: idna>=3.18 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from httpx2<3,>=2.0.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (3.20)\n", "Requirement already satisfied: truststore>=0.10 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from httpx2<3,>=2.0.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (0.10.0)\n", "Requirement already satisfied: h11>=0.16 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from httpcore2==2.16.0->httpx2<3,>=2.0.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (0.16.0)\n", "Requirement already satisfied: colorama in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from tqdm->camel-tools) (0.4.6)\n", "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from jinja2->torch>=2.0->camel-tools) (3.0.2)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from pandas->camel-tools) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from pandas->camel-tools) (2024.1)\n", "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from pandas->camel-tools) (2025.2)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from requests->camel-tools) (3.3.2)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from requests->camel-tools) (2.3.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (from requests->camel-tools) (2025.4.26)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n" ] } ], "source": [ "pip install camel-tools" ] }, { "cell_type": "code", "execution_count": 19, "id": "98d4b7a5-e664-4026-8589-c9002d1c9853", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pyspellchecker in c:\\users\\sakina_saif\\anaconda3\\lib\\site-packages (0.9.1)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~cikit-learn (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~etuptools (C:\\Users\\Sakina_Saif\\anaconda3\\Lib\\site-packages)\n" ] } ], "source": [ "%pip install pyspellchecker" ] }, { "cell_type": "code", "execution_count": 38, "id": "c18208c2-8915-44ba-9519-fb6659539822", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The following packages will be installed: 'morphology-db-msa-r13'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "\u001b[Anloading package 'morphology-db-msa-r13': 0%|\u001b[32m \u001b[0m| 0.00/40.5M [00:00]+>\", \" \", text)\n", "\n", " # 4. حذف الروابط قبل حذف الحروف الإنجليزية\n", " text = re.sub(r\"(?:https?://|www\\.)\\S+\",\" \",text,flags=re.IGNORECASE,)\n", "\n", " # 5. حذف البريد الإلكتروني\n", " text = re.sub(r\"[\\w.+-]+@[\\w.-]+\\.[^\\W\\d_]{2,}\",\" \",text,)\n", "\n", " # 6. تحويل الإيموجي إلى أوصاف عربية\n", " text = emoji.demojize(text,language=\"ar\",delimiters=(\" \", \" \"),).replace(\"_\", \" \")\n", "\n", " # 7. تحويل الأسطر والتبويبات إلى مسافات\n", " text = re.sub(r\"\\s+\", \" \", text)\n", "\n", " # 8. حذف المحارف المخفية ومحارف التحكم\n", " text = \"\".join(\n", " char\n", " for char in text\n", " if unicodedata.category(char) not in {\"Cf\", \"Cc\", \"Cs\"}\n", " )\n", "\n", " # 9. حذف التشكيل\n", " text = dediac_ar(text)\n", "\n", " # 10. حذف التطويل\n", " text = text.replace(\"ـ\", \"\")\n", "\n", " # 11. توحيد الكاف والياء الفارسيتين في جميع المواضع\n", " text = text.translate(str.maketrans({\n", " \"ک\": \"ك\",\n", " \"ی\": \"ي\",\n", " \"ے\": \"ي\",}))\n", "\n", " # 12. تحويل الإنجليزية إلى حروف صغيرة\n", " text = text.lower()\n", "\n", " # توحيد الفاصلة العليا لتسهيل مطابقة العبارات الإنجليزية\n", " text = text.replace(\"’\", \"'\").replace(\"‘\", \"'\")\n", "\n", " # 13. ترجمة الكلمات والعبارات الموجودة في القاموس\n", " translations = {\n", " \"doesn't work\": \"لا يعمل\",\n", " \"does not work\": \"لا يعمل\",\n", " \"not good\": \"ليس جيد\",\n", " \"not bad\": \"ليس سيئ\",\n", " \"very good\": \"جيد جدا\",\n", " \"thank you\": \"شكرا لك\",\n", " \"don't\": \"لا\",\n", " \"excellent\": \"ممتاز\",\n", " \"amazing\": \"رائع\",\n", " \"great\": \"رائع\",\n", " \"terrible\": \"فظيع\",\n", " \"awful\": \"سيئ جدا\",\n", " \"good\": \"جيد\",\n", " \"bad\": \"سيئ\",\n", " \"slow\": \"بطيء\",\n", " \"fast\": \"سريع\",\n", " \"expensive\": \"غالي\",\n", " \"cheap\": \"رخيص\",\n", " \"thanks\": \"شكرا\",\n", " \"application\": \"تطبيق\",\n", " \"app\": \"تطبيق\",\n", " \"service\": \"خدمة\",\n", " \"delivery\": \"توصيل\",\n", " \"uninstall\": \"الغاء التثبيت\",\n", " \"not\": \"ليس\",\n", " \"no\": \"لا\",\n", " }\n", "\n", " pattern = (r\"(?\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائعإيجابي
1برنامج رائع جد ساعد تنبيه احتياج شكل اسرعإيجابي
2تطبيق لا فتح دائم اعطي لا وجد اتصال شبكه الان ...سلبي
3لماذا لا امكن طلب ماكدونالدسلبي
4برنامج اظهر مطعم مغلق ان كان فتح بقال كد اكتري...سلبي
.........
37996تجربه جيد نقص عدم اهتمام خدمه عميل عميل تواصل ...محايد
37997كان منطقه الكينج وجد عربه ساعه نصف وجه ابتسامه...سلبي
37998جيد لماذا لا وجد خط كثير المريوطيه فيصل نادي ر...محايد
37999جيد جد سعر عالي جدمحايد
38000تطبيق حلو جد خدمه ممتاز سعر عالي شويمحايد
\n", "

38001 rows × 2 columns

\n", "" ], "text/plain": [ " review_description rating\n", "0 رائع إيجابي\n", "1 برنامج رائع جد ساعد تنبيه احتياج شكل اسرع إيجابي\n", "2 تطبيق لا فتح دائم اعطي لا وجد اتصال شبكه الان ... سلبي\n", "3 لماذا لا امكن طلب ماكدونالد سلبي\n", "4 برنامج اظهر مطعم مغلق ان كان فتح بقال كد اكتري... سلبي\n", "... ... ...\n", "37996 تجربه جيد نقص عدم اهتمام خدمه عميل عميل تواصل ... محايد\n", "37997 كان منطقه الكينج وجد عربه ساعه نصف وجه ابتسامه... سلبي\n", "37998 جيد لماذا لا وجد خط كثير المريوطيه فيصل نادي ر... محايد\n", "37999 جيد جد سعر عالي جد محايد\n", "38000 تطبيق حلو جد خدمه ممتاز سعر عالي شوي محايد\n", "\n", "[38001 rows x 2 columns]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 28, "id": "945bc036-bab6-4296-84d6-fb277c36a19a", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split\n", "from sklearn.feature_extraction.text import TfidfVectorizer\n", "from sklearn.feature_extraction.text import CountVectorizer\n", "from sklearn.pipeline import Pipeline\n", "from sklearn.naive_bayes import MultinomialNB\n", "from sklearn.metrics import accuracy_score, classification_report" ] }, { "cell_type": "code", "execution_count": 29, "id": "b751ec45-598a-4fee-bf4b-0e6ceb56aece", "metadata": {}, "outputs": [], "source": [ "x = df[\"review_description\"]\n", "y = df[\"rating\"]" ] }, { "cell_type": "code", "execution_count": 30, "id": "80efeaa3-59ac-49c1-8bb6-9644d4a8cd59", "metadata": {}, "outputs": [], "source": [ "x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=42,stratify=y)" ] }, { "cell_type": "code", "execution_count": 31, "id": "019badbe-896a-432a-8cca-b30572291c1f", "metadata": {}, "outputs": [], "source": [ "TFIDF_model = Pipeline([(\"TFIDF\", TfidfVectorizer()), (\"Model\", MultinomialNB())])" ] }, { "cell_type": "code", "execution_count": 32, "id": "853d1018-e1c0-44ca-87ff-aa1355ff195c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Pipeline(steps=[('TFIDF', TfidfVectorizer()), ('Model', MultinomialNB())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "Pipeline(steps=[('TFIDF', TfidfVectorizer()), ('Model', MultinomialNB())])" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "TFIDF_model.fit(x_train, y_train)" ] }, { "cell_type": "code", "execution_count": 33, "id": "749f8da0-7452-44d3-95e0-04e15100403f", "metadata": {}, "outputs": [], "source": [ "y_pred = TFIDF_model.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 34, "id": "15db3d40-0180-4822-b5b7-f12c5005dda0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.8231811603736351" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "accuracy = accuracy_score(y_test, y_pred)\n", "accuracy" ] }, { "cell_type": "code", "execution_count": 35, "id": "64494e9f-35cc-422d-b3c8-92af3c33ca01", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " إيجابي 0.85 0.89 0.87 4481\n", " سلبي 0.78 0.82 0.80 2749\n", " محايد 0.00 0.00 0.00 371\n", "\n", " accuracy 0.82 7601\n", " macro avg 0.54 0.57 0.56 7601\n", "weighted avg 0.78 0.82 0.80 7601\n", "\n" ] } ], "source": [ "print(classification_report(y_test, y_pred, zero_division=0))" ] }, { "cell_type": "code", "execution_count": 36, "id": "4a142caf-5524-4090-b0e1-e07aba24d7a5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "التعليق: التطبيق ممتاز وسهل الاستخدام\n", "التصنيف المتوقع: إيجابي\n", "----------------------------------------\n", "التعليق: الخدمة ليست ج ولا انصح بها\n", "التصنيف المتوقع: إيجابي\n", "----------------------------------------\n", "التعليق: التطبيق عادي\n", "التصنيف المتوقع: سلبي\n", "----------------------------------------\n" ] } ], "source": [ "reviews = [\n", " \"التطبيق ممتاز وسهل الاستخدام\",\n", " \"الخدمة ليست ج ولا انصح بها\",\n", " \"التطبيق عادي\",\n", "]\n", "\n", "cleaned_reviews = [clean_review(review) for review in reviews]\n", "\n", "predictions = TFIDF_model.predict(cleaned_reviews)\n", "\n", "for review, prediction in zip(reviews, predictions):\n", " print(f\"التعليق: {review}\")\n", " print(f\"التصنيف المتوقع: {prediction}\")\n", " print(\"-\" * 40)" ] }, { "cell_type": "code", "execution_count": 37, "id": "174115ef-f1ab-484f-aadf-aff5e1ac2704", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "تم حفظ النموذج بنجاح\n" ] } ], "source": [ "import joblib\n", "\n", "joblib.dump(\n", " TFIDF_model,\n", " \"Arabic_Sentiment_Model.joblib\"\n", ")\n", "\n", "print(\"تم حفظ النموذج بنجاح\")" ] }, { "cell_type": "code", "execution_count": null, "id": "31e68346-9d7b-49c5-bd59-25b9baafb65f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "2b28e895-eb11-48fd-90db-481ebcf0685f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "b5930345-d892-4f56-84b7-bc7ac0bbfc5e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "9f16adf3-1ed5-48c1-ac34-84fa6da8502c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.5" } }, "nbformat": 4, "nbformat_minor": 5 }