diff --git a/optuna/optuna_rapids.ipynb b/optuna/optuna_rapids.ipynb index 1b5f7e5..72e6bb2 100644 --- a/optuna/optuna_rapids.ipynb +++ b/optuna/optuna_rapids.ipynb @@ -13,7 +13,12 @@ "from sklearn.datasets import load_iris\n", "\n", "import pandas as pd\n", - "import optuna" + "import optuna\n", + "import numpy as np\n", + "import mlflow\n", + "import cuml\n", + "from cuml.ensemble import RandomForestRegressor\n", + "from cuml.metrics import accuracy_score" ] }, { @@ -25,22 +30,19 @@ "def objective(trial):\n", " iris = load_iris()\n", " X, y = cudf.DataFrame(pd.DataFrame(iris.data.astype('float32'))), cudf.DataFrame(pd.DataFrame(iris.target.astype('float32')))\n", - " solver = trial.suggest_categorical(\"solver\", [\"qn\"])\n", - " C = trial.suggest_uniform(\"C\", 0.0, 1.0)\n", + " max_depth = trial.suggest_int(\"max_depth\", 5, 15)\n", + " n_estimators = trial.suggest_int(\"n_estimators\", 100, 750)\n", + " max_leaves = trial.suggest_int(\"max_leaves\", -1, 20, 2)\n", "\n", - " if solver == \"qn\":\n", - " penalty = trial.suggest_categorical(\"penalty\", [\"l1\", \"l2\"])\n", - " else:\n", - " # 'penalty' parameter isn't relevant for this solver,\n", - " # so we always specify 'l2' as the dummy value.\n", - " penalty = \"l2\"\n", - "\n", - " classifier = LogisticRegression(max_iter=200, solver=solver, C=C, penalty=penalty)\n", + " classifier = RandomForestRegressor(max_depth=max_depth,\n", + " n_estimators=n_estimators,\n", + " max_leaves=max_leaves)\n", "\n", " X_train, X_valid, y_train, y_valid = train_test_split(X, y)\n", " classifier.fit(X_train, y_train)\n", - "\n", - " score = classifier.score(X_valid, y_valid)\n", + " y_pred = classifier.predict(X_valid)\n", + " \n", + " score = accuracy_score(y_valid, y_pred)\n", " return score" ] }, @@ -48,130 +50,51 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, + "outputs": [], + "source": [ + "N_TRIALS = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m[I 2020-06-10 19:24:27,151]\u001b[0m Finished trial#0 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.0678145987233475, 'penalty': 'l2'}. Best is trial#0 with value: 0.7368420958518982.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,252]\u001b[0m Finished trial#1 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.7270276264196817, 'penalty': 'l2'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,354]\u001b[0m Finished trial#2 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.8375729002505089, 'penalty': 'l2'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,480]\u001b[0m Finished trial#3 with value: 0.28947368264198303 with parameters: {'solver': 'qn', 'C': 0.11292021151514342, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,568]\u001b[0m Finished trial#4 with value: 0.28947368264198303 with parameters: {'solver': 'qn', 'C': 0.6944430510944374, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,698]\u001b[0m Finished trial#5 with value: 0.31578946113586426 with parameters: {'solver': 'qn', 'C': 0.765191567987065, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,810]\u001b[0m Finished trial#6 with value: 0.31578946113586426 with parameters: {'solver': 'qn', 'C': 0.10561501243776472, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,911]\u001b[0m Finished trial#7 with value: 0.3947368562221527 with parameters: {'solver': 'qn', 'C': 0.03007261494961, 'penalty': 'l2'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:27,998]\u001b[0m Finished trial#8 with value: 0.21052631735801697 with parameters: {'solver': 'qn', 'C': 0.41979272618173913, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,127]\u001b[0m Finished trial#9 with value: 0.28947368264198303 with parameters: {'solver': 'qn', 'C': 0.7489753109218725, 'penalty': 'l1'}. Best is trial#1 with value: 0.8421052694320679.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,230]\u001b[0m Finished trial#10 with value: 0.8947368264198303 with parameters: {'solver': 'qn', 'C': 0.44359087937596253, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,330]\u001b[0m Finished trial#11 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.46371780730242457, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,431]\u001b[0m Finished trial#12 with value: 0.8157894611358643 with parameters: {'solver': 'qn', 'C': 0.9927460128620971, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,537]\u001b[0m Finished trial#13 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.29952448418838495, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,633]\u001b[0m Finished trial#14 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.5794705651074834, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,729]\u001b[0m Finished trial#15 with value: 0.5526315569877625 with parameters: {'solver': 'qn', 'C': 0.2944472026388254, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,824]\u001b[0m Finished trial#16 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.5793220620566635, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:28,929]\u001b[0m Finished trial#17 with value: 0.6842105388641357 with parameters: {'solver': 'qn', 'C': 0.9590119355392663, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,027]\u001b[0m Finished trial#18 with value: 0.6052631735801697 with parameters: {'solver': 'qn', 'C': 0.3125574121635839, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,127]\u001b[0m Finished trial#19 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.6095229598262509, 'penalty': 'l2'}. Best is trial#10 with value: 0.8947368264198303.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,230]\u001b[0m Finished trial#20 with value: 0.9210526347160339 with parameters: {'solver': 'qn', 'C': 0.8799421115485504, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,333]\u001b[0m Finished trial#21 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.8803864482077604, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,432]\u001b[0m Finished trial#22 with value: 0.8157894611358643 with parameters: {'solver': 'qn', 'C': 0.8995211807065461, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,537]\u001b[0m Finished trial#23 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.646199627981733, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,633]\u001b[0m Finished trial#24 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.7886018023633428, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,731]\u001b[0m Finished trial#25 with value: 0.5526315569877625 with parameters: {'solver': 'qn', 'C': 0.399691684747305, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,834]\u001b[0m Finished trial#26 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.5368614929457577, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:29,928]\u001b[0m Finished trial#27 with value: 0.6052631735801697 with parameters: {'solver': 'qn', 'C': 0.19740949841466554, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,023]\u001b[0m Finished trial#28 with value: 0.6842105388641357 with parameters: {'solver': 'qn', 'C': 0.49401832666413054, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,123]\u001b[0m Finished trial#29 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.3650882251832587, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,225]\u001b[0m Finished trial#30 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.5345406100537605, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,326]\u001b[0m Finished trial#31 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.6881981246992266, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,426]\u001b[0m Finished trial#32 with value: 0.5526315569877625 with parameters: {'solver': 'qn', 'C': 0.8637389518235415, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,530]\u001b[0m Finished trial#33 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.9443408272068531, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,634]\u001b[0m Finished trial#34 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.8079603950749463, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,739]\u001b[0m Finished trial#35 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.6908193693947583, 'penalty': 'l2'}. Best is trial#20 with value: 0.9210526347160339.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,839]\u001b[0m Finished trial#36 with value: 0.9736841917037964 with parameters: {'solver': 'qn', 'C': 0.5089016964558896, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:30,936]\u001b[0m Finished trial#37 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.501657831988356, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,030]\u001b[0m Finished trial#38 with value: 0.7105262875556946 with parameters: {'solver': 'qn', 'C': 0.19281036617248498, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,120]\u001b[0m Finished trial#39 with value: 0.2368421107530594 with parameters: {'solver': 'qn', 'C': 0.41895753797055957, 'penalty': 'l1'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,222]\u001b[0m Finished trial#40 with value: 0.6578947305679321 with parameters: {'solver': 'qn', 'C': 0.3546309100056845, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,318]\u001b[0m Finished trial#41 with value: 0.5789473652839661 with parameters: {'solver': 'qn', 'C': 0.5516239453304751, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,420]\u001b[0m Finished trial#42 with value: 0.15789473056793213 with parameters: {'solver': 'qn', 'C': 0.8276742014432102, 'penalty': 'l1'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,516]\u001b[0m Finished trial#43 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.7392288229996461, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,613]\u001b[0m Finished trial#44 with value: 0.9736841917037964 with parameters: {'solver': 'qn', 'C': 0.6216670159760471, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,710]\u001b[0m Finished trial#45 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.4593532538600798, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,818]\u001b[0m Finished trial#46 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.6346697107777431, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:31,915]\u001b[0m Finished trial#47 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.44917505195748547, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,010]\u001b[0m Finished trial#48 with value: 0.31578946113586426 with parameters: {'solver': 'qn', 'C': 0.4622410862241562, 'penalty': 'l1'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,116]\u001b[0m Finished trial#49 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.2571394275043674, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,217]\u001b[0m Finished trial#50 with value: 0.6578947305679321 with parameters: {'solver': 'qn', 'C': 0.6484664595233616, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,314]\u001b[0m Finished trial#51 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.6230953897640432, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,413]\u001b[0m Finished trial#52 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.51615091133681, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,509]\u001b[0m Finished trial#53 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.5714682344140277, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,605]\u001b[0m Finished trial#54 with value: 0.8947368264198303 with parameters: {'solver': 'qn', 'C': 0.6015340568004777, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,711]\u001b[0m Finished trial#55 with value: 0.6842105388641357 with parameters: {'solver': 'qn', 'C': 0.5986561630870231, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,808]\u001b[0m Finished trial#56 with value: 0.6842105388641357 with parameters: {'solver': 'qn', 'C': 0.36844310681923476, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:32,912]\u001b[0m Finished trial#57 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.5448736061376203, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,011]\u001b[0m Finished trial#58 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.6860701190939763, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,106]\u001b[0m Finished trial#59 with value: 0.8947368264198303 with parameters: {'solver': 'qn', 'C': 0.4973733288839985, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,209]\u001b[0m Finished trial#60 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.49110421103802837, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,307]\u001b[0m Finished trial#61 with value: 0.7105262875556946 with parameters: {'solver': 'qn', 'C': 0.6347554464808812, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,409]\u001b[0m Finished trial#62 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.7221227434836912, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,506]\u001b[0m Finished trial#63 with value: 0.6052631735801697 with parameters: {'solver': 'qn', 'C': 0.41296451519557364, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,602]\u001b[0m Finished trial#64 with value: 0.5526315569877625 with parameters: {'solver': 'qn', 'C': 0.4710585261685819, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,700]\u001b[0m Finished trial#65 with value: 0.8157894611358643 with parameters: {'solver': 'qn', 'C': 0.5797124310013331, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,799]\u001b[0m Finished trial#66 with value: 0.7105262875556946 with parameters: {'solver': 'qn', 'C': 0.5953906154507992, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,897]\u001b[0m Finished trial#67 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.5207031946236365, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:33,994]\u001b[0m Finished trial#68 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.43686124784280767, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,086]\u001b[0m Finished trial#69 with value: 0.2631579041481018 with parameters: {'solver': 'qn', 'C': 0.3260315615886182, 'penalty': 'l1'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,183]\u001b[0m Finished trial#70 with value: 0.5263158082962036 with parameters: {'solver': 'qn', 'C': 0.5190948551093238, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,288]\u001b[0m Finished trial#71 with value: 0.7894737124443054 with parameters: {'solver': 'qn', 'C': 0.4848454631772958, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,393]\u001b[0m Finished trial#72 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.7705871073389333, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,498]\u001b[0m Finished trial#73 with value: 0.9210526347160339 with parameters: {'solver': 'qn', 'C': 0.6589256991315847, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,599]\u001b[0m Finished trial#74 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.5629004876298789, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,696]\u001b[0m Finished trial#75 with value: 0.6052631735801697 with parameters: {'solver': 'qn', 'C': 0.3794133654575614, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,795]\u001b[0m Finished trial#76 with value: 0.44736841320991516 with parameters: {'solver': 'qn', 'C': 0.6666105583406476, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,895]\u001b[0m Finished trial#77 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.6106698108091412, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:34,994]\u001b[0m Finished trial#78 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.526555948086514, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,092]\u001b[0m Finished trial#79 with value: 0.7105262875556946 with parameters: {'solver': 'qn', 'C': 0.4429793860560524, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,198]\u001b[0m Finished trial#80 with value: 0.8157894611358643 with parameters: {'solver': 'qn', 'C': 0.6606013405652754, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,301]\u001b[0m Finished trial#81 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.7131418551550445, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,400]\u001b[0m Finished trial#82 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.5592269373280605, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,498]\u001b[0m Finished trial#83 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.3938622731798883, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,598]\u001b[0m Finished trial#84 with value: 0.8947368264198303 with parameters: {'solver': 'qn', 'C': 0.9097666834366412, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,696]\u001b[0m Finished trial#85 with value: 0.8157894611358643 with parameters: {'solver': 'qn', 'C': 0.9052459084208117, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,797]\u001b[0m Finished trial#86 with value: 0.8947368264198303 with parameters: {'solver': 'qn', 'C': 0.9792775961065546, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:35,895]\u001b[0m Finished trial#87 with value: 0.7368420958518982 with parameters: {'solver': 'qn', 'C': 0.9112989472426206, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,000]\u001b[0m Finished trial#88 with value: 0.8684210777282715 with parameters: {'solver': 'qn', 'C': 0.9970820508961293, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,093]\u001b[0m Finished trial#89 with value: 0.21052631735801697 with parameters: {'solver': 'qn', 'C': 0.966818278678185, 'penalty': 'l1'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,200]\u001b[0m Finished trial#90 with value: 0.6315789222717285 with parameters: {'solver': 'qn', 'C': 0.9376514762863789, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,309]\u001b[0m Finished trial#91 with value: 0.9210526347160339 with parameters: {'solver': 'qn', 'C': 0.8428083467814781, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,410]\u001b[0m Finished trial#92 with value: 0.6578947305679321 with parameters: {'solver': 'qn', 'C': 0.8535007439855011, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,511]\u001b[0m Finished trial#93 with value: 0.9210526347160339 with parameters: {'solver': 'qn', 'C': 0.8191829878463018, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,611]\u001b[0m Finished trial#94 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.8168977560104876, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,710]\u001b[0m Finished trial#95 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.7740555917626628, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,808]\u001b[0m Finished trial#96 with value: 0.7631579041481018 with parameters: {'solver': 'qn', 'C': 0.8826534144743736, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:36,909]\u001b[0m Finished trial#97 with value: 0.8421052694320679 with parameters: {'solver': 'qn', 'C': 0.746793488676108, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:37,010]\u001b[0m Finished trial#98 with value: 0.9736841917037964 with parameters: {'solver': 'qn', 'C': 0.9757291279362099, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n", - "\u001b[32m[I 2020-06-10 19:24:37,109]\u001b[0m Finished trial#99 with value: 0.6842105388641357 with parameters: {'solver': 'qn', 'C': 0.964850073436121, 'penalty': 'l2'}. Best is trial#36 with value: 0.9736841917037964.\u001b[0m\n" + "/opt/conda/envs/rapids/lib/python3.6/site-packages/optuna/distributions.py:544: UserWarning: The distribution is specified by [-1, 20] and step=2, but the range is not divisible by `step`. It will be replaced by [-1, 19].\n", + " low=low, old_high=old_high, high=high, step=step\n", + "\u001b[32m[I 2020-06-11 15:04:57,558]\u001b[0m Finished trial#0 with value: 0.7105262875556946 with parameters: {'max_depth': 8, 'n_estimators': 582, 'max_leaves': 9}. Best is trial#0 with value: 0.7105262875556946.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:04:58,170]\u001b[0m Finished trial#1 with value: 0.7894737124443054 with parameters: {'max_depth': 9, 'n_estimators': 507, 'max_leaves': 7}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:04:58,848]\u001b[0m Finished trial#2 with value: 0.7894737124443054 with parameters: {'max_depth': 11, 'n_estimators': 446, 'max_leaves': 19}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:04:59,452]\u001b[0m Finished trial#3 with value: 0.7894737124443054 with parameters: {'max_depth': 8, 'n_estimators': 563, 'max_leaves': 17}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:00,144]\u001b[0m Finished trial#4 with value: 0.6052631735801697 with parameters: {'max_depth': 5, 'n_estimators': 721, 'max_leaves': 15}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:00,705]\u001b[0m Finished trial#5 with value: 0.5263158082962036 with parameters: {'max_depth': 14, 'n_estimators': 486, 'max_leaves': 3}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:00,965]\u001b[0m Finished trial#6 with value: 0.7368420958518982 with parameters: {'max_depth': 12, 'n_estimators': 235, 'max_leaves': 1}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:01,176]\u001b[0m Finished trial#7 with value: 0.6052631735801697 with parameters: {'max_depth': 6, 'n_estimators': 178, 'max_leaves': 1}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:01,976]\u001b[0m Finished trial#8 with value: 0.6315789222717285 with parameters: {'max_depth': 11, 'n_estimators': 615, 'max_leaves': 7}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:02,265]\u001b[0m Finished trial#9 with value: 0.5263158082962036 with parameters: {'max_depth': 8, 'n_estimators': 225, 'max_leaves': 3}. Best is trial#1 with value: 0.7894737124443054.\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Number of finished trials: 100\n", + "Number of finished trials: 10\n", "Best trial:\n", - " Value: 0.9736841917037964\n", + " Value: 0.7894737124443054\n", " Params: \n", - " solver: qn\n", - " C: 0.5089016964558896\n", - " penalty: l2\n" + " max_depth: 9\n", + " n_estimators: 507\n", + " max_leaves: 7\n" ] } ], "source": [ "study = optuna.create_study(direction=\"maximize\")\n", - "study.optimize(objective, n_trials=100)\n", + "study.optimize(objective, n_trials=N_TRIALS)\n", "\n", "print(\"Number of finished trials: \", len(study.trials))\n", "\n", @@ -185,6 +108,72 @@ " print(\" {}: {}\".format(key, value))" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def mlflow_callback(study, trial):\n", + " trial_value = trial.value if trial.value is not None else float(\"nan\")\n", + " with mlflow.start_run(run_name=study.study_name):\n", + " mlflow.log_params(trial.params)\n", + " mlflow.log_metrics({\"accuracy\": trial_value})" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m[I 2020-06-11 15:05:02,594]\u001b[0m Finished trial#0 with value: 0.3684210479259491 with parameters: {'max_depth': 14, 'n_estimators': 121, 'max_leaves': 11}. Best is trial#0 with value: 0.3684210479259491.\u001b[0m\n", + "/opt/conda/envs/rapids/lib/python3.6/site-packages/optuna/distributions.py:544: UserWarning: The distribution is specified by [-1, 20] and step=2, but the range is not divisible by `step`. It will be replaced by [-1, 19].\n", + " low=low, old_high=old_high, high=high, step=step\n", + "\u001b[32m[I 2020-06-11 15:05:03,379]\u001b[0m Finished trial#1 with value: 0.6315789222717285 with parameters: {'max_depth': 6, 'n_estimators': 616, 'max_leaves': 1}. Best is trial#1 with value: 0.6315789222717285.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:03,582]\u001b[0m Finished trial#2 with value: 0.8421052694320679 with parameters: {'max_depth': 5, 'n_estimators': 149, 'max_leaves': 11}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:04,077]\u001b[0m Finished trial#3 with value: 0.6842105388641357 with parameters: {'max_depth': 8, 'n_estimators': 356, 'max_leaves': 15}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:04,798]\u001b[0m Finished trial#4 with value: 0.6842105388641357 with parameters: {'max_depth': 12, 'n_estimators': 691, 'max_leaves': 3}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:05,173]\u001b[0m Finished trial#5 with value: 0.7631579041481018 with parameters: {'max_depth': 13, 'n_estimators': 210, 'max_leaves': 11}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:06,215]\u001b[0m Finished trial#6 with value: 0.6578947305679321 with parameters: {'max_depth': 13, 'n_estimators': 712, 'max_leaves': 15}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:06,662]\u001b[0m Finished trial#7 with value: 0.6052631735801697 with parameters: {'max_depth': 6, 'n_estimators': 354, 'max_leaves': 7}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:07,310]\u001b[0m Finished trial#8 with value: 0.6842105388641357 with parameters: {'max_depth': 13, 'n_estimators': 523, 'max_leaves': 11}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n", + "\u001b[32m[I 2020-06-11 15:05:08,016]\u001b[0m Finished trial#9 with value: 0.6842105388641357 with parameters: {'max_depth': 8, 'n_estimators': 556, 'max_leaves': 7}. Best is trial#2 with value: 0.8421052694320679.\u001b[0m\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of finished trials: 10\n", + "Best trial:\n", + " Value: 0.8421052694320679\n", + " Params: \n", + " max_depth: 5\n", + " n_estimators: 149\n", + " max_leaves: 11\n" + ] + } + ], + "source": [ + "study = optuna.create_study(direction=\"maximize\")\n", + "study.optimize(objective, n_trials=N_TRIALS, timeout=600, callbacks=[mlflow_callback])\n", + "\n", + "print(\"Number of finished trials: {}\".format(len(study.trials)))\n", + "\n", + "print(\"Best trial:\")\n", + "trial = study.best_trial\n", + "\n", + "print(\" Value: {}\".format(trial.value))\n", + "\n", + "print(\" Params: \")\n", + "for key, value in trial.params.items():\n", + " print(\" {}: {}\".format(key, value))" + ] + }, { "cell_type": "code", "execution_count": null,