{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"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","execution":{"iopub.status.busy":"2023-03-11T10:01:16.541987Z","iopub.execute_input":"2023-03-11T10:01:16.542570Z","iopub.status.idle":"2023-03-11T10:01:16.551489Z","shell.execute_reply.started":"2023-03-11T10:01:16.542526Z","shell.execute_reply":"2023-03-11T10:01:16.550213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.datasets import load_digits\n%matplotlib inline \nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:01:24.092184Z","iopub.execute_input":"2023-03-11T10:01:24.093072Z","iopub.status.idle":"2023-03-11T10:01:24.656895Z","shell.execute_reply.started":"2023-03-11T10:01:24.093015Z","shell.execute_reply":"2023-03-11T10:01:24.655782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"digits = load_digits()","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:01:30.468779Z","iopub.execute_input":"2023-03-11T10:01:30.469220Z","iopub.status.idle":"2023-03-11T10:01:30.561525Z","shell.execute_reply.started":"2023-03-11T10:01:30.469184Z","shell.execute_reply":"2023-03-11T10:01:30.559976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.gray()\nfor i in range(2):\n  plt.matshow(digits.images[i])","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:03:01.371220Z","iopub.execute_input":"2023-03-11T10:03:01.371647Z","iopub.status.idle":"2023-03-11T10:03:02.122256Z","shell.execute_reply.started":"2023-03-11T10:03:01.371613Z","shell.execute_reply":"2023-03-11T10:03:02.120498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dir(digits)","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:03:15.770399Z","iopub.execute_input":"2023-03-11T10:03:15.770804Z","iopub.status.idle":"2023-03-11T10:03:15.779067Z","shell.execute_reply.started":"2023-03-11T10:03:15.770768Z","shell.execute_reply":"2023-03-11T10:03:15.777860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"digits.data[1]","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:03:31.905364Z","iopub.execute_input":"2023-03-11T10:03:31.905838Z","iopub.status.idle":"2023-03-11T10:03:31.915547Z","shell.execute_reply.started":"2023-03-11T10:03:31.905793Z","shell.execute_reply":"2023-03-11T10:03:31.913646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:03:43.194618Z","iopub.execute_input":"2023-03-11T10:03:43.195057Z","iopub.status.idle":"2023-03-11T10:03:43.362424Z","shell.execute_reply.started":"2023-03-11T10:03:43.195022Z","shell.execute_reply":"2023-03-11T10:03:43.360907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:03:51.038592Z","iopub.execute_input":"2023-03-11T10:03:51.039612Z","iopub.status.idle":"2023-03-11T10:03:51.045005Z","shell.execute_reply.started":"2023-03-11T10:03:51.039559Z","shell.execute_reply":"2023-03-11T10:03:51.043619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, Y_train, Y_test = train_test_split(\n                                                    digits.data, \n                                                    digits.target, \n                                                    test_size = 0.2, \n                                                    random_state = 11\n                                                    )","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:01.631444Z","iopub.execute_input":"2023-03-11T10:04:01.632779Z","iopub.status.idle":"2023-03-11T10:04:01.641867Z","shell.execute_reply.started":"2023-03-11T10:04:01.632726Z","shell.execute_reply":"2023-03-11T10:04:01.640340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LogisticRegression(solver='lbfgs',class_weight='balanced', max_iter=10000)\nmodel.fit(X_train, Y_train)","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:09.646958Z","iopub.execute_input":"2023-03-11T10:04:09.648118Z","iopub.status.idle":"2023-03-11T10:04:20.348051Z","shell.execute_reply.started":"2023-03-11T10:04:09.648072Z","shell.execute_reply":"2023-03-11T10:04:20.346745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.score(X_test, Y_test)","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:20.350464Z","iopub.execute_input":"2023-03-11T10:04:20.351285Z","iopub.status.idle":"2023-03-11T10:04:20.363625Z","shell.execute_reply.started":"2023-03-11T10:04:20.351229Z","shell.execute_reply":"2023-03-11T10:04:20.362306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict(digits.data)","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:25.330589Z","iopub.execute_input":"2023-03-11T10:04:25.331017Z","iopub.status.idle":"2023-03-11T10:04:25.344273Z","shell.execute_reply.started":"2023-03-11T10:04:25.330971Z","shell.execute_reply":"2023-03-11T10:04:25.342186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"digits.target[67]","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:33.170102Z","iopub.execute_input":"2023-03-11T10:04:33.170689Z","iopub.status.idle":"2023-03-11T10:04:33.178715Z","shell.execute_reply.started":"2023-03-11T10:04:33.170645Z","shell.execute_reply":"2023-03-11T10:04:33.177472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict([digits.data[67]])","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:41.156665Z","iopub.execute_input":"2023-03-11T10:04:41.157049Z","iopub.status.idle":"2023-03-11T10:04:41.166416Z","shell.execute_reply.started":"2023-03-11T10:04:41.157014Z","shell.execute_reply":"2023-03-11T10:04:41.164774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_predictions = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:48.489328Z","iopub.execute_input":"2023-03-11T10:04:48.489732Z","iopub.status.idle":"2023-03-11T10:04:48.496407Z","shell.execute_reply.started":"2023-03-11T10:04:48.489697Z","shell.execute_reply":"2023-03-11T10:04:48.494903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:04:55.794536Z","iopub.execute_input":"2023-03-11T10:04:55.794991Z","iopub.status.idle":"2023-03-11T10:04:55.800357Z","shell.execute_reply.started":"2023-03-11T10:04:55.794924Z","shell.execute_reply":"2023-03-11T10:04:55.799033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm = confusion_matrix(Y_test, Y_predictions)\ncm","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:05:06.065971Z","iopub.execute_input":"2023-03-11T10:05:06.067433Z","iopub.status.idle":"2023-03-11T10:05:06.078676Z","shell.execute_reply.started":"2023-03-11T10:05:06.067374Z","shell.execute_reply":"2023-03-11T10:05:06.077097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nplt.figure(figsize = (10,7))\nsns.heatmap(cm, annot=True)\nplt.xlabel('Prediction')\nplt.ylabel('Actual')","metadata":{"execution":{"iopub.status.busy":"2023-03-11T10:05:17.769230Z","iopub.execute_input":"2023-03-11T10:05:17.769639Z","iopub.status.idle":"2023-03-11T10:05:18.793866Z","shell.execute_reply.started":"2023-03-11T10:05:17.769604Z","shell.execute_reply":"2023-03-11T10:05:18.792684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}