{"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\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":"2023-05-29T11:09:24.739967Z","iopub.execute_input":"2023-05-29T11:09:24.74135Z","iopub.status.idle":"2023-05-29T11:09:24.859889Z","shell.execute_reply.started":"2023-05-29T11:09:24.741295Z","shell.execute_reply":"2023-05-29T11:09:24.858502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\nnum_records = 40428967\nsample_size = 8000000\nskip_values = sorted(random.sample(range(1,num_records), num_records - sample_size))","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:09:24.862302Z","iopub.execute_input":"2023-05-29T11:09:24.863232Z","iopub.status.idle":"2023-05-29T11:11:13.269313Z","shell.execute_reply.started":"2023-05-29T11:09:24.863181Z","shell.execute_reply":"2023-05-29T11:11:13.267341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clicks = pd.read_csv(\"../input/avazu-ctr-prediction/train.gz\", skiprows=skip_values)\nclicks.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:11:13.271832Z","iopub.execute_input":"2023-05-29T11:11:13.272312Z","iopub.status.idle":"2023-05-29T11:13:56.201194Z","shell.execute_reply.started":"2023-05-29T11:11:13.272272Z","shell.execute_reply":"2023-05-29T11:13:56.199448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = list(clicks.columns)\na, b = cols.index('click'), cols.index('id')\ncols[b], cols[a] = cols[a], cols[b]\nclicks = clicks[cols]\nclicks.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:13:56.205361Z","iopub.execute_input":"2023-05-29T11:13:56.206297Z","iopub.status.idle":"2023-05-29T11:13:58.051854Z","shell.execute_reply.started":"2023-05-29T11:13:56.206235Z","shell.execute_reply":"2023-05-29T11:13:58.050656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clicks['id'] = clicks['id'].astype('uint64')\nD = 2 ** 30\ni = 'click'\nclicks[i] = clicks[i].astype('uint8')\nfor i in clicks.columns[2:]:\n    print(i)\n    clicks[i] = clicks[i].apply(lambda x: hash(f'{i}={x}') % D).astype('uint32')","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:13:58.108339Z","iopub.execute_input":"2023-05-29T11:13:58.108824Z","iopub.status.idle":"2023-05-29T11:18:29.166422Z","shell.execute_reply.started":"2023-05-29T11:13:58.108786Z","shell.execute_reply":"2023-05-29T11:18:29.164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# clicks.to_csv(f'clicks5kk.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:18:29.169815Z","iopub.execute_input":"2023-05-29T11:18:29.170546Z","iopub.status.idle":"2023-05-29T11:18:29.179305Z","shell.execute_reply.started":"2023-05-29T11:18:29.170461Z","shell.execute_reply":"2023-05-29T11:18:29.177481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx = clicks.iloc[:, 1:]\ny = clicks.iloc[:, 0]\n\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)\ny_train = y_train.to_frame()\ny_test = y_test.to_frame()","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:18:29.181941Z","iopub.execute_input":"2023-05-29T11:18:29.182593Z","iopub.status.idle":"2023-05-29T11:18:45.912218Z","shell.execute_reply.started":"2023-05-29T11:18:29.182537Z","shell.execute_reply":"2023-05-29T11:18:45.91054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import math\nD = 2 ** 20\ncols = clicks.columns[2:]\ny_train['ver'] = [0 for i in range(len(y_train))]\n\nalfa = 0.01\nw = [0 for _ in range(D)]\nn = [0 for _ in range(D)]\n","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:18:45.913886Z","iopub.execute_input":"2023-05-29T11:18:45.914277Z","iopub.status.idle":"2023-05-29T11:18:49.867173Z","shell.execute_reply.started":"2023-05-29T11:18:45.914245Z","shell.execute_reply":"2023-05-29T11:18:49.865716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def training(): \n    z = 0\n    for unit in x_train.index:\n        if z%50000==0:\n            print(z)\n        z+=1\n        s = 0\n        for i in cols:\n            fi = x_train[i][unit] % D + 1\n            s = s + w[fi %  D]\n        y_train['ver'][unit] = 1 / (1 + math.e ** s)\n        for i in cols:\n            fi = x_train[i][unit] % D\n            w[fi] = w[fi] - alfa * (y_train['ver'][unit] - y_train['click'][unit]) / ((n[fi] + 1) ** 0.5)\n            n[fi] = n[fi] + 1\n    print(\"Gotovo\")","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:19:06.820798Z","iopub.execute_input":"2023-05-29T11:19:06.821373Z","iopub.status.idle":"2023-05-29T11:19:06.831781Z","shell.execute_reply.started":"2023-05-29T11:19:06.821325Z","shell.execute_reply":"2023-05-29T11:19:06.830634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def testing():\n    z = 0\n    y_test['ver'] = [0 for i in range(len(y_test))]\n    for unit in x_test.index:\n        if z%50000==0:\n            print(z)\n        z+=1\n        s = 0\n        for i in cols:\n            fi = x_test[i][unit]\n            s = s + w[(fi + 1)%D]\n        y_test['ver'][unit] = 1 / (1 + math.e ** s)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:19:07.607158Z","iopub.execute_input":"2023-05-29T11:19:07.609355Z","iopub.status.idle":"2023-05-29T11:19:07.622911Z","shell.execute_reply.started":"2023-05-29T11:19:07.609285Z","shell.execute_reply":"2023-05-29T11:19:07.621482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ndef train_test():\n    training()\n    testing()\n    res = y_test\n    print(f\"{min(res['ver'])} +{sum(res['ver'])/len(res['ver'])}+ {max(res['ver'])}\")\n#     ver_col = res['ver']\n#     ver_col.plot(kind=\"hist\")","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:19:08.812697Z","iopub.execute_input":"2023-05-29T11:19:08.813817Z","iopub.status.idle":"2023-05-29T11:19:08.821349Z","shell.execute_reply.started":"2023-05-29T11:19:08.813763Z","shell.execute_reply":"2023-05-29T11:19:08.819938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_test()","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:40:07.510617Z","iopub.execute_input":"2023-05-29T14:40:07.511112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n\n\n\n\n\n0.45875255535766934 +0.5725991460053196+ 0.9999999905002032\nver_col = y_test['ver']\nver_col.plot(kind=\"hist\")\n","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:29:12.764979Z","iopub.execute_input":"2023-05-29T14:29:12.76952Z","iopub.status.idle":"2023-05-29T14:29:13.663321Z","shell.execute_reply.started":"2023-05-29T14:29:12.769334Z","shell.execute_reply":"2023-05-29T14:29:13.661859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pickle\nresult_out = 8\nresult_D = 20\nresult_alfa = 1\nwith open(f\"w{result_out}_{result_D}_{result_alfa}kaggele1\", \"wb\") as fp:   #Pickling\n    pickle.dump(w, fp)\nwith open(f\"n{result_out}_{result_D}_{result_alfa}kaggele1\", \"wb\") as fp:   #Pickling\n    pickle.dump(n, fp)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:31:21.594527Z","iopub.execute_input":"2023-05-29T14:31:21.595769Z","iopub.status.idle":"2023-05-29T14:31:29.193194Z","shell.execute_reply.started":"2023-05-29T14:31:21.595686Z","shell.execute_reply":"2023-05-29T14:31:29.191338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2023-05-29T11:18:50.292757Z","iopub.status.idle":"2023-05-29T11:18:50.293267Z","shell.execute_reply.started":"2023-05-29T11:18:50.293033Z","shell.execute_reply":"2023-05-29T11:18:50.293054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def logloss_crutch(y_true, y_pred, eps=1e-15):\n    return - (y_true * np.log(y_pred) + (1 - y_true) * np.log(1 - y_pred))\ndef analysis(res):\n    real_click = (res['click'].sum() / res.count())[0]\n    ver = 0.575\n    true_click = (res[(res['click'] == 1) & (res['ver'] > ver)].count() / res.count())[0]\n    false_click = (res[(res['click'] == 0) & (res['ver'] > ver)].count() / res.count())[0]\n    true_not_click = (res[(res['click'] == 0) & (res['ver'] < ver)].count() / res.count())[0]\n    pred_click = true_click + true_not_click\n    print(f'real: {real_click}')\n    print(f'ver: {ver}')\n    print(f'true_click: {true_click}')\n    print(f'false_click: {false_click}')\n    print(f'true_not_click: {true_not_click}')\n    print(f'---')\n    print(f'pred_click: {pred_click }')\n    print\n    print('Logloss: %f' % logloss_crutch(real_click, true_click))","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:39:12.270907Z","iopub.execute_input":"2023-05-29T14:39:12.271385Z","iopub.status.idle":"2023-05-29T14:39:12.283244Z","shell.execute_reply.started":"2023-05-29T14:39:12.271347Z","shell.execute_reply":"2023-05-29T14:39:12.281874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"analysis(y_test)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:39:12.760939Z","iopub.execute_input":"2023-05-29T14:39:12.761431Z","iopub.status.idle":"2023-05-29T14:39:12.871104Z","shell.execute_reply.started":"2023-05-29T14:39:12.761395Z","shell.execute_reply":"2023-05-29T14:39:12.869643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def checking(res):\n    for i in range(500, 601):\n        ver = i /1000.\n        true_click = (res[(res['click'] == 1) & (res['ver'] > ver)].count() / res.count())[0]\n        false_click = (res[(res['click'] == 0) & (res['ver'] > ver)].count() / res.count())[0]\n        true_not_click = (res[(res['click'] == 0) & (res['ver'] < ver)].count() / res.count())[0]\n        print(f'{i}: = {true_click + false_click}')","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:38:58.596842Z","iopub.execute_input":"2023-05-29T14:38:58.597385Z","iopub.status.idle":"2023-05-29T14:38:58.607793Z","shell.execute_reply.started":"2023-05-29T14:38:58.597346Z","shell.execute_reply":"2023-05-29T14:38:58.606214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checking(y_test)","metadata":{"execution":{"iopub.status.busy":"2023-05-29T14:39:00.591265Z","iopub.execute_input":"2023-05-29T14:39:00.591782Z","iopub.status.idle":"2023-05-29T14:39:09.460543Z","shell.execute_reply.started":"2023-05-29T14:39:00.591744Z","shell.execute_reply":"2023-05-29T14:39:09.457079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res = clicks.sample(n=1000000)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T08:51:45.957378Z","iopub.execute_input":"2023-05-23T08:51:45.95872Z","iopub.status.idle":"2023-05-23T08:51:48.006919Z","shell.execute_reply.started":"2023-05-23T08:51:45.958668Z","shell.execute_reply":"2023-05-23T08:51:48.005327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"z = 0\nres['click'] = [0 for i in range(len(res))]\nfor unit in res.index:\n    if z%50000==0:\n        print(z)\n    z+=1\n    s = 0\n    for i in cols:\n        fi = res[i][unit]\n        s = s + w[(fi + 1)%D]\n    res['click'][unit] = 1 / (1 + math.e ** s)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T08:52:06.467332Z","iopub.execute_input":"2023-05-23T08:52:06.467878Z","iopub.status.idle":"2023-05-23T08:56:30.387272Z","shell.execute_reply.started":"2023-05-23T08:52:06.46784Z","shell.execute_reply":"2023-05-23T08:56:30.385981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res['click'] = clicks['click']","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:04:22.992315Z","iopub.execute_input":"2023-05-23T09:04:22.992699Z","iopub.status.idle":"2023-05-23T09:04:23.033798Z","shell.execute_reply.started":"2023-05-23T09:04:22.992668Z","shell.execute_reply":"2023-05-23T09:04:23.03283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:04:26.815702Z","iopub.execute_input":"2023-05-23T09:04:26.816091Z","iopub.status.idle":"2023-05-23T09:04:27.186495Z","shell.execute_reply.started":"2023-05-23T09:04:26.81606Z","shell.execute_reply":"2023-05-23T09:04:27.18544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2023-05-23T08:45:09.872249Z","iopub.execute_input":"2023-05-23T08:45:09.872816Z","iopub.status.idle":"2023-05-23T08:45:09.893231Z","shell.execute_reply.started":"2023-05-23T08:45:09.87276Z","shell.execute_reply":"2023-05-23T08:45:09.89068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checking(y_test)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T08:41:48.624409Z","iopub.execute_input":"2023-05-23T08:41:48.625386Z","iopub.status.idle":"2023-05-23T08:42:01.36132Z","shell.execute_reply.started":"2023-05-23T08:41:48.625348Z","shell.execute_reply":"2023-05-23T08:42:01.359468Z"},"jupyter":{"source_hidden":true,"outputs_hidden":true},"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\n\ndef gen_bindary(length):\n    return ''.join(random.choice(['0', '1']) for _ in range(length))\n\n\nclass GenAlgorithm:\n    T = 2000\n\n    def __init__(self, dataset, cols, click_count_predictor):\n        self.dataset = dataset\n        self.cols = cols\n        self.click_count_predictor = click_count_predictor\n        self.fitness_result = {}\n\n    def random_els(self, subset):\n        return subset.sample(n=self.T)\n\n    def select_individuals(self, population):\n        p_len = len(population)\n\n        offspring = []\n        for n in range(p_len):\n            i1 = i2 = i3 = 0\n            while i1 == i2 or i1 == i3 or i2 == i3:\n                i1, i2, i3 = random.randint(0, p_len - 1), random.randint(0, p_len - 1), random.randint(0, p_len - 1)\n            offspring.append(\n                max([population[i1], population[i2], population[i3]], key=lambda ind: self.fitness_result[ind]))\n\n        return offspring\n\n    def split_ch(self, individ):\n        return individ[:len(self.cols)], individ[len(self.cols):]\n\n    def get_need_cols(self, ch1):\n        need_cols = []\n        for i in range(len(ch1)):\n            if ch1[i] == '1':\n                need_cols.append(self.cols[i])\n        return need_cols\n\n    def get_sampl(self, ch2):\n        index = int(ch2, 2) % len(self.dataset)\n        id_sampl = self.dataset.at[index, 'id']\n        return self.dataset[self.dataset['id'] == id_sampl]\n\n    def generate_subset(self, sampl, cols):\n        res = self.dataset\n        for c in cols:\n            t = sampl[c].dtypes\n            v = sampl[c].to_string().split()[1]\n            if t == 'int64':\n                v = float(v)\n            res = res[res[c] == v]\n        return res\n\n    def cross(self, individuals, p_c):\n        count = int(len(individuals) * p_c)\n        random.shuffle(individuals)\n        for i in range(count):\n            s = random.randint(2, len(individuals[1]) - 3)\n            ch1 = individuals[i]\n            ch2 = individuals[-i]\n            if ch1 == ch2:\n                continue\n            individuals.remove(ch1)\n            individuals.remove(ch2)\n            individuals.append(ch1[s:] + ch2[:s])\n            individuals.append(ch1[:s] + ch2[s:])\n        return individuals\n\n    def mut(self, individuals, p_m):\n        count = int(len(individuals) * p_m)\n        random.shuffle(individuals)\n        for i in range(count):\n            random_index = random.randint(0, len(individuals[i]) - 1)\n            k = list(individuals[i])\n            k[random_index] = '1' if k[random_index] == '0' else '0'\n            individuals[i] = ''.join(k)\n        return individuals\n\n    def main(self, len_ind, p_count, max_iterations, p_c, p_m):\n        result = []\n        individuals = [gen_bindary(len_ind) for _ in range(p_count)]\n        for iteration in range(max_iterations):\n            for individ in individuals:\n                if individ in self.fitness_result.keys():\n                    continue\n                ch1, ch2 = self.split_ch(individ)\n                cols = self.get_need_cols(ch1)\n                sampl = self.get_sampl(ch2)\n                subset = self.generate_subset(sampl, cols)\n                if len(subset) > self.T:\n                    subset = self.random_els(subset)\n                D = len(subset)\n                if D == 0:\n                    ctr = 0\n                else:\n                    ctr = self.click_count_predictor(subset) / D\n                self.fitness_result[individ] = ctr * min(D, self.T)\n            result.append(\n                [max([self.fitness_result[i] for i in individuals]), list(filter(lambda x: self.fitness_result[x] == max([self.fitness_result[i] for i in individuals]), self.fitness_result))[0], sum([self.fitness_result[i] for i in individuals])/ len(individuals), iteration, min([self.fitness_result[i] for i in individuals])\n                ])\n                 \n            individuals = self.select_individuals(individuals)\n            individuals = self.cross(individuals, p_c)\n            individuals = self.mut(individuals, p_m)\n        return result, self.fitness_result","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:06.934488Z","iopub.execute_input":"2023-05-23T09:05:06.93491Z","iopub.status.idle":"2023-05-23T09:05:06.958808Z","shell.execute_reply.started":"2023-05-23T09:05:06.934878Z","shell.execute_reply":"2023-05-23T09:05:06.957666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def counter(subset):\n    return len(subset[subset['click'] == 1].index)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:03.893838Z","iopub.execute_input":"2023-05-23T09:05:03.894247Z","iopub.status.idle":"2023-05-23T09:05:03.900034Z","shell.execute_reply.started":"2023-05-23T09:05:03.894216Z","shell.execute_reply":"2023-05-23T09:05:03.898682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = res.columns[2:]\nalg = GenAlgorithm(res, cols, counter)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:08.376919Z","iopub.execute_input":"2023-05-23T09:05:08.377341Z","iopub.status.idle":"2023-05-23T09:05:08.382185Z","shell.execute_reply.started":"2023-05-23T09:05:08.377306Z","shell.execute_reply":"2023-05-23T09:05:08.381026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res= res.reset_index()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T08:59:23.762606Z","iopub.execute_input":"2023-05-23T08:59:23.763715Z","iopub.status.idle":"2023-05-23T08:59:23.811935Z","shell.execute_reply.started":"2023-05-23T08:59:23.763679Z","shell.execute_reply":"2023-05-23T08:59:23.810879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nres","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:10.806107Z","iopub.execute_input":"2023-05-23T09:05:10.806756Z","iopub.status.idle":"2023-05-23T09:05:11.173234Z","shell.execute_reply.started":"2023-05-23T09:05:10.80672Z","shell.execute_reply":"2023-05-23T09:05:11.172211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = alg.main(len_ind=40, p_count=20, max_iterations=50, p_c=0.2, p_m=0.2)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:13.948218Z","iopub.execute_input":"2023-05-23T09:05:13.948635Z","iopub.status.idle":"2023-05-23T09:05:17.1431Z","shell.execute_reply.started":"2023-05-23T09:05:13.948601Z","shell.execute_reply":"2023-05-23T09:05:17.142343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:05:20.49274Z","iopub.execute_input":"2023-05-23T09:05:20.493803Z","iopub.status.idle":"2023-05-23T09:05:20.514036Z","shell.execute_reply.started":"2023-05-23T09:05:20.49376Z","shell.execute_reply":"2023-05-23T09:05:20.512618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k = [[762.0, '0001011101000000110010101110110010101111', 103.34, 0, 0.0],\n [762.0, '0001011101000000110010101110110010101111', 219.78, 1, 0.0],\n [762.0, '0001011101000000110010101110110010101111', 347.36, 2, 0.0],\n [790.0, '0001011101000010110010101110110010101111', 410.4, 3, 0.0],\n [793.0, '0101011101000000110010101110110010101111', 477.78, 4, 0.0],\n [803.0, '0101011101000000110000101110110010101111', 554.88, 5, 0.0],\n [830.0, '0001001101000010110010101110110010101111', 572.44, 6, 0.0],\n [830.0, '0001001101000010110010101110110010101111', 577.48, 7, 0.0],\n [824.0, '0001011101000110111010101110110010101111', 634.76, 8, 0.0],\n [824.0, '0001011101000110111010101110110010101111', 598.36, 9, 0.0],\n [824.0, '0001011101000110111010101110110010101111', 589.36, 10, 0.0],\n [949.0, '0101010101000000100000101110110010101111', 582.7, 11, 0.0],\n [949.0, '0101010101000000100000101110110010101111', 653.16, 12, 0.0],\n [949.0, '0101010101000000100000101110110010101111', 651.0, 13, 0.0],\n [970.0, '0111010101000000100000101110110010101111', 675.48, 14, 0.0],\n [970.0, '0111010101000000100000101110110010101111', 722.52, 15, 0.0],\n [970.0, '0111010101000000100000101110110010101111', 757.16, 16, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 783.24, 17, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 790.86, 18, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 769.5, 19, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 777.68, 20, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 852.6, 21, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 849.8, 22, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 801.7, 23, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 860.2, 24, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 941.04, 25, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 903.1, 26, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 922.54, 27, 1.0],\n [985.0, '0111110101000000100000101110110010101111', 894.98, 28, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 916.2, 29, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 891.3, 30, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 891.96, 31, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 846.76, 32, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 880.22, 33, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 882.96, 34, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 889.2, 35, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 869.22, 36, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 885.06, 37, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 902.14, 38, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 899.32, 39, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 935.84, 40, 384.0],\n [985.0, '0111110101000000100000101110110010101111', 901.94, 41, 1.0],\n [985.0, '0111110101000000100000101110110010101111', 910.66, 42, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 919.54, 43, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 900.5, 44, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 878.56, 45, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 908.82, 46, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 894.48, 47, 0.0],\n [985.0, '0111110101000000100000101110110010101111', 894.94, 48, 160.0],\n [985.0, '0111110101000000100000101110110010101111', 944.74, 49, 0.0]]","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:06.651253Z","iopub.execute_input":"2023-05-23T09:32:06.65171Z","iopub.status.idle":"2023-05-23T09:32:06.670927Z","shell.execute_reply.started":"2023-05-23T09:32:06.65167Z","shell.execute_reply":"2023-05-23T09:32:06.669503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = []\na = []\nstep = []\nfor i in range(len(k)):\n    m.append(k[i][0]/2)\n    a.append(k[i][2]/2)\n    step.append(k[i][3])\n    k[i] = [k[i][0]/2, k[i][1],k[i][2]/2,k[i][3]]","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:07.271032Z","iopub.execute_input":"2023-05-23T09:32:07.271761Z","iopub.status.idle":"2023-05-23T09:32:07.278375Z","shell.execute_reply.started":"2023-05-23T09:32:07.271714Z","shell.execute_reply":"2023-05-23T09:32:07.277574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random.shuffle(k)\nk\nm = []\na = []\nstep = []\nfor i in range(10, 20):\n    m.append(k[i][0]/2)\n    a.append(k[i][2]/2000.)\n    step.append(k[i][3])\n    k[i] = [k[i][0]/2, k[i][1],k[i][2]/2,k[i][3]]","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:08.365534Z","iopub.execute_input":"2023-05-23T09:32:08.366638Z","iopub.status.idle":"2023-05-23T09:32:08.372237Z","shell.execute_reply.started":"2023-05-23T09:32:08.366598Z","shell.execute_reply":"2023-05-23T09:32:08.371387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.plot([i for i in range(10)], a)\nplt.xlabel('Кампани')\nplt.ylabel('CTR')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:19.516069Z","iopub.execute_input":"2023-05-23T09:32:19.516562Z","iopub.status.idle":"2023-05-23T09:32:19.658345Z","shell.execute_reply.started":"2023-05-23T09:32:19.516512Z","shell.execute_reply":"2023-05-23T09:32:19.657249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}