{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96416,"databundleVersionId":11456366,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:50:43.479768Z","iopub.execute_input":"2025-03-23T15:50:43.480053Z","iopub.status.idle":"2025-03-23T15:50:44.782475Z","shell.execute_reply.started":"2025-03-23T15:50:43.480026Z","shell.execute_reply":"2025-03-23T15:50:44.781281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n\ntrain = pd.read_csv(\"/kaggle/input/digit-recognizer-challenge/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/digit-recognizer-challenge/test.csv\")\n\ntrain.head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:52:09.732048Z","iopub.execute_input":"2025-03-23T15:52:09.732443Z","iopub.status.idle":"2025-03-23T15:52:14.633343Z","shell.execute_reply.started":"2025-03-23T15:52:09.732409Z","shell.execute_reply":"2025-03-23T15:52:14.632253Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nfig, axes = plt.subplots(1, 5, figsize=(10, 5))\nfor i, ax in enumerate(axes):\n    img = train.iloc[i, 1:].values.reshape(28, 28)\n    ax.imshow(img, cmap=\"gray\")\n    ax.set_title(f\"Label: {train.iloc[i, 0]}\")\n    ax.axis(\"off\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:52:23.467918Z","iopub.execute_input":"2025-03-23T15:52:23.468399Z","iopub.status.idle":"2025-03-23T15:52:23.850741Z","shell.execute_reply.started":"2025-03-23T15:52:23.468339Z","shell.execute_reply":"2025-03-23T15:52:23.849702Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfig, axes = plt.subplots(1, 5, figsize=(10, 5))\nfor i, ax in enumerate(axes):\n    img = train.iloc[i, 1:].values.reshape(28, 28)\n    ax.imshow(img, cmap=\"gray\")\n    ax.set_title(f\"Label: {train.iloc[i, 0]}\")\n    ax.axis(\"off\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:52:35.804080Z","iopub.execute_input":"2025-03-23T15:52:35.804550Z","iopub.status.idle":"2025-03-23T15:52:36.093074Z","shell.execute_reply.started":"2025-03-23T15:52:35.804497Z","shell.execute_reply":"2025-03-23T15:52:36.092019Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\n\n# تحضير البيانات\nX = train.drop(\"label\", axis=1)\ny = train[\"label\"]\n\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)\n\n\nrf = RandomForestClassifier(n_estimators=100, random_state=42)\nrf.fit(X_train, y_train)\n\ny_pred = rf.predict(X_val)\naccuracy = accuracy_score(y_val, y_pred)\nprint(f\"Accuracy: {accuracy * 100:.2f}%\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:53:27.410990Z","iopub.execute_input":"2025-03-23T15:53:27.411356Z","iopub.status.idle":"2025-03-23T15:53:52.478748Z","shell.execute_reply.started":"2025-03-23T15:53:27.411325Z","shell.execute_reply":"2025-03-23T15:53:52.477615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Flatten\nfrom tensorflow.keras.optimizers import Adam\n\n# بناء النموذج\nmodel = Sequential([\n    Flatten(input_shape=(784,)),\n    Dense(128, activation=\"relu\"),\n    Dense(64, activation=\"relu\"),\n    Dense(10, activation=\"softmax\")\n])\n\n# تجميع النموذج\nmodel.compile(optimizer=Adam(), loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"])\n\n# التدريب\nmodel.fit(X_train, y_train, epochs=10, validation_data=(X_val, y_val))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:54:09.987203Z","iopub.execute_input":"2025-03-23T15:54:09.987628Z","iopub.status.idle":"2025-03-23T15:54:57.543483Z","shell.execute_reply.started":"2025-03-23T15:54:09.987595Z","shell.execute_reply":"2025-03-23T15:54:57.542500Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# التنبؤ بالاختبار\npredictions = model.predict(test)\npredictions = np.argmax(predictions, axis=1)\n\n# إنشاء ملف الإرسال\nsubmission = pd.DataFrame({\"ImageId\": list(range(1, len(predictions)+1)), \"Label\": predictions})\nsubmission.to_csv(\"submission.csv\", index=False)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-23T15:55:35.957742Z","iopub.execute_input":"2025-03-23T15:55:35.958568Z","iopub.status.idle":"2025-03-23T15:55:37.915528Z","shell.execute_reply.started":"2025-03-23T15:55:35.958531Z","shell.execute_reply":"2025-03-23T15:55:37.914443Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}