{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "51c78b68",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sklearn\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import log_loss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4421a043",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training data shape: (25000, 2560), labels shape: (25000,)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LogisticRegression(max_iter=2000)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.load(f'data_features/X_train_b7.npy')\n",
    "y = np.load(f'data_features/y_train_b7.npy')\n",
    "\n",
    "# Split data and train classifier\n",
    "print(f\"Training data shape: {X.shape}, labels shape: {y.shape}\")\n",
    "X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.001, random_state=1337)\n",
    "clf = LogisticRegression(max_iter=2000)\n",
    "clf.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d5cfc5b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On validation set:\n",
      "Accuracy: 1.0\n",
      "LOG LOSS: 7.980845755748817e-05 \n",
      "%--------------------------------------------------%\n",
      "Getting predictions for test set\n",
      "Done getting predictions!\n"
     ]
    }
   ],
   "source": [
    "# Check on validation\n",
    "val_preds= clf.predict_proba(X_val)[:,1]\n",
    "print(f\"On validation set:\")\n",
    "print(f\"Accuracy: {clf.score(X_val, y_val)}\")\n",
    "print(f\"LOG LOSS: {log_loss(y_val, val_preds)} \")\n",
    "print(\"%--------------------------------------------------%\")\n",
    "\n",
    "# Get predictions on test set\n",
    "print(\"Getting predictions for test set\")\n",
    "X_test = np.load(f'data_features/X_test_b7.npy')\n",
    "X_test_preds = clf.predict_proba(X_test)[:,1]\n",
    "df = pd.DataFrame({'id': np.arange(1, 12501), 'label': np.clip(X_test_preds, 0.005, 0.995)})\n",
    "df.to_csv(f\"submissions/mysubmission.csv\", index=False)\n",
    "print(\"Done getting predictions!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9cce7af",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
