{"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":84969,"databundleVersionId":10033515,"sourceType":"competition"},{"sourceId":10543412,"sourceType":"datasetVersion","datasetId":6523690},{"sourceId":218673919,"sourceType":"kernelVersion"},{"sourceId":241205,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":206056,"modelId":227804}],"dockerImageVersionId":30839,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"***We will first determine the type of objects required and then call the required scripts.***","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.svm import SVC\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:48.855616Z","iopub.execute_input":"2025-01-24T16:10:48.856090Z","iopub.status.idle":"2025-01-24T16:10:52.482365Z","shell.execute_reply.started":"2025-01-24T16:10:48.856024Z","shell.execute_reply":"2025-01-24T16:10:52.481039Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***then we read the file***","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/czii-cryo-et-object-identification/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.483608Z","iopub.execute_input":"2025-01-24T16:10:52.484346Z","iopub.status.idle":"2025-01-24T16:10:52.504726Z","shell.execute_reply.started":"2025-01-24T16:10:52.484306Z","shell.execute_reply":"2025-01-24T16:10:52.502857Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.506270Z","iopub.execute_input":"2025-01-24T16:10:52.506720Z","iopub.status.idle":"2025-01-24T16:10:52.542359Z","shell.execute_reply.started":"2025-01-24T16:10:52.506678Z","shell.execute_reply":"2025-01-24T16:10:52.540968Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission.tail()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.543570Z","iopub.execute_input":"2025-01-24T16:10:52.544045Z","iopub.status.idle":"2025-01-24T16:10:52.559768Z","shell.execute_reply.started":"2025-01-24T16:10:52.543999Z","shell.execute_reply":"2025-01-24T16:10:52.558224Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***we aslo delete the columns which is not light***","metadata":{}},{"cell_type":"code","source":"sample_new = sample_submission.drop(['id','experiment','x','y','z'],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.561337Z","iopub.execute_input":"2025-01-24T16:10:52.561929Z","iopub.status.idle":"2025-01-24T16:10:52.588485Z","shell.execute_reply.started":"2025-01-24T16:10:52.561890Z","shell.execute_reply":"2025-01-24T16:10:52.586985Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_new.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.592359Z","iopub.execute_input":"2025-01-24T16:10:52.592971Z","iopub.status.idle":"2025-01-24T16:10:52.618874Z","shell.execute_reply.started":"2025-01-24T16:10:52.592915Z","shell.execute_reply":"2025-01-24T16:10:52.617417Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***We know the level of definition of objects such as  Beta-amylase (impossible, not listed)\n\nBeta-galactosidase (difficult)\n\nRibosome (easy)\n\nThyroglobulin (difficult)\n\nVirus-like particle (easy)\n\napo-ferritin(easy)\n\nWe will make the easy level 1, the difficult level 2, and the undefined level 0***","metadata":{}},{"cell_type":"code","source":"Selection_level = []\nfor i in range(len(sample_new)):\n    if sample_new.iloc[i]['particle_type'] == 'beta-amylase':\n        Selection_level.append ('0')\n    elif sample_new.iloc[i]['particle_type'] == 'beta-galactosidase':\n        Selection_level.append ('2')\n    elif sample_new.iloc[i]['particle_type'] == 'ribosome' or sample_new.iloc[i]['particle_type'] == 'apo-ferritin' or sample_new.iloc[i]['particle_type'] == 'virus-like-particle':\n        Selection_level.append ('1')\nsample_new['Selection_level'] = Selection_level\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.620718Z","iopub.execute_input":"2025-01-24T16:10:52.621162Z","iopub.status.idle":"2025-01-24T16:10:52.643541Z","shell.execute_reply.started":"2025-01-24T16:10:52.621116Z","shell.execute_reply":"2025-01-24T16:10:52.642289Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_new.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.644819Z","iopub.execute_input":"2025-01-24T16:10:52.645294Z","iopub.status.idle":"2025-01-24T16:10:52.670401Z","shell.execute_reply.started":"2025-01-24T16:10:52.645247Z","shell.execute_reply":"2025-01-24T16:10:52.669403Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.countplot(x='particle_type', data=sample_new)\nplt.xticks(rotation=45)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:13:33.875207Z","iopub.execute_input":"2025-01-24T16:13:33.875772Z","iopub.status.idle":"2025-01-24T16:13:34.110271Z","shell.execute_reply.started":"2025-01-24T16:13:33.875722Z","shell.execute_reply":"2025-01-24T16:13:34.108948Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"selection= pd.get_dummies(sample_new, prefix=['particle_type'], columns=['particle_type'])\nx = selection.drop(['Selection_level'], axis=1)\ny = selection['Selection_level']\ny = y.astype('int')\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:52.998244Z","iopub.execute_input":"2025-01-24T16:10:52.998620Z","iopub.status.idle":"2025-01-24T16:10:53.016508Z","shell.execute_reply.started":"2025-01-24T16:10:52.998580Z","shell.execute_reply":"2025-01-24T16:10:53.014438Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"selection.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:53.018225Z","iopub.execute_input":"2025-01-24T16:10:53.018684Z","iopub.status.idle":"2025-01-24T16:10:53.033869Z","shell.execute_reply.started":"2025-01-24T16:10:53.018627Z","shell.execute_reply":"2025-01-24T16:10:53.032728Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***Finally, we build a model using two libraries, LogisticRegression and , SVC and determine the level of Training and test in both libraries***","metadata":{}},{"cell_type":"code","source":"logreg = LogisticRegression()\nlogreg.fit(x_train, y_train)\n\nscore = logreg.score(x_train, y_train)\nscore2 = logreg.score(x_test, y_test)\nprint(\"Training set accuracy\",'%.3f'%(score))\nprint(\"Test set accuracy\",'%.3f'%(score2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:53.035004Z","iopub.execute_input":"2025-01-24T16:10:53.035386Z","iopub.status.idle":"2025-01-24T16:10:53.073629Z","shell.execute_reply.started":"2025-01-24T16:10:53.035351Z","shell.execute_reply":"2025-01-24T16:10:53.072352Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"logreg2 = SVC()  \nlogreg2.fit(x_train, y_train) \n\nscore = logreg2.score(x_train, y_train)\nscore2 = logreg2.score(x_test, y_test)\nprint(\"Training set accuracy\",'%.3f'%(score))\nprint(\"Test set accuracy\",'%.3f'%(score2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-24T16:10:53.074585Z","iopub.execute_input":"2025-01-24T16:10:53.075002Z","iopub.status.idle":"2025-01-24T16:10:53.093075Z","shell.execute_reply.started":"2025-01-24T16:10:53.074964Z","shell.execute_reply":"2025-01-24T16:10:53.091934Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***Thanke***","metadata":{}}]}