{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":50160,"databundleVersionId":7602123,"sourceType":"competition"},{"sourceId":38613,"sourceType":"datasetVersion","datasetId":30292},{"sourceId":508365,"sourceType":"datasetVersion","datasetId":239789},{"sourceId":2179861,"sourceType":"datasetVersion","datasetId":423609},{"sourceId":3228623,"sourceType":"datasetVersion","datasetId":1957837},{"sourceId":6394510,"sourceType":"datasetVersion","datasetId":3686276},{"sourceId":6425759,"sourceType":"datasetVersion","datasetId":3707219},{"sourceId":7384155,"sourceType":"datasetVersion","datasetId":4291772},{"sourceId":7447257,"sourceType":"datasetVersion","datasetId":4334838},{"sourceId":7551506,"sourceType":"datasetVersion","datasetId":4398266},{"sourceId":7611756,"sourceType":"datasetVersion","datasetId":4432392}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"%matplotlib inline\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport sklearn\nfrom sklearn.model_selection import train_test_split\nimport imblearn\nfrom sklearn import metrics","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:33:15.933802Z","iopub.execute_input":"2024-02-12T13:33:15.934472Z","iopub.status.idle":"2024-02-12T13:33:15.945277Z","shell.execute_reply.started":"2024-02-12T13:33:15.934439Z","shell.execute_reply":"2024-02-12T13:33:15.943189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **DATASET LOADING & PREPROCESSING**","metadata":{}},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/ml-sle/generated_dataset.csv\")\ndata = data.sample(n=100000, random_state=42)\ndata.dropna(inplace=True)\ndata.drop('A_id', axis=1,inplace=True)\ndata.shape","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:34:52.095508Z","iopub.execute_input":"2024-02-12T13:34:52.095969Z","iopub.status.idle":"2024-02-12T13:34:52.623219Z","shell.execute_reply.started":"2024-02-12T13:34:52.095937Z","shell.execute_reply":"2024-02-12T13:34:52.621927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:34:55.891792Z","iopub.execute_input":"2024-02-12T13:34:55.892186Z","iopub.status.idle":"2024-02-12T13:34:55.932035Z","shell.execute_reply.started":"2024-02-12T13:34:55.892157Z","shell.execute_reply":"2024-02-12T13:34:55.930413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:35:00.70926Z","iopub.execute_input":"2024-02-12T13:35:00.70964Z","iopub.status.idle":"2024-02-12T13:35:00.804343Z","shell.execute_reply.started":"2024-02-12T13:35:00.709611Z","shell.execute_reply":"2024-02-12T13:35:00.803048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:35:02.036528Z","iopub.execute_input":"2024-02-12T13:35:02.03792Z","iopub.status.idle":"2024-02-12T13:35:02.062Z","shell.execute_reply.started":"2024-02-12T13:35:02.037873Z","shell.execute_reply":"2024-02-12T13:35:02.060664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:35:03.676084Z","iopub.execute_input":"2024-02-12T13:35:03.677176Z","iopub.status.idle":"2024-02-12T13:35:03.762467Z","shell.execute_reply.started":"2024-02-12T13:35:03.677127Z","shell.execute_reply":"2024-02-12T13:35:03.761066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Quality']=data['Quality'].map({'good':1,'bad':0})","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:35:06.159425Z","iopub.execute_input":"2024-02-12T13:35:06.160421Z","iopub.status.idle":"2024-02-12T13:35:06.180738Z","shell.execute_reply.started":"2024-02-12T13:35:06.160382Z","shell.execute_reply":"2024-02-12T13:35:06.179175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **DATASET VISUALIZATION**","metadata":{}},{"cell_type":"code","source":"data.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:35:07.893751Z","iopub.execute_input":"2024-02-12T13:35:07.894221Z","iopub.status.idle":"2024-02-12T13:35:07.917489Z","shell.execute_reply.started":"2024-02-12T13:35:07.894187Z","shell.execute_reply":"2024-02-12T13:35:07.916009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Acidity']=data['Acidity'].astype('float')","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:04:57.427135Z","iopub.execute_input":"2024-02-12T13:04:57.42743Z","iopub.status.idle":"2024-02-12T13:04:57.432138Z","shell.execute_reply.started":"2024-02-12T13:04:57.427408Z","shell.execute_reply":"2024-02-12T13:04:57.431555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=data.drop('Quality',axis=1)\ny=data['Quality']\nx_train, x_test, y_train, y_test=train_test_split(x,y, test_size=0.25, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:05:34.084481Z","iopub.execute_input":"2024-02-12T13:05:34.084776Z","iopub.status.idle":"2024-02-12T13:05:34.091244Z","shell.execute_reply.started":"2024-02-12T13:05:34.084755Z","shell.execute_reply":"2024-02-12T13:05:34.090391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import GridSearchCV\n\nclf_svc=SVC()\nparametres_svc={'C': [5.0,6.0,7.0,8.0]}\ngrid_svc=GridSearchCV(clf_svc,parametres_svc, cv=6, n_jobs=-1)\ngrid_svc.fit(x_train,y_train)\nprint(grid_svc.best_params_)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:06:13.38387Z","iopub.execute_input":"2024-02-12T13:06:13.384156Z","iopub.status.idle":"2024-02-12T13:06:15.606733Z","shell.execute_reply.started":"2024-02-12T13:06:13.384136Z","shell.execute_reply":"2024-02-12T13:06:15.605991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_svc=grid_svc.best_estimator_.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:08:20.215694Z","iopub.execute_input":"2024-02-12T13:08:20.215981Z","iopub.status.idle":"2024-02-12T13:08:20.252335Z","shell.execute_reply.started":"2024-02-12T13:08:20.21596Z","shell.execute_reply":"2024-02-12T13:08:20.25176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(metrics.accuracy_score(y_test,y_pred_svc))","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:08:21.589158Z","iopub.execute_input":"2024-02-12T13:08:21.589627Z","iopub.status.idle":"2024-02-12T13:08:21.594937Z","shell.execute_reply.started":"2024-02-12T13:08:21.589599Z","shell.execute_reply":"2024-02-12T13:08:21.594093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm = metrics.confusion_matrix(y_test, y_pred_svc,normalize='true')\nprint(cm)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:08:29.299308Z","iopub.execute_input":"2024-02-12T13:08:29.299837Z","iopub.status.idle":"2024-02-12T13:08:29.306439Z","shell.execute_reply.started":"2024-02-12T13:08:29.29981Z","shell.execute_reply":"2024-02-12T13:08:29.305803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Logistic Regression**","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\n\nLGR_Classifier = LogisticRegression(n_jobs=-1, random_state=0)\nLGR_Classifier.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:09:02.029407Z","iopub.execute_input":"2024-02-12T13:09:02.02977Z","iopub.status.idle":"2024-02-12T13:09:02.049715Z","shell.execute_reply.started":"2024-02-12T13:09:02.029749Z","shell.execute_reply":"2024-02-12T13:09:02.04909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import metrics\n# accuracy\n# confusion matrix\n\ny_pred_svc=grid_svc.best_estimator_.predict(x_test)\n\n# accuracy\naccuracy = metrics.accuracy_score(y_test, predictions)\nprint (\"Model Accuracy:\" \"\\n\", accuracy)\n\n# confusion matrix\nconfusion_matrix = metrics.confusion_matrix(y_test, predictions)\nprint(\"Confusion matrix:\" \"\\n\", confusion_matrix)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:10:37.677133Z","iopub.execute_input":"2024-02-12T13:10:37.677459Z","iopub.status.idle":"2024-02-12T13:10:37.718668Z","shell.execute_reply.started":"2024-02-12T13:10:37.677435Z","shell.execute_reply":"2024-02-12T13:10:37.717947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Decision Tree**","metadata":{}},{"cell_type":"code","source":"# DECISION TREE CLASSIFIER\nfrom sklearn.tree import DecisionTreeClassifier\n\ndeccision_classifier = DecisionTreeClassifier()\ndeccision_classifier.fit(x_train,y_train)\n","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:10:55.193593Z","iopub.execute_input":"2024-02-12T13:10:55.193911Z","iopub.status.idle":"2024-02-12T13:10:55.222276Z","shell.execute_reply.started":"2024-02-12T13:10:55.19389Z","shell.execute_reply":"2024-02-12T13:10:55.221456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# accuracy\n# confusion matrix\npredictions = deccision_classifier.predict(x_test)\naccuracy = metrics.accuracy_score(y_test, predictions)\nconfusion_matrix = metrics.confusion_matrix(y_test,predictions)\n\nprint (\"Decision Classifier Model Accuracy:\" \"\\n\", accuracy)\nprint(\"Decision Classifier Model Confusion matrix:\" \"\\n\", confusion_matrix)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T13:10:58.96467Z","iopub.execute_input":"2024-02-12T13:10:58.965041Z","iopub.status.idle":"2024-02-12T13:10:58.974866Z","shell.execute_reply.started":"2024-02-12T13:10:58.965012Z","shell.execute_reply":"2024-02-12T13:10:58.974308Z"},"trusted":true},"execution_count":null,"outputs":[]}]}