{"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":3649,"databundleVersionId":46718,"sourceType":"competition"},{"sourceId":1003830,"sourceType":"datasetVersion","datasetId":550917},{"sourceId":1455620,"sourceType":"datasetVersion","datasetId":853363},{"sourceId":6638020,"sourceType":"datasetVersion","datasetId":3832160}],"dockerImageVersionId":30559,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pickle\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score\nfrom sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n\nwith open('/kaggle/input/dataaa/data_batch_1', \"rb\") as batch_1:\n     dataset = pickle.load(batch_1, encoding='bytes')\n        \nX = dataset[b'data']\ny = dataset[b'labels']\nX1=[];y1=[]\nfor i in range (len(y)):\n    if y[i]==3 or y[i]==5:\n        X1.append(X[i])\n        y1.append(y[i])\nX_train, X_test, y_train, y_test = train_test_split(X1, y1, test_size=0.3, random_state=42)\n\n","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:34.243878Z","iopub.execute_input":"2024-08-06T09:24:34.244859Z","iopub.status.idle":"2024-08-06T09:24:36.249411Z","shell.execute_reply.started":"2024-08-06T09:24:34.244810Z","shell.execute_reply":"2024-08-06T09:24:36.248144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=LogisticRegression()\nmodel.fit(X_train,y_train)\n","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:36.251472Z","iopub.execute_input":"2024-08-06T09:24:36.252056Z","iopub.status.idle":"2024-08-06T09:24:36.999727Z","shell.execute_reply.started":"2024-08-06T09:24:36.252013Z","shell.execute_reply":"2024-08-06T09:24:36.998530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=model.predict(X_test)\naccuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:37.001371Z","iopub.execute_input":"2024-08-06T09:24:37.003227Z","iopub.status.idle":"2024-08-06T09:24:37.045703Z","shell.execute_reply.started":"2024-08-06T09:24:37.003181Z","shell.execute_reply":"2024-08-06T09:24:37.042983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"param_grid = {\n    \"penalty\": ['l1', None],\n    \"solver\" : [ 'newton-cg', 'saga'],\n    \"multi_class\":['ovr', 'multinomial'],\n    \"max_iter\" : [200,300]  }\n","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:37.049194Z","iopub.execute_input":"2024-08-06T09:24:37.049687Z","iopub.status.idle":"2024-08-06T09:24:37.061172Z","shell.execute_reply.started":"2024-08-06T09:24:37.049647Z","shell.execute_reply":"2024-08-06T09:24:37.060166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_search = GridSearchCV(\n    estimator=model, \n    param_grid=param_grid, \n    cv=2, \n    scoring='accuracy', \n    n_jobs=-1, \n    verbose=10\n)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:37.062720Z","iopub.execute_input":"2024-08-06T09:24:37.063219Z","iopub.status.idle":"2024-08-06T09:24:37.075786Z","shell.execute_reply.started":"2024-08-06T09:24:37.063181Z","shell.execute_reply":"2024-08-06T09:24:37.074646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_search.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:24:37.077416Z","iopub.execute_input":"2024-08-06T09:24:37.078118Z","iopub.status.idle":"2024-08-06T09:26:30.475833Z","shell.execute_reply.started":"2024-08-06T09:24:37.078078Z","shell.execute_reply":"2024-08-06T09:26:30.474741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_search.cv_results_","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:30.477416Z","iopub.execute_input":"2024-08-06T09:26:30.477745Z","iopub.status.idle":"2024-08-06T09:26:30.491094Z","shell.execute_reply.started":"2024-08-06T09:26:30.477712Z","shell.execute_reply":"2024-08-06T09:26:30.489827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid_search.best_params_","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:30.492388Z","iopub.execute_input":"2024-08-06T09:26:30.492730Z","iopub.status.idle":"2024-08-06T09:26:30.504817Z","shell.execute_reply.started":"2024-08-06T09:26:30.492701Z","shell.execute_reply":"2024-08-06T09:26:30.503900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_model = grid_search.best_estimator_\nbest_model.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:30.506229Z","iopub.execute_input":"2024-08-06T09:26:30.506569Z","iopub.status.idle":"2024-08-06T09:26:51.071183Z","shell.execute_reply.started":"2024-08-06T09:26:30.506540Z","shell.execute_reply":"2024-08-06T09:26:51.070101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = best_model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:51.073833Z","iopub.execute_input":"2024-08-06T09:26:51.074192Z","iopub.status.idle":"2024-08-06T09:26:51.085578Z","shell.execute_reply.started":"2024-08-06T09:26:51.074157Z","shell.execute_reply":"2024-08-06T09:26:51.084317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:51.087305Z","iopub.execute_input":"2024-08-06T09:26:51.088262Z","iopub.status.idle":"2024-08-06T09:26:51.098177Z","shell.execute_reply.started":"2024-08-06T09:26:51.088213Z","shell.execute_reply":"2024-08-06T09:26:51.096876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"precision_score(y_test, y_pred, average=\"weighted\")","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:51.100187Z","iopub.execute_input":"2024-08-06T09:26:51.101088Z","iopub.status.idle":"2024-08-06T09:26:51.112207Z","shell.execute_reply.started":"2024-08-06T09:26:51.101050Z","shell.execute_reply":"2024-08-06T09:26:51.111157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall_score(y_test, y_pred, average=\"weighted\")","metadata":{"execution":{"iopub.status.busy":"2024-08-06T09:26:51.114218Z","iopub.execute_input":"2024-08-06T09:26:51.115163Z","iopub.status.idle":"2024-08-06T09:26:51.127602Z","shell.execute_reply.started":"2024-08-06T09:26:51.115124Z","shell.execute_reply":"2024-08-06T09:26:51.126138Z"},"trusted":true},"execution_count":null,"outputs":[]}]}