Skip to content

Update new helpers #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/quick-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Quick Checks
env:
KHIOPS_PYTHON_REVISION: 171-implement-multi-table-helper-functions
on:
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install khiops-python dev dependencies
run: |
pip install pre-commit
- name: Run pre-commit checks
uses: pre-commit/[email protected]

execute-nb:
runs-on: ubuntu-22.04
container:
image: ghcr.io/khiopsml/khiops-python/khiopspydev-ubuntu22.04:10.2.3-b.5.0
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install pre-requisites
run: |
pip install nbconvert nbformat jupyter
- name: Install khiops-python
run: |
git clone https://github.com/khiopsml/khiops-python
cd khiops-python
git switch $KHIOPS_PYTHON_REVISION
pip install .
kh-status
kh-download-datasets
- name: Execute the convert hook
run: |
mkdir output_nb
export KHIOPS_PROC_NUMBER=1
python khiops-python/doc/convert_tutorials.py --execute-notebooks ./ output_nb
ls -ltr output_nb
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ repos:
rev: 22.10.0
hooks:
- id: black
language_version: python3.9
- id: black-jupyter
language_version: python3.9
- repo: local
hooks:
- id: my-nb-clean
Expand Down
108 changes: 68 additions & 40 deletions Core Basics 1 - Train, Evaluate and Deploy a Classifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"# Core Basics 1: Train, Evaluate and Deploy a Classifier\n",
"In this lesson we will learn how to train, evaluate and deploy classifiers with Khiops.\n",
"\n",
"We start by importing Khiops, some helper functions and saving the location of the Khiops `Samples` directory into a variable"
"Make sure you have installed [Khiops](https://khiops.org/setup/) and [Khiops Visualization](https://khiops.org/setup/visualization/).\n",
"\n",
"We start by importing Khiops and defining some helper functions:"
]
},
{
Expand All @@ -16,13 +18,32 @@
"metadata": {},
"outputs": [],
"source": [
"from os import path\n",
"\n",
"import os\n",
"import platform\n",
"import subprocess\n",
"from khiops import core as kh\n",
"from helper_functions import explorer_open, peek\n",
"\n",
"samples_dir = kh.get_samples_dir()\n",
"print(f\"Khiops samples directory located at {samples_dir}\")"
"# Define helper functions\n",
"def peek(file_path, n=10):\n",
" \"\"\"Shows the first n lines of a file\"\"\"\n",
" with open(file_path, encoding=\"utf8\", errors=\"replace\") as file:\n",
" for line in file.readlines()[:n]:\n",
" print(line, end=\"\")\n",
" print(\"\")\n",
"\n",
"\n",
"def os_open(path):\n",
" \"\"\"Opens a file or directory with its default application\"\"\"\n",
" if platform.system() == \"Windows\":\n",
" os.startfile(path)\n",
" elif platform.system() == \"Darwin\":\n",
" subprocess.call([\"open\", path])\n",
" else:\n",
" subprocess.call([\"xdg-open\", path])\n",
"\n",
"\n",
"# If there are any issues you may Khiops status with the following command\n",
"# kh.get_runner().print_status()"
]
},
{
Expand All @@ -46,18 +67,12 @@
"metadata": {},
"outputs": [],
"source": [
"iris_kdic = path.join(samples_dir, \"Iris\", \"Iris.kdic\")\n",
"iris_data_file = path.join(samples_dir, \"Iris\", \"Iris.txt\")\n",
"iris_kdic = os.path.join(kh.get_samples_dir(), \"Iris\", \"Iris.kdic\")\n",
"iris_data_file = os.path.join(kh.get_samples_dir(), \"Iris\", \"Iris.txt\")\n",
"\n",
"print(\"\")\n",
"print(f\"Iris dictionary file location: {iris_kdic}\")\n",
"print(\"\")\n",
"print(f\"Iris dictionary file: {iris_kdic}\")\n",
"peek(iris_kdic)\n",
"\n",
"print(\"\")\n",
"print(\"\")\n",
"print(f\"Iris data location: {iris_data_file}\")\n",
"print(\"\")\n",
"print(f\"Iris data file: {iris_data_file}\\n\")\n",
"peek(iris_data_file)"
]
},
Expand All @@ -74,7 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"iris_results_dir = path.join(\"exercises\", \"Iris\")\n",
"iris_results_dir = os.path.join(\"exercises\", \"Iris\")\n",
"print(f\"Iris results directory: {iris_results_dir}\")"
]
},
Expand All @@ -101,15 +116,15 @@
" results_dir=iris_results_dir,\n",
" max_trees=0, # by default Khiops constructs 10 decision tree variables\n",
")\n",
"print(f\"Iris report file located at: {iris_report}\")\n",
"print(f\"Iris modeling dictionary file located at: {iris_model_kdic}\")"
"print(f\"Iris report file: {iris_report}\")\n",
"print(f\"Iris modeling dictionary: {iris_model_kdic}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can verify that the result files were created in `iris_results_dir`. In the next sections, we'll use the file at `iris_report` to assess the models' performances and the file at `iris_model_kdic` to deploy it."
"You can verify that the result files were created in `iris_results_dir`. In the next sections, we'll use the file at `iris_report` to assess the models' performances and the file at `iris_model_kdic` to deploy it. Now we can see the report with the Khiops Visualization app:"
]
},
{
Expand All @@ -118,8 +133,8 @@
"metadata": {},
"outputs": [],
"source": [
"# To take a look at the directory where the resulting files are stored\n",
"# explorer_open(iris_results_dir)"
"# To visualize uncomment the line below\n",
"# os_open(iris_report)"
]
},
{
Expand All @@ -139,8 +154,8 @@
"metadata": {},
"outputs": [],
"source": [
"adult_kdic = path.join(samples_dir, \"Adult\", \"Adult.kdic\")\n",
"adult_data_file = path.join(samples_dir, \"Adult\", \"Adult.txt\")"
"adult_kdic = os.path.join(kh.get_samples_dir(), \"Adult\", \"Adult.kdic\")\n",
"adult_data_file = os.path.join(kh.get_samples_dir(), \"Adult\", \"Adult.txt\")"
]
},
{
Expand All @@ -158,15 +173,9 @@
},
"outputs": [],
"source": [
"print(\"\")\n",
"print(f\"Adult dictionary file location: {adult_kdic}\")\n",
"print(\"\")\n",
"print(f\"Adult dictionary file: {adult_kdic}\")\n",
"peek(adult_kdic)\n",
"\n",
"print(\"\")\n",
"print(\"\")\n",
"print(f\"Adult data location: {adult_data_file}\")\n",
"print(\"\")\n",
"print(f\"Adult data file: {adult_data_file}\\n\")\n",
"peek(adult_data_file)"
]
},
Expand All @@ -183,8 +192,8 @@
"metadata": {},
"outputs": [],
"source": [
"adult_results_dir = path.join(\"exercises\", \"Adult\")\n",
"print(f\"Adult exercise results directory: {adult_results_dir}\")"
"adult_results_dir = os.path.join(\"exercises\", \"Adult\")\n",
"print(f\"Adult results directory: {adult_results_dir}\")"
]
},
{
Expand All @@ -211,8 +220,27 @@
" results_dir=adult_results_dir,\n",
" max_trees=0,\n",
")\n",
"print(f\"Adult report file located at: {adult_report}\")\n",
"print(f\"Adult modeling dictionary file located at: {adult_model_kdic}\")"
"print(f\"Adult report file: {adult_report}\")\n",
"print(f\"Adult modeling dictionary file: {adult_model_kdic}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Inspect the results with the Khiops Visualization app"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"is_khiops_tutorial_solution": true
},
"outputs": [],
"source": [
"# To visualize uncomment the line below\n",
"# os_open(adult_report)"
]
},
{
Expand Down Expand Up @@ -388,7 +416,7 @@
"metadata": {},
"outputs": [],
"source": [
"iris_deployment_file = path.join(iris_results_dir, \"iris_deployment.txt\")\n",
"iris_deployment_file = os.path.join(iris_results_dir, \"iris_deployment.txt\")\n",
"kh.deploy_model(\n",
" iris_model_kdic,\n",
" dictionary_name=\"SNB_Iris\",\n",
Expand Down Expand Up @@ -416,7 +444,7 @@
},
"outputs": [],
"source": [
"adult_deployment_file = path.join(adult_results_dir, \"adult_deployment.txt\")\n",
"adult_deployment_file = os.path.join(adult_results_dir, \"adult_deployment.txt\")\n",
"kh.deploy_model(\n",
" adult_model_kdic,\n",
" dictionary_name=\"SNB_Adult\",\n",
Expand Down Expand Up @@ -447,5 +475,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"nbformat_minor": 4
}
Loading