{"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!pip install sklego\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-08-01T01:24:02.783585Z","iopub.execute_input":"2022-08-01T01:24:02.784013Z","iopub.status.idle":"2022-08-01T01:24:19.162330Z","shell.execute_reply.started":"2022-08-01T01:24:02.783978Z","shell.execute_reply":"2022-08-01T01:24:19.160974Z"},"jupyter":{"source_hidden":true,"outputs_hidden":true},"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('../input/tabular-playground-series-jul-2022/data.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T01:10:10.872348Z","iopub.execute_input":"2022-08-01T01:10:10.873376Z","iopub.status.idle":"2022-08-01T01:10:12.256730Z","shell.execute_reply.started":"2022-08-01T01:10:10.873324Z","shell.execute_reply":"2022-08-01T01:10:12.255502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy import stats\ncols_select = []\nalpha = 0.05\n\nfor col in data:\n    _, p_value = stats.shapiro(data[col])\n    \n    if (p_value <= alpha): \n        cols_select.append(col)       \ndata = data[cols_select]","metadata":{"execution":{"iopub.status.busy":"2022-08-01T01:12:26.063527Z","iopub.execute_input":"2022-08-01T01:12:26.064585Z","iopub.status.idle":"2022-08-01T01:12:26.208839Z","shell.execute_reply.started":"2022-08-01T01:12:26.064540Z","shell.execute_reply":"2022-08-01T01:12:26.207558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import PowerTransformer\ndata = PowerTransformer().fit_transform(data)\ndata = pd.DataFrame(data, columns=cols_select)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T01:14:01.129625Z","iopub.execute_input":"2022-08-01T01:14:01.130068Z","iopub.status.idle":"2022-08-01T01:14:03.078474Z","shell.execute_reply.started":"2022-08-01T01:14:01.130020Z","shell.execute_reply":"2022-08-01T01:14:03.077358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.mixture import BayesianGaussianMixture\ncls_gaussian= BayesianGaussianMixture(n_components=7,tol=0.001,init_params='kmeans',n_init=5)\npredict1 = cls_gaussian.fit_predict(data)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T01:19:05.786485Z","iopub.execute_input":"2022-08-01T01:19:05.786907Z","iopub.status.idle":"2022-08-01T01:23:16.580418Z","shell.execute_reply.started":"2022-08-01T01:19:05.786872Z","shell.execute_reply":"2022-08-01T01:23:16.578861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklego.mixture import BayesianGMMClassifier\nbgmmC = BayesianGMMClassifier(n_components=7,covariance_type = 'full',max_iter = 300,n_init=3)\nbgmmC.fit(data,predict1)\npredict2 = bgmmC.predict(data)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T01:26:20.481346Z","iopub.execute_input":"2022-08-01T01:26:20.482567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('../input/tabular-playground-series-jul-2022/sample_submission.csv')\nsubmission['Predicted'] = predict2\nsubmission.to_csv('submission.csv',index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}