Skip to main content

image

neuro-ml is a open source library designed to avoid writing duplicate code.

You can use new model of scikit learn without writing any code. Model training can be control by configuration file.

neuro_mf.ModelFactory

class neuro_mf.ModelFactory(model_config_path:str) source


Parameters:

model_config_path: location of model.yaml file

How to generate configuration file
It is very simple.
We will export sample model config file in config directory
You can use below python to export sample configuration file.

```python
from neuro_mf.config import get_sample_model_config_yaml_file

if __name__ == "__main__":
    export_file_path=get_sample_model_config_yaml_file(export_dir="config")

Check your config folder You will find a file name as "model.yaml"

content of model.yaml

grid_search:
  class: GridSearchCV
  module: sklearn.model_selection
  params:
    cv: 3
    verbose: 1
model_selection:
  module_0:
    class: ModelClassName
    module: module_of_model
    params:
      param_name1: value1
      param_name2: value2
    search_param_grid:
      param_name:
      - param_value_1
      - param_value_2
  

Now update the content of model.yaml file with below content for testing.

grid_search:
  class: GridSearchCV
  module: sklearn.model_selection
  params:
    cv: 3
    verbose: 1
model_selection:
  module_0:
    class: RandomForestRegressor
    module: sklearn.ensemble
    params:
      n_estimators: 200
      criterion: squared_error
    search_param_grid:
      n_estimators:
      - 150
      - 200
      - 250
      max_depth:
      - 2
      - 5
      - 6
  module_1:
    class: SVR
    module: sklearn.svm
    params:
      kernel: rbf
    search_param_grid:
      kernel:
      - poly
      - rbf

Attributes:

config: dict model.yaml file will be available as dict in this attribute

grid_search_cv_module: str Module of grid search cv from sklearn lib sklearn.model_selection

grid_search_class_name: str

grid_search_property_data:dict

models_initialization_config: dict

initialized_model_list: All model instance will be available in this attribute once get_initialized_model_list has been invoked on model factory object

grid_searched_best_model_list Once grid search has been done for all model then every model with their tuned paramter will be available in this attribute

Few of the function return type can be inferred using below named tuple

InitializedModelDetail = namedtuple("InitializedModelDetail",
                                    ["model_serial_number", "model", "param_grid_search", "model_name"])

GridSearchedBestModel = namedtuple("GridSearchedBestModel", ["model_serial_number",
                                                             "model",
                                                             "best_model",
                                                             "best_parameters",
                                                             "best_score",
                                                             ])

BestModel = namedtuple("BestModel", ["model_serial_number",
                                     "model",
                                     "best_model",
                                     "best_parameters",
                                     "best_score", ])


Methods:
class_for_name(module_name, class_name)
execute_grid_search_operation(self, initialized_model: InitializedModelDetail, input_feature, output_feature)
get_best_model(self, X, y, base_accuracy=0.6) -> BestModel
get_best_model_from_grid_searched_best_model_list(grid_searched_best_model_list: List[GridSearchedBestModel], base_accuracy=0.6 ) -> BestModel
get_initialized_model_list(self) -> List[InitializedModelDetail]
initiate_best_parameter_search_for_initialized_model(self, initialized_model: InitializedModelDetail, input_feature, output_feature) -> GridSearchedBestModel
initiate_best_parameter_search_for_initialized_models(self, initialized_model_list: List[InitializedModelDetail], input_feature, output_feature) -> List[GridSearchedBestModel]
read_params
update_property_of_class

How to generate configuration file It is very simple. We will export sample model config file in config directory You can use below python to export sample configuration file.

from neuro_mf.config import get_sample_model_config_yaml_file

if __name__ == "__main__":
    export_file_path=get_sample_model_config_yaml_file(export_dir="config")

Check your config folder You will find a file name as "model.yaml"

content of model.yaml

grid_search:
  class: GridSearchCV
  module: sklearn.model_selection
  params:
    cv: 3
    verbose: 1
model_selection:
  module_0:
    class: ModelClassName
    module: module_of_model
    params:
      param_name1: value1
      param_name2: value2
    search_param_grid:
      param_name:
      - param_value_1
      - param_value_2
  

Now update the content of model.yaml file with below content for testing.

grid_search:
  class: GridSearchCV
  module: sklearn.model_selection
  params:
    cv: 3
    verbose: 1
model_selection:
  module_0:
    class: RandomForestRegressor
    module: sklearn.ensemble
    params:
      n_estimators: 200
      criterion: squared_error
    search_param_grid:
      n_estimators:
      - 150
      - 200
      - 250
      max_depth:
      - 2
      - 5
      - 6
    module_1:
        class: SVR
        module: sklearn.svm
        params:
          kernel: rbf
        search_param_grid:
          kernel:
          - poly
          - rbf

Above configuration file contains information about two model Random Forest and Support Vector

get_best_model_function will return best model after comparison

Now Let's try to train a RandomForestRegressor

import os

from neuro_mf.config import get_sample_model_config_yaml_file
from neuro_mf import ModelFactory

if __name__ == "__main__":
    # export_dir=get_sample_model_config_yaml_file(export_dir="config")
    export_file_path = os.path.join("config", "model.yaml")
    model_factory = ModelFactory(model_config_path=export_file_path)
    x = None  # input feature
    y = None  # target feature
    best_model = model_factory.get_best_model(x, y, base_accuracy=0.9)
    print(best_model.best_model)
    print(f"best score:{best_model.best_score}")

Metadata

Release files for neuro-mf 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neuro-mf 0.0.5
File Size Uploaded Provenance
neuro_mf-0.0.5.tar.gz 9.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for neuro-mf 0.0.5
File Interpreter ABI Platform
neuro_mf-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / neuro_mf-0.0.5.tar.gz

Download URL neuro_mf-0.0.5.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6d0fc99e53f8b1cd93eb54346853f570feec13958ecef177fb025931a3792dc8
BLAKE2b-256 checksum
How to use checksums
b32e611f7f8dcc0c3752d7a1f56ef54d571520a84df3d13aab48ed21841024f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / neuro_mf-0.0.5-py3-none-any.whl

Download URL neuro_mf-0.0.5-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f990693c065b39f286b900426fc61c82c2d9a08b13258ef097df774448d465a
BLAKE2b-256 checksum
How to use checksums
4fa90945130e9537336dc6796bd5db87e31ca95bc99f806dfe8315c1d3ef3b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for neuro-mf 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page