{"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"}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-22T02:15:18.828301Z","iopub.status.idle":"2024-02-22T02:15:18.828727Z","shell.execute_reply.started":"2024-02-22T02:15:18.828508Z","shell.execute_reply":"2024-02-22T02:15:18.828525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def gini_stability(gini_in_time, w_fallingrate=88.0, w_resstd=-0.5):\n    x = np.arange(len(gini_in_time))\n    y = gini_in_time\n    a, b = np.polyfit(x, y, 1)\n    y_hat = a*x + b\n    residuals = y - y_hat\n    res_std = np.std(residuals)\n    avg_gini = np.mean(gini_in_time)\n    return avg_gini + w_fallingrate * min(0, a) + w_resstd * res_std","metadata":{"execution":{"iopub.status.busy":"2024-02-22T02:15:18.829838Z","iopub.status.idle":"2024-02-22T02:15:18.830257Z","shell.execute_reply.started":"2024-02-22T02:15:18.830031Z","shell.execute_reply":"2024-02-22T02:15:18.830048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_model = np.arange(0.95, 0.5, -0.0045)\nbest_model","metadata":{"execution":{"iopub.status.busy":"2024-02-22T02:15:18.831804Z","iopub.status.idle":"2024-02-22T02:15:18.832233Z","shell.execute_reply.started":"2024-02-22T02:15:18.832000Z","shell.execute_reply":"2024-02-22T02:15:18.832018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"poor_model = np.arange(0.90, 0.5, -0.004)\npoor_model","metadata":{"execution":{"iopub.status.busy":"2024-02-22T02:15:18.833397Z","iopub.status.idle":"2024-02-22T02:15:18.833749Z","shell.execute_reply.started":"2024-02-22T02:15:18.833572Z","shell.execute_reply":"2024-02-22T02:15:18.833584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fixed_model = np.arange(0.90, 0.899, -0.00001)\nfixed_model","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gini_stability(best_model)","metadata":{"execution":{"iopub.status.busy":"2024-02-22T02:15:18.834412Z","iopub.status.idle":"2024-02-22T02:15:18.834777Z","shell.execute_reply.started":"2024-02-22T02:15:18.834570Z","shell.execute_reply":"2024-02-22T02:15:18.834585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gini_stability(poor_model)","metadata":{"execution":{"iopub.status.busy":"2024-02-22T02:15:18.836569Z","iopub.status.idle":"2024-02-22T02:15:18.837059Z","shell.execute_reply.started":"2024-02-22T02:15:18.836796Z","shell.execute_reply":"2024-02-22T02:15:18.836856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gini_stability(fixed_model)","metadata":{},"execution_count":null,"outputs":[]}]}