Skip to content

Commit 0a1bd5c

Browse files
authored
Merge pull request #173 from aimclub/fix/land_use_classification
Fix/land use classification
2 parents ad2a532 + 3b14461 commit 0a1bd5c

8 files changed

Lines changed: 541 additions & 247 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ pip install blocksnet
7575

7676
There are various extras to install:
7777

78-
- `ml` - machine learning related packages (`torch`, `catboost`, etc).
78+
- `ml` - machine learning related packages (`catboost`, `lightgmb` etc).
79+
- `torch` - torch related packages (`torch`, `torch_geometric`).
7980
- `opt` - optimization problem related packages (`optuna`, `pymoo`).
80-
- `full` - all packages required by blocksnet methods (`ml` + `opt` extras).
81+
- `full` - all packages required by blocksnet methods (`ml` + `torch` + `opt` extras).
8182
- `ipynb` - jupyter notebook visualization packages (`matplotlib`, etc).
8283
- `tests` (DEVELOPMENT ONLY) - pytest related packages.
8384
- `docs` (DEVELOPMENT ONLY) - sphinx documentation related packages.
@@ -162,7 +163,7 @@ The repository includes the following directories and modules:
162163
- [`blocks`](blocksnet/blocks) - methods to generate, aggregate and process urban blocks.
163164
- [`config`](blocksnet/config) - config to handle logging and meta information (service types, land use relations, etc).
164165
- [`enums`](blocksnet/enums) - enums used within the code base.
165-
- [`machine_learning`](blocksnet/machine_learning) - machine learning strategies for different packages. Requires `ml` extra (`pip install blocksnet[ml]`).
166+
- [`machine_learning`](blocksnet/machine_learning) - machine learning strategies for different packages. Requires `ml` and `torch` (optional) extras (`pip install blocksnet[ml,torch]`).
166167
- [`optimization`](blocksnet/optimization) - optimization related methods. Requires the `opt` extra (`pip install blocksnet[opt]`).
167168
- [`preprocessing`](blocksnet/preprocessing) - data imputing and preprocessing.
168169
- [`relations`](blocksnet/relations) - methods to handle network graphs and accessibility matrices.

blocksnet/analysis/land_use/prediction/_strategy.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
("hgb", HistGradientBoostingClassifier(**MODEL_PARAMS["hgb"])),
5151
]
5252

53-
strategy = SKLearnVotingClassificationStrategy(estimators)
54-
strategy.load(ARTIFACTS_DIRECTORY)
53+
def get_default_strategy() -> SKLearnVotingClassificationStrategy:
54+
strategy = SKLearnVotingClassificationStrategy(estimators)
55+
strategy.load(ARTIFACTS_DIRECTORY)
56+
print(ARTIFACTS_DIRECTORY)
57+
return strategy
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"strategy_cls": "SKLearnVotingClassificationStrategy", "model_cls": "VotingClassifier", "model_params": {"voting": "soft", "n_jobs": -1}}
1+
{"strategy_cls": "SKLearnVotingClassificationStrategy", "model_cls": "VotingClassifier", "model_params": {"voting": "soft", "n_jobs": -1}}
464 KB
Binary file not shown.

blocksnet/analysis/land_use/prediction/core.py

Lines changed: 94 additions & 93 deletions
Large diffs are not rendered by default.

blocksnet/analysis/land_use/prediction/schemas.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
import pandas as pd
22
from pandera.typing import Series
3-
from shapely import MultiPolygon, Polygon
3+
from shapely import Polygon
44
from blocksnet.enums import LandUseCategory
55
from blocksnet.utils.validation import GdfSchema, LandUseSchema
66

77

8-
class BlocksInputSchema(GdfSchema):
9-
category: Series
8+
class BlocksRunSchema(GdfSchema):
9+
10+
# @classmethod
11+
# def _after_validate(cls, df: pd.DataFrame) -> pd.DataFrame:
12+
# if not 'category' in df:
13+
# df['category'] = None
14+
# return df
1015

1116
@classmethod
1217
def _geometry_types(cls):
13-
return [Polygon | MultiPolygon]
18+
return {Polygon}
19+
20+
21+
class BlocksTrainSchema(BlocksRunSchema):
22+
23+
category: Series
1424

1525
@classmethod
1626
def _before_validate(cls, df: pd.DataFrame) -> pd.DataFrame:
1727
df = df.copy()
1828

1929
if "category" in df.columns:
30+
2031
def parse_category(c):
2132
if isinstance(c, LandUseCategory):
2233
return c
@@ -35,4 +46,3 @@ def to_category(lu):
3546
df["category"] = lu_df["land_use"].map(to_category)
3647

3748
return df
38-

examples/analysis/land_use/prediction.ipynb

Lines changed: 418 additions & 134 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,17 @@ version_scheme = "post-release"
4646
local_scheme = "no-local-version"
4747

4848
[project.optional-dependencies]
49-
ml = [
50-
"pygeoops",
51-
"featuretools",
52-
"torch",
53-
"torch_geometric",
54-
'catboost',
55-
'xgboost',
56-
]
49+
ml = ["pygeoops", "featuretools", 'catboost', 'xgboost', 'lightgbm']
50+
torch = ["torch", "torch_geometric"]
5751
opt = ["optuna>=4.1.0,<5.0.0", "pymoo>=0.6.0,<1.0.0"]
58-
full = ["blocksnet[ml, opt]"]
52+
full = ["blocksnet[ml, torch, opt]"]
5953

6054
ipynb = [
6155
"mapclassify==2.6.1", #jupyter maps
6256
"matplotlib-inline==0.1.6", #jupyter plots
6357
"folium==0.14.0", #jupyter maps
6458
"matplotlib>=3.9.0,<4.0.0",
59+
"ipywidgets",
6560
]
6661

6762
tests = ["pytest==7.4.3", "pytest-cov==4.1.0"]

0 commit comments

Comments
 (0)