learninghouse


Namelearninghouse JSON
Version 1.7.4 PyPI version JSON
download
home_pagehttps://github.com/LearningHouseService/learninghouse-monorepo
SummarylearningHouse - Teach your smart home everything
upload_time2023-03-25 21:02:52
maintainer
docs_urlNone
authorJohannes Ott
requires_python>=3.7, <4
license
keywords smart home machine learning house automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # learningHouse Service 
[![License](https://img.shields.io/github/license/LearningHouseService/learninghouse)](https://github.com/LearningHouseService/learninghouse/blob/master/LICENSE) [![Release](https://img.shields.io/github/v/release/LearningHouseService/learninghouse)](https://github.com/LearningHouseService/learninghouse/releases/latest) [![Build Status](https://img.shields.io/github/actions/workflow/status/LearningHouseService/learninghouse/build_project.yml?branch=master)](https://github.com/LearningHouseService/learninghouse/actions/workflows/build_project.yml) [![PyPI version](https://img.shields.io/pypi/v/learninghouse.svg)](https://pypi.org/project/learninghouse/) [![Discord Chat](https://img.shields.io/discord/997393653758697482)](https://discord.gg/U9axHEYqqB)

![learningHouse Logo](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/artwork/learninghouse_logo.svg)

## Introduction

**learningHouse Service** provides machine learning algorithms based on scikit-learn python library as a RESTful API, with the purpose to give smart home fans an easy possibility to teach their homes.

## Contact and Feedback.

If you have any questions please get in contact with us on discord.

[![Discord Banner](https://discordapp.com/api/guilds/997393653758697482/widget.png?style=banner2)](https://discord.gg/U9axHEYqqB)

Please share your ideas what you want to teach your home, suggestions or problems by opening an [issue](https://github.com/LearningHouseService/learninghouse/issues). Really looking forward for your feedback.

## Installation and configuration

Install and update using pip.
```
pip install -U learninghouse
```

Install and update using docker
```
docker pull ghcr.io/learninghouseservice/learninghouse:latest
```

### Prepare configuration directory
```
mkdir -p brains
```

The `brains` directory holds the model configuration as json-file. The models are the brains of your learning house.

There will be one subdirectory per brain, where all files relevant for a brain will be stored.
The brain subdirectory needs a `config.json` holding the basic configuration. The service will store a `training_data.csv` holding
all data of your sensors and an object dump of the trained model to a file called `trained.pkl`.

### Service configuration

The service is configured by environment variables. Following options can be set:

Environment Variable             | default (production/development) | description                                            
-------------------------------- | -------------------------------- | ------------------------------------------------------ 
LEARNINGHOUSE_ENVIRONMENT        | production                       | Choose environment default settings production or development. 
LEARNINGHOUSE_HOST               | 127.0.0.1                        | Set address the service should bind. (use 0.0.0.0 for all available)
LEARNINGHOUSE_PORT               | 5000                             | Set the port the service should listen.
LEARNINGHOUSE_BASE_URL           | _Not set_                        | Set base url for external access
LEARNINGHOUSE_CONFIG_DIRECTORY   | ./brains                         | Define directory where all configuration data goes
LEARNINGHOUSE_OPENAPI_FILE       | /learninghouse_api.json          | File url path to OpenAPI json file
LEARNINGHOUSE_DOCS_URL           | /docs                            | Define url path for interactive [API documentation](#api-documentation). If you set to empty the documentation will be disabled.
LEARNINGHOUSE_JWT_SECRET         | _Generated on startup_           | For administration authentication there is a JWT generated after login. This is signed with this secret. By default it is generated on startup this will invalid existing JWTs on each restart.
LEARNINGHOUSE_JWT_EXPIRE_MINUTES | 10                               | JWTs refresh token will expire after given amount of minutes
LEARNINGHOUSE_LOGGING_LEVEL      | INFO                             | Set logging level to DEBUG, INFO, WARNING, ERROR, CRITICAL
LEARNINGHOUSE_DEBUG              | (False/True)                     | Debugger will be automatically activated in development environment. For security reasons it is recommended not to activate in production. 
LEARNINGHOUSE_RELOAD             | (False/True)                     | Reload of source will be automatically activated in development environment. For security reasons it is recommended not to activate in production. 

#### Example configuration

You can download [.env.example](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/core/.env.example) 
and rename it to `.env`. Inside you can modify default configuration values to your needs in this file.

## Run service 

### In console

Copy the [.env.example](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/core/.env.example)
to .env and modify it to your needs.

Then just run `learninghouse` to run the service. By default the service will listen to http://localhost:5000/

### With docker:

```
docker run --name learninghouse --rm -v brains:/learninghouse/brains -p 5000:5000 learninghouseservice/learninghouse:latest
```
## Security

The service is protected by different authentication and authorization mechanisms. For administration you have to generated a JWT by using POST request to `/api/auth/token` endpoint and use the resulting `access_token` as `Authorization: Bearer **access_token**` header to each requests. Access token will expire after 1 minute and can be refreshed by sending a PUT request to `/api/auth/token` using the `request_token` of the POST result within the expire time configured above as `LEARNINGHOUSE_JWT_EXPIRE_MINUTES`.

### Fallback password
On first run the service is set to use the fallback password `learninghouse`. Until this is not changed all other endpoints will be deactivated. 

Do following procedure to unlock service for usage:

**Security notice: Unless you use a proxy setup for SSL security of your connection, only use a seperate password for your learninghouse.**

1) Login using fallback password:

```
# URL is http://<host>:5000/api/auth/token
curl --location --request POST 'http://localhost:5000/api/auth/login' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "password": "learninghouse"
    }'
```

2) Change password
Take the returned access_token value for next call to change the fallback password to your own.

```
# URL is http://<host>:5000/api/auth/password
curl --location --request PUT 'http://localhost:5000/api/auth/password' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <access_token>' \
    --data-raw '{
        "old_password": "learninghouse",
        "new_password": "YOURPASSWORD"
    }'
```

### API Key

You can use the described JWT mechanism to use training and prediction endpoints as well, but for application access you can use an API key mechanism as well. There are two roles for API key authorization `user` for prediction endpoint and `trainer` for training and prediction endpoints.

Create a new API key like this:

```
# URL is http://<host>:5000/api/auth/apikey
curl --location --request POST 'http://localhost:5000/api/auth/apikey' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "description": "my_trainer_app",
        "role": "trainer"
    }'
```

Your API key will only displayed in this response and can not be requested again. So save it for your usage.
If you forget it you have to delete this API key and recreate.

```
# URL is http://<host>:5000/api/auth/apikey/{description}
curl --location --request DELETE 'http://localhost:5000/api/auth/apikey/my_trainer_app'
```

You have to give this API key to all requests either as query parameter `?api_key=YOURSECRETKEY` or as header field `X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY`.

## Brains and sensors configuration

### Sensors configuration

Send data of all sensors to **learningHouse Service** especially when training your brains. The service will save all data fields even if they are not used as a `feature` at the moment. The service will choose the best feature set each time you train a brain.

In general there are two different data types your sensor data can be divided in. `Numerical data` can be processed directly by your models. `Categorical data` has to be preproccesed by the service to be used as a `feature`. `Categorical data` can be identified by a simple rule:

**Non numerical values or if you can give each numerical value a term to describe it.**

Some examples for categorical data:

- pressure_trend: Values of 'falling', 'rising', 'consistent'
- month_of_year: 1 _('January')_, 2 _('Februrary')_, ...
- weather_condition: 'sunny', 'cloudy'
- switch: 'ON', 'OFF'

To enable the service to use the data of your sensors as `features` for your brain, you have to give the service information about the data type. For this put a `sensors.json` to the directory brains. List all your sensors and their data type.

Example content of sensors.json:

```
{
    "azimuth": "numerical",
    "elevation": "numerical",
    "rain_gauge": "numerical",
    "pressure": "numerical",
    "pressure_trend_1h": "categorical",
    "temperature_outside": "numerical",
    "temperature_trend_1h": "categorical",
    "light_state": "categorical"
}
```



### Example brain

The brain decides whether it is so dark that the light has to be switched on. It uses a machine learning algorithm called RandomForestClassifier.

Store a config.json in brains/darkness subdirectory with following content:

```
{
    "estimator": {
        "typed": "classifier",
        "estimators": 100, 
        "max_depth": 5
    }
    "dependent": "darkness",
    "dependent_encode": true,
    "test_size": 0.2
}
```

### Configuration parameter

#### Estimator

**LearningHouse Service** can predict values using an estimator. An estimator can be of type `classifier` which fits best for your needs if you have somekind of categorical output like in the example true and false. If you want to predict a numerical value for example the setpoint of an heating equipment use the type `regressor` instead.

For both types **learningHouse Service** uses a machine learning algorithm called random forest estimation. This algorithm builds a "forest" of decision trees with your `features` and takes the mean of the prediction of all of them to give you a best result. For more details see the API description of scikit-learn:

| Estimator type | API Reference |
|-----------------|-------------------|
| RandomForestRegressor | https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html#sklearn.ensemble.RandomForestRegressor |
| RandomForestClassifier | https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier |

You can adjust the amount of decision trees by using `estimators` (default: 100) option. And the maximum depth of each tree by using `max_depth` (default: 5) option. Both options are optional. Try to resize this value to optimize the accuracy of your model.


#### Dependent variable

The `dependent` variable is the one that have to be in the training data and which is predicted by the trained brain.

The `dependent` variable has to be a number. If it is not a number, but a string or boolean (true/false) like in the example. For this set `dependent_encode` to true.

#### Test size

LearningHouse service only uses a part of your training data to train the brain. The other part specified by `test_size` will be used to score the accuracy of your brain.

Give a percentage by using floating point numbers between 0.01 and 0.99 or a absolute number of data points by using integer numbers.

For the beginning a `test_size` of 20 % (0.2) like the example should be fine.

The accuracy between 80 % and 90 % between is a good score to gain. Below your brain is kind of underfitted and above overfitted, which both make it not working well for new data points to be predicted. You can try to change the [`estimator` configuration](#estimator) to gain a better score

Training of the brain will start, when there are at least 10 data points.

### Change configuration via RESTful API

You can change the configuration of sensors and brains although via the API. Visit the interactive [API documentation](#api-documentation) when the service is running.

The configuration endpoints are always protected by JWT authentication mechanism (see [Security](#security)).


## API Documentation

When the service is running, you can reach an interactive API documentation by calling url http://localhost:5000/docs

## Train brain

For training send a PUT request to the service:

_You need JWT or API key role `trainer` for this request (see [Security](#security))_

```
# URL is http://<host>:5000/api/brain/:name/training
curl --location --request PUT 'http://localhost:5000/api/brain/darkness/training' \
    --header 'Content-Type: application/json' \
    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \
    --data-raw '{
        "azimuth": 321.4441223144531,
        "elevation": -19.691608428955078,
        "rain_gauge": 0.0,
        "pressure": 971.0,
        "pressure_trend_1h": "falling",
        "temperature_outside": 23.0,
        "temperature_trend_1h": "rising",
        "light_state": false,
        "darkness": true
}'
```

You can send either a field `timestamp` with your dataset containing a UNIX-Timestamp or the service will add this information with its current time. The service generate some further time relevant fields inside the training dataset you can although use as `features`. These are `month_of_year`, `day_of_month`, `day_of_week`, `hour_of_day` and `minute_of_hour`

If one of your sensors is not working at the moment and for this not sending a value the service will add a value by using the following rules. For `categorical data` all categorical columns will be set to zero. For `numerical data` the mean of all known training set values (see [Test size](#test-size)) for this `feature` will be assumed.

To train the brain with existing data for example after a service update use a POST request without data:

_You need JWT or API key role `trainer` for this request (see [Security](#security))_

```
# URL is http://host:5000/api/brain/:name/training
curl --location \
    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \
    --request POST 'http://localhost:5000/api/brain/darkness/training'
```

To get the information about a trained brain use a GET request:


_You need JWT or API key role `trainer` or `user` for this request (see [Security](#security))_

```
# URL is http://host:5000/api/brain/:name/info
curl --location \
    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \ 
    --request GET 'http://localhost:5000/brain/darkness/info'
```

## Prediction

To predict a new data set with your brain send a POST request:

_You need JWT or API key role `trainer` or `user` for this request (see [Security](#security))_

```
# URL is http://host:5000/api/brain/:name/prediction
curl --location --request POST 'http://localhost:5000/api/brain/darkness/prediction' \
    --header 'Content-Type: application/json' \
    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \
    --data-raw '{    
        "azimuth": 321.4441223144531,
        "elevation": -19.691608428955078,
        "rain_gauge": 0.0,
        "pressure_trend_1h": "falling"
    }'
```

If one of your sensors used as `feature` in the brain is not working at the moment and for this not sending a value the service will add this by using following rules. For `categorical data` all categorical columns will be set to zero. For `numerical data` the mean of all known training set values (see [Test size](#test-size)) for this `feature` will be assumed.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LearningHouseService/learninghouse-monorepo",
    "name": "learninghouse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7, <4",
    "maintainer_email": "",
    "keywords": "smart home,machine learning,house automation",
    "author": "Johannes Ott",
    "author_email": "info@johannes-ott.net",
    "download_url": "https://files.pythonhosted.org/packages/26/43/76a277875e0d7fbe68d87406269ff0c281ad432755345ffe559f6bd020e1/learninghouse-1.7.4.tar.gz",
    "platform": null,
    "description": "# learningHouse Service \n[![License](https://img.shields.io/github/license/LearningHouseService/learninghouse)](https://github.com/LearningHouseService/learninghouse/blob/master/LICENSE) [![Release](https://img.shields.io/github/v/release/LearningHouseService/learninghouse)](https://github.com/LearningHouseService/learninghouse/releases/latest) [![Build Status](https://img.shields.io/github/actions/workflow/status/LearningHouseService/learninghouse/build_project.yml?branch=master)](https://github.com/LearningHouseService/learninghouse/actions/workflows/build_project.yml) [![PyPI version](https://img.shields.io/pypi/v/learninghouse.svg)](https://pypi.org/project/learninghouse/) [![Discord Chat](https://img.shields.io/discord/997393653758697482)](https://discord.gg/U9axHEYqqB)\n\n![learningHouse Logo](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/artwork/learninghouse_logo.svg)\n\n## Introduction\n\n**learningHouse Service** provides machine learning algorithms based on scikit-learn python library as a RESTful API, with the purpose to give smart home fans an easy possibility to teach their homes.\n\n## Contact and Feedback.\n\nIf you have any questions please get in contact with us on discord.\n\n[![Discord Banner](https://discordapp.com/api/guilds/997393653758697482/widget.png?style=banner2)](https://discord.gg/U9axHEYqqB)\n\nPlease share your ideas what you want to teach your home, suggestions or problems by opening an [issue](https://github.com/LearningHouseService/learninghouse/issues). Really looking forward for your feedback.\n\n## Installation and configuration\n\nInstall and update using pip.\n```\npip install -U learninghouse\n```\n\nInstall and update using docker\n```\ndocker pull ghcr.io/learninghouseservice/learninghouse:latest\n```\n\n### Prepare configuration directory\n```\nmkdir -p brains\n```\n\nThe `brains` directory holds the model configuration as json-file. The models are the brains of your learning house.\n\nThere will be one subdirectory per brain, where all files relevant for a brain will be stored.\nThe brain subdirectory needs a `config.json` holding the basic configuration. The service will store a `training_data.csv` holding\nall data of your sensors and an object dump of the trained model to a file called `trained.pkl`.\n\n### Service configuration\n\nThe service is configured by environment variables. Following options can be set:\n\nEnvironment Variable             | default (production/development) | description                                            \n-------------------------------- | -------------------------------- | ------------------------------------------------------ \nLEARNINGHOUSE_ENVIRONMENT        | production                       | Choose environment default settings production or development. \nLEARNINGHOUSE_HOST               | 127.0.0.1                        | Set address the service should bind. (use 0.0.0.0 for all available)\nLEARNINGHOUSE_PORT               | 5000                             | Set the port the service should listen.\nLEARNINGHOUSE_BASE_URL           | _Not set_                        | Set base url for external access\nLEARNINGHOUSE_CONFIG_DIRECTORY   | ./brains                         | Define directory where all configuration data goes\nLEARNINGHOUSE_OPENAPI_FILE       | /learninghouse_api.json          | File url path to OpenAPI json file\nLEARNINGHOUSE_DOCS_URL           | /docs                            | Define url path for interactive [API documentation](#api-documentation). If you set to empty the documentation will be disabled.\nLEARNINGHOUSE_JWT_SECRET         | _Generated on startup_           | For administration authentication there is a JWT generated after login. This is signed with this secret. By default it is generated on startup this will invalid existing JWTs on each restart.\nLEARNINGHOUSE_JWT_EXPIRE_MINUTES | 10                               | JWTs refresh token will expire after given amount of minutes\nLEARNINGHOUSE_LOGGING_LEVEL      | INFO                             | Set logging level to DEBUG, INFO, WARNING, ERROR, CRITICAL\nLEARNINGHOUSE_DEBUG              | (False/True)                     | Debugger will be automatically activated in development environment. For security reasons it is recommended not to activate in production. \nLEARNINGHOUSE_RELOAD             | (False/True)                     | Reload of source will be automatically activated in development environment. For security reasons it is recommended not to activate in production. \n\n#### Example configuration\n\nYou can download [.env.example](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/core/.env.example) \nand rename it to `.env`. Inside you can modify default configuration values to your needs in this file.\n\n## Run service \n\n### In console\n\nCopy the [.env.example](https://raw.githubusercontent.com/LearningHouseService/learninghouse/master/core/.env.example)\nto .env and modify it to your needs.\n\nThen just run `learninghouse` to run the service. By default the service will listen to http://localhost:5000/\n\n### With docker:\n\n```\ndocker run --name learninghouse --rm -v brains:/learninghouse/brains -p 5000:5000 learninghouseservice/learninghouse:latest\n```\n## Security\n\nThe service is protected by different authentication and authorization mechanisms. For administration you have to generated a JWT by using POST request to `/api/auth/token` endpoint and use the resulting `access_token` as `Authorization: Bearer **access_token**` header to each requests. Access token will expire after 1 minute and can be refreshed by sending a PUT request to `/api/auth/token` using the `request_token` of the POST result within the expire time configured above as `LEARNINGHOUSE_JWT_EXPIRE_MINUTES`.\n\n### Fallback password\nOn first run the service is set to use the fallback password `learninghouse`. Until this is not changed all other endpoints will be deactivated. \n\nDo following procedure to unlock service for usage:\n\n**Security notice: Unless you use a proxy setup for SSL security of your connection, only use a seperate password for your learninghouse.**\n\n1) Login using fallback password:\n\n```\n# URL is http://<host>:5000/api/auth/token\ncurl --location --request POST 'http://localhost:5000/api/auth/login' \\\n    --header 'Content-Type: application/json' \\\n    --data-raw '{\n        \"password\": \"learninghouse\"\n    }'\n```\n\n2) Change password\nTake the returned access_token value for next call to change the fallback password to your own.\n\n```\n# URL is http://<host>:5000/api/auth/password\ncurl --location --request PUT 'http://localhost:5000/api/auth/password' \\\n    --header 'Content-Type: application/json' \\\n    --header 'Authorization: Bearer <access_token>' \\\n    --data-raw '{\n        \"old_password\": \"learninghouse\",\n        \"new_password\": \"YOURPASSWORD\"\n    }'\n```\n\n### API Key\n\nYou can use the described JWT mechanism to use training and prediction endpoints as well, but for application access you can use an API key mechanism as well. There are two roles for API key authorization `user` for prediction endpoint and `trainer` for training and prediction endpoints.\n\nCreate a new API key like this:\n\n```\n# URL is http://<host>:5000/api/auth/apikey\ncurl --location --request POST 'http://localhost:5000/api/auth/apikey' \\\n    --header 'Content-Type: application/json' \\\n    --data-raw '{\n        \"description\": \"my_trainer_app\",\n        \"role\": \"trainer\"\n    }'\n```\n\nYour API key will only displayed in this response and can not be requested again. So save it for your usage.\nIf you forget it you have to delete this API key and recreate.\n\n```\n# URL is http://<host>:5000/api/auth/apikey/{description}\ncurl --location --request DELETE 'http://localhost:5000/api/auth/apikey/my_trainer_app'\n```\n\nYou have to give this API key to all requests either as query parameter `?api_key=YOURSECRETKEY` or as header field `X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY`.\n\n## Brains and sensors configuration\n\n### Sensors configuration\n\nSend data of all sensors to **learningHouse Service** especially when training your brains. The service will save all data fields even if they are not used as a `feature` at the moment. The service will choose the best feature set each time you train a brain.\n\nIn general there are two different data types your sensor data can be divided in. `Numerical data` can be processed directly by your models. `Categorical data` has to be preproccesed by the service to be used as a `feature`. `Categorical data` can be identified by a simple rule:\n\n**Non numerical values or if you can give each numerical value a term to describe it.**\n\nSome examples for categorical data:\n\n- pressure_trend: Values of 'falling', 'rising', 'consistent'\n- month_of_year: 1 _('January')_, 2 _('Februrary')_, ...\n- weather_condition: 'sunny', 'cloudy'\n- switch: 'ON', 'OFF'\n\nTo enable the service to use the data of your sensors as `features` for your brain, you have to give the service information about the data type. For this put a `sensors.json` to the directory brains. List all your sensors and their data type.\n\nExample content of sensors.json:\n\n```\n{\n    \"azimuth\": \"numerical\",\n    \"elevation\": \"numerical\",\n    \"rain_gauge\": \"numerical\",\n    \"pressure\": \"numerical\",\n    \"pressure_trend_1h\": \"categorical\",\n    \"temperature_outside\": \"numerical\",\n    \"temperature_trend_1h\": \"categorical\",\n    \"light_state\": \"categorical\"\n}\n```\n\n\n\n### Example brain\n\nThe brain decides whether it is so dark that the light has to be switched on. It uses a machine learning algorithm called RandomForestClassifier.\n\nStore a config.json in brains/darkness subdirectory with following content:\n\n```\n{\n    \"estimator\": {\n        \"typed\": \"classifier\",\n        \"estimators\": 100, \n        \"max_depth\": 5\n    }\n    \"dependent\": \"darkness\",\n    \"dependent_encode\": true,\n    \"test_size\": 0.2\n}\n```\n\n### Configuration parameter\n\n#### Estimator\n\n**LearningHouse Service** can predict values using an estimator. An estimator can be of type `classifier` which fits best for your needs if you have somekind of categorical output like in the example true and false. If you want to predict a numerical value for example the setpoint of an heating equipment use the type `regressor` instead.\n\nFor both types **learningHouse Service** uses a machine learning algorithm called random forest estimation. This algorithm builds a \"forest\" of decision trees with your `features` and takes the mean of the prediction of all of them to give you a best result. For more details see the API description of scikit-learn:\n\n| Estimator type | API Reference |\n|-----------------|-------------------|\n| RandomForestRegressor | https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html#sklearn.ensemble.RandomForestRegressor |\n| RandomForestClassifier | https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier |\n\nYou can adjust the amount of decision trees by using `estimators` (default: 100) option. And the maximum depth of each tree by using `max_depth` (default: 5) option. Both options are optional. Try to resize this value to optimize the accuracy of your model.\n\n\n#### Dependent variable\n\nThe `dependent` variable is the one that have to be in the training data and which is predicted by the trained brain.\n\nThe `dependent` variable has to be a number. If it is not a number, but a string or boolean (true/false) like in the example. For this set `dependent_encode` to true.\n\n#### Test size\n\nLearningHouse service only uses a part of your training data to train the brain. The other part specified by `test_size` will be used to score the accuracy of your brain.\n\nGive a percentage by using floating point numbers between 0.01 and 0.99 or a absolute number of data points by using integer numbers.\n\nFor the beginning a `test_size` of 20 % (0.2) like the example should be fine.\n\nThe accuracy between 80 % and 90 % between is a good score to gain. Below your brain is kind of underfitted and above overfitted, which both make it not working well for new data points to be predicted. You can try to change the [`estimator` configuration](#estimator) to gain a better score\n\nTraining of the brain will start, when there are at least 10 data points.\n\n### Change configuration via RESTful API\n\nYou can change the configuration of sensors and brains although via the API. Visit the interactive [API documentation](#api-documentation) when the service is running.\n\nThe configuration endpoints are always protected by JWT authentication mechanism (see [Security](#security)).\n\n\n## API Documentation\n\nWhen the service is running, you can reach an interactive API documentation by calling url http://localhost:5000/docs\n\n## Train brain\n\nFor training send a PUT request to the service:\n\n_You need JWT or API key role `trainer` for this request (see [Security](#security))_\n\n```\n# URL is http://<host>:5000/api/brain/:name/training\ncurl --location --request PUT 'http://localhost:5000/api/brain/darkness/training' \\\n    --header 'Content-Type: application/json' \\\n    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \\\n    --data-raw '{\n        \"azimuth\": 321.4441223144531,\n        \"elevation\": -19.691608428955078,\n        \"rain_gauge\": 0.0,\n        \"pressure\": 971.0,\n        \"pressure_trend_1h\": \"falling\",\n        \"temperature_outside\": 23.0,\n        \"temperature_trend_1h\": \"rising\",\n        \"light_state\": false,\n        \"darkness\": true\n}'\n```\n\nYou can send either a field `timestamp` with your dataset containing a UNIX-Timestamp or the service will add this information with its current time. The service generate some further time relevant fields inside the training dataset you can although use as `features`. These are `month_of_year`, `day_of_month`, `day_of_week`, `hour_of_day` and `minute_of_hour`\n\nIf one of your sensors is not working at the moment and for this not sending a value the service will add a value by using the following rules. For `categorical data` all categorical columns will be set to zero. For `numerical data` the mean of all known training set values (see [Test size](#test-size)) for this `feature` will be assumed.\n\nTo train the brain with existing data for example after a service update use a POST request without data:\n\n_You need JWT or API key role `trainer` for this request (see [Security](#security))_\n\n```\n# URL is http://host:5000/api/brain/:name/training\ncurl --location \\\n    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \\\n    --request POST 'http://localhost:5000/api/brain/darkness/training'\n```\n\nTo get the information about a trained brain use a GET request:\n\n\n_You need JWT or API key role `trainer` or `user` for this request (see [Security](#security))_\n\n```\n# URL is http://host:5000/api/brain/:name/info\ncurl --location \\\n    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \\ \n    --request GET 'http://localhost:5000/brain/darkness/info'\n```\n\n## Prediction\n\nTo predict a new data set with your brain send a POST request:\n\n_You need JWT or API key role `trainer` or `user` for this request (see [Security](#security))_\n\n```\n# URL is http://host:5000/api/brain/:name/prediction\ncurl --location --request POST 'http://localhost:5000/api/brain/darkness/prediction' \\\n    --header 'Content-Type: application/json' \\\n    --header 'X-LEARNINGHOUSE-API-KEY: YOURSECRETKEY' \\\n    --data-raw '{    \n        \"azimuth\": 321.4441223144531,\n        \"elevation\": -19.691608428955078,\n        \"rain_gauge\": 0.0,\n        \"pressure_trend_1h\": \"falling\"\n    }'\n```\n\nIf one of your sensors used as `feature` in the brain is not working at the moment and for this not sending a value the service will add this by using following rules. For `categorical data` all categorical columns will be set to zero. For `numerical data` the mean of all known training set values (see [Test size](#test-size)) for this `feature` will be assumed.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "learningHouse - Teach your smart home everything",
    "version": "1.7.4",
    "split_keywords": [
        "smart home",
        "machine learning",
        "house automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92752dcd0c3b56b19fdff710b6adf7cd91335eea83242c3f34dbb7aefbd64cd5",
                "md5": "151fd2072056277bb62e72d60720c37c",
                "sha256": "8523a28ef6262a123bc7225e7bd84e28888aa2865183310343380ea77788b3d2"
            },
            "downloads": -1,
            "filename": "learninghouse-1.7.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "151fd2072056277bb62e72d60720c37c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7, <4",
            "size": 2758429,
            "upload_time": "2023-03-25T21:02:50",
            "upload_time_iso_8601": "2023-03-25T21:02:50.276443Z",
            "url": "https://files.pythonhosted.org/packages/92/75/2dcd0c3b56b19fdff710b6adf7cd91335eea83242c3f34dbb7aefbd64cd5/learninghouse-1.7.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "264376a277875e0d7fbe68d87406269ff0c281ad432755345ffe559f6bd020e1",
                "md5": "36ae45bb934f3eb258030f28ca3c1199",
                "sha256": "a7f34732dc33e9c439ccf58461c162f73910be022d02188d0017fb11a00ae698"
            },
            "downloads": -1,
            "filename": "learninghouse-1.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "36ae45bb934f3eb258030f28ca3c1199",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7, <4",
            "size": 2752487,
            "upload_time": "2023-03-25T21:02:52",
            "upload_time_iso_8601": "2023-03-25T21:02:52.453389Z",
            "url": "https://files.pythonhosted.org/packages/26/43/76a277875e0d7fbe68d87406269ff0c281ad432755345ffe559f6bd020e1/learninghouse-1.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-25 21:02:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "LearningHouseService",
    "github_project": "learninghouse-monorepo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "learninghouse"
}
        
Elapsed time: 0.06526s