Skip to content

Commit 031b819

Browse files
ckurzeamotl
authored andcommitted
ML/AutoML: Reworked connection string for easier usage
1 parent c4cad47 commit 031b819

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

topic/machine-learning/automl/automl_timeseries_forecasting_with_pycaret.ipynb

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,48 @@
120120
"sign up for a free account at https://console.cratedb.cloud and \n",
121121
"[deploy a cluster].\n",
122122
"\n",
123+
"[deploy a cluster]: https://cratedb.com/docs/cloud/en/latest/tutorials/deploy/stripe.html#deploy-cluster\n"
124+
]
125+
},
126+
{
127+
"cell_type": "markdown",
128+
"metadata": {},
129+
"source": [
123130
"To populate your environment with corresponding database access credentials,\n",
124131
"create an `.env` file with the following content:\n",
125132
"\n",
126133
"```env\n",
127-
"CRATE_HOST=<your-crate-host> # set this to localhost if you're running crate locally\n",
128-
"CRATE_USER=<your-crate-user> # set this to crate if you're running crate locally\n",
129-
"CRATE_PASSWORD=<your-crate-password> # set this to \"\" if you're running crate locally\n",
130-
"CRATE_SSL=true # set this to false if you're running crate locally\n",
134+
"# use this string for a connection to CrateDB Cloud\n",
135+
"CONNECTION_STRING=crate://username:password@hostname/?ssl=true \n",
136+
"\n",
137+
"# use this string for a local connection to CrateDB\n",
138+
"# CONNECTION_STRING=crate://crate@localhost/?ssl=false \n",
131139
"```\n",
132140
"\n",
133141
"You can find your CrateDB credentials in the [CrateDB Cloud Console].\n",
134142
"\n",
135-
"[CrateDB Cloud Console]: https://cratedb.com/docs/cloud/en/latest/reference/overview.html#cluster\n",
136-
"[deploy a cluster]: https://cratedb.com/docs/cloud/en/latest/tutorials/deploy/stripe.html#deploy-cluster\n"
143+
"[CrateDB Cloud Console]: https://cratedb.com/docs/cloud/en/latest/reference/overview.html#cluster"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": [
152+
"import os\n",
153+
"\n",
154+
"# For CrateDB Cloud, use:\n",
155+
"CONNECTION_STRING = os.environ.get(\n",
156+
" \"CRATEDB_CONNECTION_STRING\",\n",
157+
" \"crate://username:password@hostname/?ssl=true\",\n",
158+
")\n",
159+
"\n",
160+
"# For an self-deployed CrateDB, e.g. via Docker, please use:\n",
161+
"# CONNECTION_STRING = os.environ.get(\n",
162+
"# \"CRATEDB_CONNECTION_STRING\",\n",
163+
"# \"crate://crate@localhost/?ssl=false\",\n",
164+
"# )"
137165
]
138166
},
139167
{
@@ -203,8 +231,7 @@
203231
"data[\"date\"] = pd.to_datetime(data[\"date\"])\n",
204232
"\n",
205233
"# Insert the data into CrateDB\n",
206-
"dburi = f\"crate://{os.environ['CRATE_USER']}:{os.environ['CRATE_PASSWORD']}@{os.environ['CRATE_HOST']}:4200?ssl={os.environ['CRATE_SSL']}\"\n",
207-
"engine = sa.create_engine(dburi, echo=os.environ.get(\"DEBUG\"))\n",
234+
"engine = sa.create_engine(CONNECTION_STRING, echo=os.environ.get(\"DEBUG\"))\n",
208235
"\n",
209236
"with engine.connect() as conn:\n",
210237
" data.to_sql(\n",
@@ -253,7 +280,7 @@
253280
"data[\"month\"] = pd.to_datetime(data['month'], unit='ms')\n",
254281
"\n",
255282
"# We set the MLFLOW_TRACKING_URI to our CrateDB instance. We'll see later why\n",
256-
"os.environ[\"MLFLOW_TRACKING_URI\"] = f\"{dburi}&schema=mlflow\""
283+
"os.environ[\"MLFLOW_TRACKING_URI\"] = f\"{CONNECTION_STRING}&schema=mlflow\""
257284
]
258285
},
259286
{
@@ -1277,28 +1304,28 @@
12771304
"output_type": "display_data"
12781305
},
12791306
{
1280-
"name": "stdout",
12811307
"metadata": {
12821308
"nbreg": {
12831309
"diff_ignore": [
12841310
"/outputs"
12851311
]
12861312
}
12871313
},
1314+
"name": "stdout",
12881315
"output_type": "stream",
12891316
"text": [
12901317
"Fitting 3 folds for each of 10 candidates, totalling 30 fits\n"
12911318
]
12921319
},
12931320
{
1294-
"name": "stderr",
12951321
"metadata": {
12961322
"nbreg": {
12971323
"diff_ignore": [
12981324
"/outputs"
12991325
]
13001326
}
13011327
},
1328+
"name": "stderr",
13021329
"output_type": "stream",
13031330
"text": [
13041331
"[Parallel(n_jobs=-1)]: Using backend LokyBackend with 24 concurrent workers.\n",
@@ -1433,28 +1460,28 @@
14331460
"output_type": "display_data"
14341461
},
14351462
{
1436-
"name": "stdout",
14371463
"metadata": {
14381464
"nbreg": {
14391465
"diff_ignore": [
14401466
"/outputs"
14411467
]
14421468
}
14431469
},
1470+
"name": "stdout",
14441471
"output_type": "stream",
14451472
"text": [
14461473
"Fitting 3 folds for each of 10 candidates, totalling 30 fits\n"
14471474
]
14481475
},
14491476
{
1450-
"name": "stderr",
14511477
"metadata": {
14521478
"nbreg": {
14531479
"diff_ignore": [
14541480
"/outputs"
14551481
]
14561482
}
14571483
},
1484+
"name": "stderr",
14581485
"output_type": "stream",
14591486
"text": [
14601487
"[Parallel(n_jobs=-1)]: Using backend LokyBackend with 24 concurrent workers.\n",
@@ -1583,28 +1610,28 @@
15831610
"output_type": "display_data"
15841611
},
15851612
{
1586-
"name": "stdout",
1587-
"output_type": "stream",
15881613
"metadata": {
15891614
"nbreg": {
15901615
"diff_ignore": [
15911616
"/outputs"
15921617
]
15931618
}
15941619
},
1620+
"name": "stdout",
1621+
"output_type": "stream",
15951622
"text": [
15961623
"Fitting 3 folds for each of 10 candidates, totalling 30 fits\n"
15971624
]
15981625
},
15991626
{
1600-
"name": "stderr",
16011627
"metadata": {
16021628
"nbreg": {
16031629
"diff_ignore": [
16041630
"/outputs"
16051631
]
16061632
}
16071633
},
1634+
"name": "stderr",
16081635
"output_type": "stream",
16091636
"text": [
16101637
"[Parallel(n_jobs=-1)]: Using backend LokyBackend with 24 concurrent workers.\n",
@@ -2086,7 +2113,7 @@
20862113
"source": [
20872114
"os.environ[\n",
20882115
" \"MLFLOW_TRACKING_URI\"\n",
2089-
"] = f\"crate://{os.environ['CRATE_USER']}:{os.environ['CRATE_PASSWORD']}@{os.environ['CRATE_HOST']}:4200?ssl={os.environ['CRATE_SSL']}&schema=mlflow\""
2116+
"] = f\"{CONNECTION_STRING}&schema=mlflow\""
20902117
]
20912118
},
20922119
{
@@ -2182,7 +2209,7 @@
21822209
],
21832210
"metadata": {
21842211
"kernelspec": {
2185-
"display_name": "crate",
2212+
"display_name": "Python 3 (ipykernel)",
21862213
"language": "python",
21872214
"name": "python3"
21882215
},
@@ -2196,7 +2223,7 @@
21962223
"name": "python",
21972224
"nbconvert_exporter": "python",
21982225
"pygments_lexer": "ipython3",
2199-
"version": "3.10.0"
2226+
"version": "3.11.4"
22002227
}
22012228
},
22022229
"nbformat": 4,

0 commit comments

Comments
 (0)