Skip to content

Commit

Permalink
Add python 3.11 to MLBlocks (#143)
Browse files Browse the repository at this point in the history
* test python 3.11

* pin lightfm

* update pip

* fix syntax

* add wheel

* fix data loading

* fix readme example

* remove data
  • Loading branch information
sarahmish authored Sep 26, 2023
1 parent ec84335 commit 21f0df5
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 54 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: pip install -U pip setuptools wheel
- name: Install lightfm
run: python -m pip install --no-use-pep517 'lightfm<2'
- name: Install package
run: pip install .[dev]
- name: make test-devel
Expand All @@ -36,6 +40,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: pip install -U pip setuptools wheel
- name: Install lightfm
run: python -m pip install --no-use-pep517 'lightfm<2'
- name: Install package and dependencies
run: pip install rundoc .[mlprimitives]
- name: make test-readme
Expand All @@ -45,7 +53,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
os: [ubuntu-20.04, macos-latest]
steps:
- uses: actions/checkout@v1
Expand All @@ -70,6 +78,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: pip install -U pip setuptools wheel
- name: Install lightfm
run: python -m pip install --no-use-pep517 'lightfm<2'
- name: Install package and dependencies
run: pip install .[test]
- name: make test-mlprimitives
Expand All @@ -90,6 +102,10 @@ jobs:
- if: matrix.os == 'ubuntu-20.04'
name: Install dependencies - Ubuntu
run: sudo apt-get install graphviz
- name: Upgrade pip
run: pip install -U pip setuptools wheel
- name: Install lightfm
run: python -m pip install --no-use-pep517 'lightfm<2'
- name: Install package and dependencies
run: pip install .[examples]
- name: make test-tutorials
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ pipeline which combines primitives from [MLPrimitives](https://github.com/MLBaza
[scikit-learn](https://scikit-learn.org/) and [xgboost](https://xgboost.readthedocs.io/).

```python3
import pandas as pd
from mlblocks import MLPipeline
from mlprimitives.datasets import load_dataset
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

dataset = load_dataset('census')
X_train, X_test, y_train, y_test = dataset.get_splits(1)
dataset = pd.read_csv('http://mlblocks.s3.amazonaws.com/census.csv')
label = dataset.pop('label')

X_train, X_test, y_train, y_test = train_test_split(dataset, label, stratify=label)

primitives = [
'mlprimitives.custom.preprocessing.ClassEncoder',
Expand All @@ -104,7 +108,7 @@ pipeline = MLPipeline(primitives)
pipeline.fit(X_train, y_train)
predictions = pipeline.predict(X_test)

dataset.score(y_test, predictions)
accuracy_score(y_test, predictions)
```

# What's Next?
Expand Down
14 changes: 10 additions & 4 deletions docs/getting_started/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ labels.
.. ipython:: python
:okwarning:
from mlprimitives.datasets import load_census
dataset = load_census()
X_train, X_test, y_train, y_test = dataset.get_splits(1)
import pandas as pd
from sklearn.model_selection import train_test_split
dataset = pd.read_csv('http://mlblocks.s3.amazonaws.com/census.csv')
label = dataset.pop('label')
X_train, X_test, y_train, y_test = train_test_split(dataset, label, stratify=label)
pipeline.fit(X_train, y_train)
Once we have fitted our model to our data, we can call the ``predict`` method passing new data
Expand All @@ -115,9 +119,11 @@ to obtain predictions from the pipeline.
.. ipython:: python
:okwarning:
from sklearn.metrics import accuracy_score
predictions = pipeline.predict(X_test)
predictions
dataset.score(y_test, predictions)
accuracy_score(y_test, predictions)
.. _you have already installed them: install.html#additional-dependencies
.. _MLPipeline class: ../api_reference.html#mlblocks.MLPipeline
Expand Down
23 changes: 15 additions & 8 deletions examples/tutorials/1. Using and MLPipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"metadata": {},
"outputs": [],
"source": [
"from mlprimitives.datasets import load_dataset\n",
"from utils import load_census\n",
"\n",
"dataset = load_dataset('census')"
"dataset = load_census()"
]
},
{
Expand Down Expand Up @@ -528,7 +528,16 @@
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
}
],
"source": [
"pipeline.fit(X_train, y_train)"
]
Expand All @@ -546,9 +555,7 @@
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"predictions = pipeline.predict(X_test)"
Expand Down Expand Up @@ -611,7 +618,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -625,7 +632,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
24 changes: 20 additions & 4 deletions examples/tutorials/3. Setting MLPipeline Hyperparameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"from mlprimitives.datasets import load_dataset\n",
"from utils import load_census\n",
"\n",
"dataset = load_dataset('census')\n",
"dataset = load_census()\n",
"X_train, X_test, y_train, y_test = dataset.get_splits(1)"
]
},
Expand Down Expand Up @@ -268,6 +268,14 @@
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
Expand Down Expand Up @@ -394,6 +402,14 @@
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
Expand All @@ -415,7 +431,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -429,7 +445,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
19 changes: 14 additions & 5 deletions examples/tutorials/4. Saving and Loading a Pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"metadata": {},
"outputs": [],
"source": [
"from mlprimitives.datasets import load_dataset\n",
"from utils import load_census\n",
"\n",
"dataset = load_dataset('census')"
"dataset = load_census()"
]
},
{
Expand Down Expand Up @@ -71,7 +71,16 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
}
],
"source": [
"pipeline.fit(X_train, y_train)"
]
Expand Down Expand Up @@ -166,7 +175,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -180,7 +189,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"metadata": {},
"outputs": [],
"source": [
"from mlprimitives.datasets import load_dataset\n",
"from utils import load_census\n",
"\n",
"dataset = load_dataset('census')"
"dataset = load_census()"
]
},
{
Expand Down Expand Up @@ -430,7 +430,16 @@
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
}
],
"source": [
"fit_context = pipeline.fit(start_=1, output_=2, **fit_context)"
]
Expand Down Expand Up @@ -690,7 +699,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -704,7 +713,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
30 changes: 24 additions & 6 deletions examples/tutorials/6. Flexible outputs specification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"from mlprimitives.datasets import load_dataset\n",
"from utils import load_census\n",
"\n",
"dataset = load_dataset('census')"
"dataset = load_census()"
]
},
{
Expand Down Expand Up @@ -420,7 +420,16 @@
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
}
],
"source": [
"output_spec = [\n",
" 'sklearn.impute.SimpleImputer#1.X',\n",
Expand All @@ -441,7 +450,16 @@
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/sarah/anaconda3/envs/mlp/lib/python3.8/site-packages/sklearn/impute/_base.py:382: FutureWarning: The 'verbose' parameter was deprecated in version 1.1 and will be removed in 1.3. A warning will always be raised upon the removal of empty columns in the future version.\n",
" warnings.warn(\n"
]
}
],
"source": [
"output_spec = [\n",
" 'mlprimitives.custom.feature_extraction.CategoricalEncoder#1.X',\n",
Expand Down Expand Up @@ -495,7 +513,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -509,7 +527,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 21f0df5

Please sign in to comment.