{"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)\nfrom sklearn.linear_model import Ridge\nfrom sklearn.model_selection import cross_val_score\nfrom sklearn.preprocessing import OneHotEncoder\n\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\nfeatures = '/kaggle/input/feature-shop-for-multimodal-singlecell-competition/citeseq_train_and_test_PCA200.csv'\ndf_features = pd.read_csv(features, sep =',')\n\ntargets = pd.read_hdf('/kaggle/input/open-problems-multimodal/train_cite_targets.h5')\ninputs = pd.read_hdf('/kaggle/input/open-problems-multimodal/train_cite_inputs.h5')\ncell_types = pd.read_csv('/kaggle/input/open-problems-multimodal/metadata.csv')\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":"2022-12-18T12:15:48.451441Z","iopub.execute_input":"2022-12-18T12:15:48.451876Z","iopub.status.idle":"2022-12-18T12:16:50.951988Z","shell.execute_reply.started":"2022-12-18T12:15:48.451843Z","shell.execute_reply":"2022-12-18T12:16:50.950960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transcripts = inputs.columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:50.953611Z","iopub.execute_input":"2022-12-18T12:16:50.954008Z","iopub.status.idle":"2022-12-18T12:16:50.961254Z","shell.execute_reply.started":"2022-12-18T12:16:50.953976Z","shell.execute_reply":"2022-12-18T12:16:50.959992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(transcripts)):\n    if 'CD36' in transcripts[i]:\n        print(transcripts[i])","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:50.962632Z","iopub.execute_input":"2022-12-18T12:16:50.963829Z","iopub.status.idle":"2022-12-18T12:16:50.976130Z","shell.execute_reply.started":"2022-12-18T12:16:50.963786Z","shell.execute_reply":"2022-12-18T12:16:50.974630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cell_types","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:50.979209Z","iopub.execute_input":"2022-12-18T12:16:50.979538Z","iopub.status.idle":"2022-12-18T12:16:51.011079Z","shell.execute_reply.started":"2022-12-18T12:16:50.979510Z","shell.execute_reply":"2022-12-18T12:16:51.009873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targets_cd_36 = targets[['CD36']]\ntargets_cd_36 = targets_cd_36.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.012335Z","iopub.execute_input":"2022-12-18T12:16:51.012700Z","iopub.status.idle":"2022-12-18T12:16:51.021542Z","shell.execute_reply.started":"2022-12-18T12:16:51.012656Z","shell.execute_reply":"2022-12-18T12:16:51.020239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cell_types_common =cell_types.merge(targets_cd_36, on=[\"cell_id\", \"cell_id\"])","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.023135Z","iopub.execute_input":"2022-12-18T12:16:51.023499Z","iopub.status.idle":"2022-12-18T12:16:51.324501Z","shell.execute_reply.started":"2022-12-18T12:16:51.023466Z","shell.execute_reply":"2022-12-18T12:16:51.323262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cell_types_common = cell_types_common.drop(['day', 'donor', 'technology'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.326118Z","iopub.execute_input":"2022-12-18T12:16:51.327973Z","iopub.status.idle":"2022-12-18T12:16:51.341069Z","shell.execute_reply.started":"2022-12-18T12:16:51.327924Z","shell.execute_reply":"2022-12-18T12:16:51.340066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cell_types_common","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.342692Z","iopub.execute_input":"2022-12-18T12:16:51.343835Z","iopub.status.idle":"2022-12-18T12:16:51.360915Z","shell.execute_reply.started":"2022-12-18T12:16:51.343788Z","shell.execute_reply":"2022-12-18T12:16:51.359699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_cells = df_features.merge(targets_cd_36, on=[\"cell_id\", \"cell_id\"])","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.362497Z","iopub.execute_input":"2022-12-18T12:16:51.363597Z","iopub.status.idle":"2022-12-18T12:16:51.563473Z","shell.execute_reply.started":"2022-12-18T12:16:51.363540Z","shell.execute_reply":"2022-12-18T12:16:51.562296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_cells_2 = df_features.merge(cell_types_common, on=[\"cell_id\", \"cell_id\"])","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.568593Z","iopub.execute_input":"2022-12-18T12:16:51.568952Z","iopub.status.idle":"2022-12-18T12:16:51.755254Z","shell.execute_reply.started":"2022-12-18T12:16:51.568922Z","shell.execute_reply":"2022-12-18T12:16:51.753957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_cells_2","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.756753Z","iopub.execute_input":"2022-12-18T12:16:51.757213Z","iopub.status.idle":"2022-12-18T12:16:51.809165Z","shell.execute_reply.started":"2022-12-18T12:16:51.757169Z","shell.execute_reply":"2022-12-18T12:16:51.808088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ohe = OneHotEncoder(sparse = False)\nohe.fit(common_cells_2[['cell_type']])\nohe_data = ohe.transform(common_cells_2[['cell_type']])\ncommon_cells_2[ohe.get_feature_names()]=ohe_data","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.810405Z","iopub.execute_input":"2022-12-18T12:16:51.810754Z","iopub.status.idle":"2022-12-18T12:16:51.854641Z","shell.execute_reply.started":"2022-12-18T12:16:51.810721Z","shell.execute_reply":"2022-12-18T12:16:51.853790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna_cd36 = inputs[['ENSG00000135218_CD36']]","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.855905Z","iopub.execute_input":"2022-12-18T12:16:51.856393Z","iopub.status.idle":"2022-12-18T12:16:51.864720Z","shell.execute_reply.started":"2022-12-18T12:16:51.856362Z","shell.execute_reply":"2022-12-18T12:16:51.863381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna_cd36 = rna_cd36.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.866429Z","iopub.execute_input":"2022-12-18T12:16:51.867189Z","iopub.status.idle":"2022-12-18T12:16:51.878402Z","shell.execute_reply.started":"2022-12-18T12:16:51.867143Z","shell.execute_reply":"2022-12-18T12:16:51.877148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna_cd36","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.880002Z","iopub.execute_input":"2022-12-18T12:16:51.880480Z","iopub.status.idle":"2022-12-18T12:16:51.897282Z","shell.execute_reply.started":"2022-12-18T12:16:51.880431Z","shell.execute_reply":"2022-12-18T12:16:51.896227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_cells_2['ENSG00000135218_CD36']=  rna_cd36['ENSG00000135218_CD36'].tolist()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.899143Z","iopub.execute_input":"2022-12-18T12:16:51.899482Z","iopub.status.idle":"2022-12-18T12:16:51.918377Z","shell.execute_reply.started":"2022-12-18T12:16:51.899453Z","shell.execute_reply":"2022-12-18T12:16:51.917177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_cells","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.920019Z","iopub.execute_input":"2022-12-18T12:16:51.920555Z","iopub.status.idle":"2022-12-18T12:16:51.983279Z","shell.execute_reply.started":"2022-12-18T12:16:51.920496Z","shell.execute_reply":"2022-12-18T12:16:51.982061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_X = common_cells.copy()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:51.984763Z","iopub.execute_input":"2022-12-18T12:16:51.985254Z","iopub.status.idle":"2022-12-18T12:16:52.036022Z","shell.execute_reply.started":"2022-12-18T12:16:51.985210Z","shell.execute_reply":"2022-12-18T12:16:52.034857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_X.pop('cell_id')\ndf_X.pop('CD36')\n","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:52.037515Z","iopub.execute_input":"2022-12-18T12:16:52.037896Z","iopub.status.idle":"2022-12-18T12:16:52.049767Z","shell.execute_reply.started":"2022-12-18T12:16:52.037862Z","shell.execute_reply":"2022-12-18T12:16:52.048556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_X2 = common_cells_2.copy()\ndf_X2.pop('cell_id')\ndf_X2.pop('CD36')\ndf_X2.pop('cell_type')","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:52.051429Z","iopub.execute_input":"2022-12-18T12:16:52.052036Z","iopub.status.idle":"2022-12-18T12:16:52.199956Z","shell.execute_reply.started":"2022-12-18T12:16:52.052000Z","shell.execute_reply":"2022-12-18T12:16:52.198684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df_X\ny = common_cells[['CD36']]","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:52.201502Z","iopub.execute_input":"2022-12-18T12:16:52.202280Z","iopub.status.idle":"2022-12-18T12:16:52.208946Z","shell.execute_reply.started":"2022-12-18T12:16:52.202226Z","shell.execute_reply":"2022-12-18T12:16:52.207546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for alpha in [ 1e2, 1e3,1e4,1e5 ]:\n    model = Ridge(alpha=alpha)\n    s = cross_val_score(model, X, y, cv=4)\n    print(np.mean(s), s)","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:52.210968Z","iopub.execute_input":"2022-12-18T12:16:52.211331Z","iopub.status.idle":"2022-12-18T12:16:56.619178Z","shell.execute_reply.started":"2022-12-18T12:16:52.211299Z","shell.execute_reply":"2022-12-18T12:16:56.615079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df_X2\ny = common_cells_2['CD36'].tolist()","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:56.620945Z","iopub.execute_input":"2022-12-18T12:16:56.621702Z","iopub.status.idle":"2022-12-18T12:16:56.641761Z","shell.execute_reply.started":"2022-12-18T12:16:56.621640Z","shell.execute_reply":"2022-12-18T12:16:56.639760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for alpha in [ 1e2, 1e3,1e4,1e5 ]:\n    model = Ridge(alpha=alpha)\n    s = cross_val_score(model, X, y, cv=4)\n    print(np.mean(s), s)","metadata":{"execution":{"iopub.status.busy":"2022-12-18T12:16:56.648468Z","iopub.execute_input":"2022-12-18T12:16:56.654388Z","iopub.status.idle":"2022-12-18T12:17:01.310538Z","shell.execute_reply.started":"2022-12-18T12:16:56.654309Z","shell.execute_reply":"2022-12-18T12:17:01.308046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}