{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30761,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Digit Recoginzer Prediction","metadata":{}},{"cell_type":"markdown","source":"![Handwritten-digit-recognition.png](https://www.google.co.in/url?sa=i&url=https%3A%2F%2Fpartheniumprojects.com%2Fhandwritten-digit-recognition-using-image-processing%2F&psig=AOvVaw3vK4ae2hBM17hMRFPu5Cid&ust=1725975698315000&source=images&cd=vfe&opi=89978449&ved=0CBQQjRxqFwoTCOCinNb-tYgDFQAAAAAdAAAAABAE)","metadata":{}},{"cell_type":"markdown","source":"\nThe Digit Recognizer dataset is a popular dataset used for training and testing machine learning models, particularly for image classification tasks. Here's a general overview:\n\n### Overview\n\n- **Content**: The dataset consists of grayscale images of handwritten digits, where each image is a 28x28 pixel square. Each pixel in the image is represented by a value between 0 and 255, indicating the intensity of the pixel.\n\n- **Purpose**: It's commonly used to train and evaluate models for recognizing digits (0 through 9) in images. This is a classic problem in computer vision and machine learning.\n\n### Structure\n\n- **Training Set**: Contains a large number of labeled images (each labeled with the correct digit it represents). Typically, this set includes thousands of images.\n\n- **Test Set**: Contains images similar to those in the training set but without labels. Thegoal is to predict the labels for these images.","metadata":{}},{"cell_type":"code","source":"# Importing the Dataset from the Kaggle\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:53.793262Z","iopub.execute_input":"2024-09-09T13:47:53.793761Z","iopub.status.idle":"2024-09-09T13:47:53.814077Z","shell.execute_reply.started":"2024-09-09T13:47:53.793717Z","shell.execute_reply":"2024-09-09T13:47:53.812856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## EDA\n\n#### Basic dataframe exploration","metadata":{}},{"cell_type":"code","source":"# Standard\nimport warnings\nimport string\n\n# Third-party\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# ML \nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder, OrdinalEncoder\nfrom sklearn.impute import SimpleImputer, KNNImputer\nfrom scipy.stats import boxcox\nfrom scipy.special import inv_boxcox\nfrom sklearn.decomposition import PCA\nfrom sklearn.manifold import TSNE\n\n# ML-Algorithm\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.svm import LinearSVC\nfrom sklearn.svm import SVC\nfrom xgboost import XGBClassifier\nfrom catboost import CatBoostClassifier\n\nfrom sklearn.metrics import accuracy_score, classification_report, confusion_matrix, matthews_corrcoef\n\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:53.910504Z","iopub.execute_input":"2024-09-09T13:47:53.911350Z","iopub.status.idle":"2024-09-09T13:47:53.921301Z","shell.execute_reply.started":"2024-09-09T13:47:53.911252Z","shell.execute_reply":"2024-09-09T13:47:53.920083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load Dataset","metadata":{}},{"cell_type":"code","source":"# data directory\ntrain_dir = '/kaggle/input/digit-recognizer/train.csv'\ntest_dir = '/kaggle/input/digit-recognizer/test.csv'\nsub_dir = '/kaggle/input/digit-recognizer/sample_submission.csv'\n\n# load data\ndf = pd.read_csv(train_dir)\ntest = pd.read_csv(test_dir)\nsub = pd.read_csv(sub_dir)\n\n# quick view\nprint(\"Training data shape:\", df.shape)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:53.997198Z","iopub.execute_input":"2024-09-09T13:47:53.997734Z","iopub.status.idle":"2024-09-09T13:47:59.800175Z","shell.execute_reply.started":"2024-09-09T13:47:53.997690Z","shell.execute_reply":"2024-09-09T13:47:59.798965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# explore dataset\nprint(\"\\nDataset Info:\")\nprint(df.info())\nprint(\"--\" * 20)\nprint('First Few Rows:')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:59.802382Z","iopub.execute_input":"2024-09-09T13:47:59.802786Z","iopub.status.idle":"2024-09-09T13:47:59.866332Z","shell.execute_reply.started":"2024-09-09T13:47:59.802745Z","shell.execute_reply":"2024-09-09T13:47:59.865035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualizing Numerical Data Distributions\nThis function creates histograms and Kernel Density Estimate (KDE) plots for each numerical feature in a DataFrame. These visualizations help assess the distribution of numerical data, identifying skewness and the presence of outliers. By examining these plots, we can better understand the data's characteristics, which aids in making informed decisions on necessary data preprocessing steps such as normalization and outlier treatment. The visual output is especially useful for spotting distribution anomalies and verifying the effectiveness of any transformations applied to the data.","metadata":{}},{"cell_type":"code","source":"def visualize_numerical_distributions(df):\n    # Identify numerical columns\n    numerical_columns = df.select_dtypes(include=['number']).columns\n    \n    # Setup the figure for multiple subplots\n    num_cols = 5\n    num_rows = (len(numerical_columns) + num_cols - 1) // num_cols\n    \n    fig, axes = plt.subplots(num_rows, num_cols, figsize=(18, 5 * num_rows))\n    fig.suptitle(\"Distribution of Numerical Features\", fontsize=16)\n    \n    # Flatten axes array for easy iteration\n    axes = axes.flatten()\n    \n    # Iterate over each numerical column and create a histogram with KDE\n    for i, col in enumerate(numerical_columns):\n        sns.histplot(df[col], kde=True, ax=axes[i], color='skyblue', element='step', stat='density')\n        axes[i].set_title(f'Distribution of {col}', fontsize=14)\n        axes[i].set_xlabel(col, fontsize=12)\n        axes[i].set_ylabel('Density', fontsize=12)\n        \n    # Remove unused axes\n    for j in range(i + 1, len(axes)):\n        fig.delaxes(axes[j])\n        \n    # Adjust layout\n    plt.tight_layout(rect=[0, 0.03, 1, 0.95])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:59.867703Z","iopub.execute_input":"2024-09-09T13:47:59.868080Z","iopub.status.idle":"2024-09-09T13:47:59.879038Z","shell.execute_reply.started":"2024-09-09T13:47:59.868043Z","shell.execute_reply":"2024-09-09T13:47:59.877702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# visualize_numerical_distributions(df)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:59.880460Z","iopub.execute_input":"2024-09-09T13:47:59.880818Z","iopub.status.idle":"2024-09-09T13:47:59.892973Z","shell.execute_reply.started":"2024-09-09T13:47:59.880780Z","shell.execute_reply":"2024-09-09T13:47:59.891604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Adjusting Skewness in Numerical Features\nGiven the observed right skewness in features such as cap-diameter, stem-height, and stem-width, we've updated our skewness handling function to apply Box-Cox transformations selectively. This transformation will only be applied to features exhibiting a skewness greater than 1.0, targeting highly skewed distributions. This approach helps normalize these features, enhancing modeling efforts by stabilizing variance and making the data more conformant to the normal distribution assumptions required by many statistical modeling techniques. The transformation parameters (lambda values) are also retained for each feature, allowing for the precise reversal or consistent application to other data sets.","metadata":{}},{"cell_type":"code","source":"def handle_skewness(df, threshold=1.0):\n    \"\"\"\n    Applies Box-Cox transformation to numerical columns in the DataFrame where skewness exceeds a threshold.\n    \n    Parameters:\n    - df (pd.DataFrame): The input DataFrame.\n    - threshold (float): Skewness threshold to decide which columns to transform.\n    \n    Returns:\n    - pd.DataFrame: DataFrame with transformed columns.\n    - dict: Dictionary of lambda values used for Box-Cox transformation for each column.\n    \"\"\"\n    numeric_cols = df.select_dtypes(include=['number']).columns\n    lambda_dict = {}\n    \n    for col in numeric_cols:\n        skewness = df[col].skew()\n        # Check the skewness and ensure positive values for Box-Cox\n        if skewness > threshold:\n            # Adding 1 to shift all data to positive if there are zero or negative values\n            df[col] = df[col] + 1\n            df[col], fitted_lambda = boxcox(df[col])\n            lambda_dict[col] = fitted_lambda\n    \n    return df, lambda_dict\n\n# Example usage:\n# df is your DataFrame containing the numerical data\ndf, lambda_values = handle_skewness(df)\ntest, lambda_test = handle_skewness(test)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:47:59.896217Z","iopub.execute_input":"2024-09-09T13:47:59.896644Z","iopub.status.idle":"2024-09-09T13:50:54.544042Z","shell.execute_reply.started":"2024-09-09T13:47:59.896597Z","shell.execute_reply":"2024-09-09T13:50:54.542870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# visualize_numerical_distributions(df)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:50:54.545853Z","iopub.execute_input":"2024-09-09T13:50:54.546244Z","iopub.status.idle":"2024-09-09T13:50:54.551102Z","shell.execute_reply.started":"2024-09-09T13:50:54.546206Z","shell.execute_reply":"2024-09-09T13:50:54.549747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualizing Outliers with Box Plots\nThe provided function visualize_box_plots is designed to plot the numerical data within a DataFrame using box plots. Each plot displays the minimum, first quartile, median, third quartile, and maximum, with outliers clearly marked beyond the whiskers. This visual aid is crucial for quick outlier detection and helps in decisions regarding data cleaning or outlier handling strategies. Box plots are particularly useful because they do not only identify outliers but also provide a concise summary of the data's distribution, including its central tendency and variability. By visualizing these plots, one can effectively assess the need for further data processing steps such as outlier removal or transformation.","metadata":{}},{"cell_type":"code","source":"def visualize_box_plots(df):\n    \"\"\"\n    Visualizes the distribution of numerical features in the DataFrame using box plots to identify outliers.\n    \n    Parameters:\n    - df (pd.DataFrame): The DataFrame containing the numerical features to visualize.\n    \n    Returns:\n    - None: Displays the box plots.\n    \"\"\"\n    # Identify numerical columns\n    numerical_columns = df.select_dtypes(include=['number']).columns\n\n    # Set up the figure for multiple subplots\n    num_cols = 3  # Number of columns for the subplot grid\n    num_rows = (len(numerical_columns) + num_cols - 1) // num_cols  # Calculate number of rows needed\n\n    fig, axes = plt.subplots(num_rows, num_cols, figsize=(18, 5 * num_rows))\n    fig.suptitle('Box Plot of Numerical Features', fontsize=16)\n\n    # Flatten axes array for easy iteration\n    axes = axes.flatten()\n\n    # Iterate over each numerical column and create a box plot\n    for i, col in enumerate(numerical_columns):\n        sns.boxplot(x=df[col], ax=axes[i], color=\"skyblue\")\n        axes[i].set_title(f'Box Plot of {col}', fontsize=14)\n        axes[i].set_xlabel(col, fontsize=12)\n\n    # Remove unused axes\n    for j in range(i + 1, len(axes)):\n        fig.delaxes(axes[j])\n\n    # Adjust layout\n    plt.tight_layout(rect=[0, 0.03, 1, 0.95])  # Adjust the main title space\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:50:54.552602Z","iopub.execute_input":"2024-09-09T13:50:54.552996Z","iopub.status.idle":"2024-09-09T13:50:54.565903Z","shell.execute_reply.started":"2024-09-09T13:50:54.552958Z","shell.execute_reply":"2024-09-09T13:50:54.564653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# visualize_box_plots(df)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:50:54.567782Z","iopub.execute_input":"2024-09-09T13:50:54.568775Z","iopub.status.idle":"2024-09-09T13:50:54.580561Z","shell.execute_reply.started":"2024-09-09T13:50:54.568707Z","shell.execute_reply":"2024-09-09T13:50:54.579385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Managing Outliers in Numerical Data\nThe function handle_outliers caps values beyond 1.5 times the interquartile range (IQR) from the first and third quartiles. This approach, known as the IQR method, is effective for reducing the impact of extreme outliers without losing valuable data. By capping rather than removing these points, we retain all records for analysis, ensuring robustness in our statistical tests and models. This method is applied to both the training and test datasets to maintain consistency in data processing, crucial for accurate model evaluation. The handling of outliers helps stabilize the datasets, making them more uniform and enhancing the predictive performance of subsequent modeling steps.","metadata":{}},{"cell_type":"code","source":"def calculate_outliers_percentage(df):\n    outlier_counts = {}\n    \n    for column in df.select_dtypes(include=['number']).columns:\n        Q1 = df[column].quantile(0.25)\n        Q3 = df[column].quantile(0.75)\n        \n        IQR = Q3 - Q1\n        \n        lower_bound = Q1 - 1.5 * IQR\n        upper_bound = Q3 + 1.5 * IQR\n        \n        # Calculate outliers\n        outliers = df[(df[column] < lower_bound) | (df[column] > upper_bound)]\n        outlier_counts[column] = len(outliers)\n    \n    # Print the percentage of outliers for each column\n    for column in outlier_counts:\n        percentage = (outlier_counts[column] / len(df)) * 100\n        print(f\"Percentage of Outliers in {column}: {percentage:.2f}%\")\n\n# Example usage:\ncalculate_outliers_percentage(df)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:50:54.582214Z","iopub.execute_input":"2024-09-09T13:50:54.582715Z","iopub.status.idle":"2024-09-09T13:51:17.937012Z","shell.execute_reply.started":"2024-09-09T13:50:54.582661Z","shell.execute_reply":"2024-09-09T13:51:17.935708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def handle_outliers(df):\n    \"\"\"\n    Handles outliers in a DataFrame by capping based on the IQR method.\n\n    Parameters:\n    - df (pd.DataFrame): DataFrame to process.\n\n    Returns:\n    - pd.DataFrame: DataFrame with outliers handled.\n    \"\"\"\n    for column in df.select_dtypes(include=['number']).columns:\n        Q1 = df[column].quantile(0.25)\n        Q3 = df[column].quantile(0.75)\n        IQR = Q3 - Q1\n        lower_bound = Q1 - 1.5 * IQR\n        upper_bound = Q3 + 1.5 * IQR\n        \n        # Capping\n        df[column] = df[column].clip(lower=lower_bound, upper=upper_bound)\n    \n    return df\n\n# Apply to both training and test datasets\ndf = handle_outliers(df)\ntest = handle_outliers(test)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:17.939150Z","iopub.execute_input":"2024-09-09T13:51:17.939639Z","iopub.status.idle":"2024-09-09T13:51:24.463161Z","shell.execute_reply.started":"2024-09-09T13:51:17.939587Z","shell.execute_reply":"2024-09-09T13:51:24.462156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Scaler Numerical Data","metadata":{}},{"cell_type":"code","source":"scaler = StandardScaler()\n\ntrain_data = df.drop('label', axis=1)\n# Standardize the numeric features\nX = scaler.fit_transform(train_data)\ntest = scaler.fit_transform(test)\n\n# Prepare target\ny = df.label","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:24.464737Z","iopub.execute_input":"2024-09-09T13:51:24.465220Z","iopub.status.idle":"2024-09-09T13:51:26.016426Z","shell.execute_reply.started":"2024-09-09T13:51:24.465152Z","shell.execute_reply":"2024-09-09T13:51:26.015208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Split the data\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=True, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:26.018374Z","iopub.execute_input":"2024-09-09T13:51:26.018763Z","iopub.status.idle":"2024-09-09T13:51:27.125807Z","shell.execute_reply.started":"2024-09-09T13:51:26.018724Z","shell.execute_reply":"2024-09-09T13:51:27.124493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Logistic Regression Model","metadata":{}},{"cell_type":"code","source":"# Training With Logistic Regression Algo\nmodel_1 = LogisticRegression()\n\n# fit the X and y\nmodel_1.fit(X_train, y_train)\n\n# predict\npred_1 = model_1.predict(X_test)\n\n# Accuracy Score\nlog_ac = accuracy_score(y_test, pred_1)\nprint(f'Logistic Regression AC: {log_ac}')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:27.127490Z","iopub.execute_input":"2024-09-09T13:51:27.127899Z","iopub.status.idle":"2024-09-09T13:51:36.013784Z","shell.execute_reply.started":"2024-09-09T13:51:27.127845Z","shell.execute_reply":"2024-09-09T13:51:36.012610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## DecisionTreeClassifier Model","metadata":{}},{"cell_type":"code","source":"# Training with DecisionTreeClassifier Algo\nmodel_2 = DecisionTreeClassifier()\n\n# fit the X_train and y_train\nmodel_2.fit(X_train, y_train)\n\n# Predict\npred_2 = model_2.predict(X_test)\n\n# Accuracy Score\ndtc_ac = accuracy_score(y_test, pred_2)\nprint(f'DecisionTreeClassifier AC: {dtc_ac}')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:36.019176Z","iopub.execute_input":"2024-09-09T13:51:36.020553Z","iopub.status.idle":"2024-09-09T13:51:43.739152Z","shell.execute_reply.started":"2024-09-09T13:51:36.020498Z","shell.execute_reply":"2024-09-09T13:51:43.737717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## RandomForestClassifier Model","metadata":{}},{"cell_type":"code","source":"# Training with RandomForestClassifier Algo\nmodel_3 = RandomForestClassifier()\n\n# fit the X_train and y_train\nmodel_3.fit(X_train, y_train)\n\n# Predict\npred_3 = model_3.predict(X_test)\n\n# Accuracy Score\nrfc_ac = accuracy_score(y_test, pred_3)\nprint(f'RandomForestClassifier AC: {rfc_ac}')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:51:43.740741Z","iopub.execute_input":"2024-09-09T13:51:43.741213Z","iopub.status.idle":"2024-09-09T13:52:04.934109Z","shell.execute_reply.started":"2024-09-09T13:51:43.741171Z","shell.execute_reply":"2024-09-09T13:52:04.932840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## LinearSVC","metadata":{}},{"cell_type":"code","source":"# Training With LinearSVC Algo\nmodel_4 = LinearSVC()\n\n# fit the X_traina and y_train\nmodel_4.fit(X_train, y_train)\n\n# Predict\npred_4 = model_4.predict(X_test)\n\n# Accuracy Score\nl_scv_ac = accuracy_score(y_test, pred_4)\nprint(f'Linear SVC AC: {l_scv_ac}')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:52:04.936070Z","iopub.execute_input":"2024-09-09T13:52:04.936495Z","iopub.status.idle":"2024-09-09T13:54:53.787852Z","shell.execute_reply.started":"2024-09-09T13:52:04.936453Z","shell.execute_reply":"2024-09-09T13:54:53.783346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## SVC Model","metadata":{}},{"cell_type":"code","source":"# Training With SVC Algo\nmodel_5 = SVC()\n\n# fit the X_train and y_train\nmodel_5.fit(X_train, y_train)\n\n# Predict \npred_5 = model_5.predict(X_test)\n\n# Accuracy Score\nsvc_ac = accuracy_score(y_test, pred_5)\nprint(f'SVC AC: {svc_ac}')","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:54:53.790701Z","iopub.execute_input":"2024-09-09T13:54:53.791362Z","iopub.status.idle":"2024-09-09T13:57:57.537792Z","shell.execute_reply.started":"2024-09-09T13:54:53.791277Z","shell.execute_reply":"2024-09-09T13:57:57.536451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## XGBClassifier Model","metadata":{}},{"cell_type":"code","source":"# Training With XGBClassifier Algo\nmodel_6 = XGBClassifier()\n\n# Fit the X_train and y_train\nmodel_6.fit(X_train, y_train)\n\n# Predict\npred_6 = model_6.predict(X_test)\n\n# Accuracy Score\nxgbc_ac = accuracy_score(y_test, pred_6)\nprint(f\"XGBClassifier AC: {xgbc_ac}\")","metadata":{"execution":{"iopub.status.busy":"2024-09-09T13:57:57.539553Z","iopub.execute_input":"2024-09-09T13:57:57.539970Z","iopub.status.idle":"2024-09-09T14:00:02.054599Z","shell.execute_reply.started":"2024-09-09T13:57:57.539929Z","shell.execute_reply":"2024-09-09T14:00:02.053625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Best Model","metadata":{}},{"cell_type":"code","source":"model_ac = pd.DataFrame({\"Model-Name\": [\"LogisticRegression\", \"DecisionTreeClassifier\", \"RandomForestClassifier\", \"LinearSVC\", \"SVC\", \"XGBClassifier\"], \"Model-Accuracy-Score\": [log_ac, dtc_ac, rfc_ac, l_scv_ac, svc_ac, xgbc_ac]})","metadata":{"execution":{"iopub.status.busy":"2024-09-09T14:00:02.055904Z","iopub.execute_input":"2024-09-09T14:00:02.056700Z","iopub.status.idle":"2024-09-09T14:00:02.063556Z","shell.execute_reply.started":"2024-09-09T14:00:02.056655Z","shell.execute_reply":"2024-09-09T14:00:02.062295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Bar Plot Model-Accuracy-Score","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(15, 7))\nsns.barplot(data=model_ac, x=\"Model-Name\", y='Model-Accuracy-Score')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-09-09T14:00:02.065047Z","iopub.execute_input":"2024-09-09T14:00:02.065913Z","iopub.status.idle":"2024-09-09T14:00:02.383395Z","shell.execute_reply.started":"2024-09-09T14:00:02.065841Z","shell.execute_reply":"2024-09-09T14:00:02.382117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Confusion Matrix","metadata":{}},{"cell_type":"code","source":"cm = confusion_matrix(y_test, pred_6)\nplt.figure(figsize=(8, 6))\nsns.heatmap(cm, annot=True, fmt='d', cmap='Blues')\nplt.title(\"Confusion Matrix\")\nplt.xlabel(\"Predicted\")\nplt.ylabel(\"Actual\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-09-09T14:03:00.531166Z","iopub.execute_input":"2024-09-09T14:03:00.531762Z","iopub.status.idle":"2024-09-09T14:03:01.208354Z","shell.execute_reply.started":"2024-09-09T14:03:00.531718Z","shell.execute_reply":"2024-09-09T14:03:01.206997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Training With XGBClassifier Algo\nmodel_6 = XGBClassifier()\n\n# Fit the X and y\nmodel_6.fit(X, y)\n\n# Predict\ntest_pred = model_6.predict(test)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T14:07:04.163217Z","iopub.execute_input":"2024-09-09T14:07:04.163771Z","iopub.status.idle":"2024-09-09T14:09:34.034368Z","shell.execute_reply.started":"2024-09-09T14:07:04.163717Z","shell.execute_reply":"2024-09-09T14:09:34.033280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Prepare Submission\nsub['label'] = test_pred\nsub.to_csv('digit_recognizer.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-09-09T14:10:51.155902Z","iopub.execute_input":"2024-09-09T14:10:51.156397Z","iopub.status.idle":"2024-09-09T14:10:51.216222Z","shell.execute_reply.started":"2024-09-09T14:10:51.156352Z","shell.execute_reply":"2024-09-09T14:10:51.214955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}