|
278 | 278 | "# kh.visualize_report(report_file_path)" |
279 | 279 | ] |
280 | 280 | }, |
| 281 | + { |
| 282 | + "cell_type": "markdown", |
| 283 | + "metadata": {}, |
| 284 | + "source": [ |
| 285 | + "### `train_predictor_text()`\n\n", |
| 286 | + "Trains a predictor with just text-specific parameters\n" |
| 287 | + ] |
| 288 | + }, |
| 289 | + { |
| 290 | + "cell_type": "code", |
| 291 | + "execution_count": null, |
| 292 | + "metadata": {}, |
| 293 | + "outputs": [], |
| 294 | + "source": [ |
| 295 | + "# Imports\n", |
| 296 | + "import os\n", |
| 297 | + "from khiops import core as kh\n", |
| 298 | + "\n", |
| 299 | + "# Set the file paths\n", |
| 300 | + "dictionary_file_path = os.path.join(\n", |
| 301 | + " kh.get_samples_dir(), \"NegativeAirlineTweets\", \"NegativeAirlineTweets.kdic\"\n", |
| 302 | + ")\n", |
| 303 | + "data_table_path = os.path.join(\n", |
| 304 | + " kh.get_samples_dir(), \"NegativeAirlineTweets\", \"NegativeAirlineTweets.txt\"\n", |
| 305 | + ")\n", |
| 306 | + "report_file_path = os.path.join(\n", |
| 307 | + " \"kh_samples\", \"train_predictor_text\", \"AnalysisResults.khj\"\n", |
| 308 | + ")\n", |
| 309 | + "\n", |
| 310 | + "# Train the predictor\n", |
| 311 | + "kh.train_predictor(\n", |
| 312 | + " dictionary_file_path,\n", |
| 313 | + " \"FlightNegativeTweets\",\n", |
| 314 | + " data_table_path,\n", |
| 315 | + " \"negativereason\",\n", |
| 316 | + " report_file_path,\n", |
| 317 | + " max_trees=5,\n", |
| 318 | + " max_text_features=1000,\n", |
| 319 | + " text_features=\"words\",\n", |
| 320 | + ")" |
| 321 | + ] |
| 322 | + }, |
281 | 323 | { |
282 | 324 | "cell_type": "markdown", |
283 | 325 | "metadata": {}, |
|
1248 | 1290 | ")" |
1249 | 1291 | ] |
1250 | 1292 | }, |
| 1293 | + { |
| 1294 | + "cell_type": "markdown", |
| 1295 | + "metadata": {}, |
| 1296 | + "source": [ |
| 1297 | + "### `deploy_model_text()`\n\n", |
| 1298 | + "Deploys a model learned on textual data\n It is a call to `~.api.deploy_model` with its mandatory parameters, plus\n text-specific parameters.\n\n In this example, a Selective Naive Bayes (SNB) model is deployed by applying its\n associated dictionary to the input database. The model predictions are written to\n the output database.\n \n" |
| 1299 | + ] |
| 1300 | + }, |
| 1301 | + { |
| 1302 | + "cell_type": "code", |
| 1303 | + "execution_count": null, |
| 1304 | + "metadata": {}, |
| 1305 | + "outputs": [], |
| 1306 | + "source": [ |
| 1307 | + "# Imports\n", |
| 1308 | + "import os\n", |
| 1309 | + "from khiops import core as kh\n", |
| 1310 | + "\n", |
| 1311 | + "# Set the file paths\n", |
| 1312 | + "dictionary_file_path = os.path.join(\n", |
| 1313 | + " kh.get_samples_dir(), \"NegativeAirlineTweets\", \"NegativeAirlineTweets.kdic\"\n", |
| 1314 | + ")\n", |
| 1315 | + "data_table_path = os.path.join(\n", |
| 1316 | + " kh.get_samples_dir(), \"NegativeAirlineTweets\", \"NegativeAirlineTweets.txt\"\n", |
| 1317 | + ")\n", |
| 1318 | + "output_dir = os.path.join(\"kh_samples\", \"deploy_model_text\")\n", |
| 1319 | + "report_file_path = os.path.join(output_dir, \"AnalysisResults.khj\")\n", |
| 1320 | + "output_data_table_path = os.path.join(output_dir, \"ScoresNegativeAirlineTweets.txt\")\n", |
| 1321 | + "\n", |
| 1322 | + "# Train the predictor\n", |
| 1323 | + "_, model_dictionary_file_path = kh.train_predictor(\n", |
| 1324 | + " dictionary_file_path,\n", |
| 1325 | + " \"FlightNegativeTweets\",\n", |
| 1326 | + " data_table_path,\n", |
| 1327 | + " \"negativereason\",\n", |
| 1328 | + " report_file_path,\n", |
| 1329 | + " max_trees=5,\n", |
| 1330 | + " max_text_features=1000,\n", |
| 1331 | + " text_features=\"words\",\n", |
| 1332 | + ")\n", |
| 1333 | + "\n", |
| 1334 | + "# Deploy the model on the database\n", |
| 1335 | + "# It will score it according to the trained predictor\n", |
| 1336 | + "kh.deploy_model(\n", |
| 1337 | + " model_dictionary_file_path,\n", |
| 1338 | + " \"SNB_FlightNegativeTweets\",\n", |
| 1339 | + " data_table_path,\n", |
| 1340 | + " output_data_table_path,\n", |
| 1341 | + ")" |
| 1342 | + ] |
| 1343 | + }, |
1251 | 1344 | { |
1252 | 1345 | "cell_type": "markdown", |
1253 | 1346 | "metadata": {}, |
|
0 commit comments