# Introduction of BMINet
<!-- ![framework](Example/image.png) -->
Machine learning and network based tool for:
- Classify and predict different disease stages precisely
- Understand machenism using SHAP model explanation
- Detect Bone-Muscle Interact network and detect disease modules
# Install
## Dependency
- **Python>=3.9**
## Quick install
- Install from pypi: `pip install BMINet`
- Or install from GitHub:
```
git clone https://github.com/Spencer-JRWang/BMINet
cd BMINet
pip install .
```
# Example Usage
- First, you should prepare your data (from CT or MRI etc.): [Example Data](Example/data.txt)
- Load your data
```python
import pandas as pd
df = pd.read_csv('Example/data.txt', sep='\t')
```
- Select features
```python
# Load FeatureSelector
from BMINet.Interaction import FeatureSelector
selector = FeatureSelector(core_name="LightGBM")
# Conduct feature selection from df
selected_features = selector.select(df)
```
> core_name should be "LightGBM", "XGBoost" or "CatBoost"
- Build stacking model
```python
from BMINet.Interaction import StackingModel
# Load stacking model framework
'''
default: StackingModel(
base_models = [
('LGBM', LGBMClassifier(verbose=-1, n_estimators=1000, max_depth=5)),
('XGBoost', XGBClassifier(n_estimators=1000, max_depth=5)),
('CatBoost', CatBoostClassifier(verbose=False, iterations=800, max_depth=5))
]),
meta_model = LogisticRegression()
'''
Model = StackingModel()
best_scores = Model.stacking_model_search(df, selected_features)
```
> Using default base model and meta model, you can also define it yourself
- Predict of each group
```python
# single predict
single_prediction_score = Model.single_predict("A vs B", [...], use_our_model=True)
# multiple predict
multiple_prediction_score = Model.multiple_predict_predict("A vs B", [[...], [...],], use_our_model=True)
```
> If you use `use_our model = True`, you are predicting disease staged based on our data and model
>
> If you are researching on a brand new project, use `use_our_model = False`
- Basic machine learning plots
```python
from BMINet.plot import plot_ml_roc
plot_ml_roc(best_scores)
from BMINet.plot import plot_precision_recall
plot_precision_recall(best_scores)
from BMINet.plot import plot_score_histogram
plot_score_histogram(best_scores)
from BMINet.plot import plot_calibration_curve
plot_calibration_curve(best_scores)
```
- Model Explanation
```python
from BMINet.Interaction import SHAPVisualizer
# Load explanation class and train it
shap_visualizer = SHAPVisualizer(core_name="LightGBM")
shap_visualizer.train_model(df, selected_features)
# The dir you want to save the files
shap_visualizer.plot_shap('./Example')
shap_visualizer.plot_dependence('./Example')
```
- Network Construction
```python
# Load NetworkConstructor
from BMINet.Interaction import NetworkConstructor
network_constructor = NetworkConstructor(core_name="LightGBM", cutoff = 1.5)
# Construct sub-network list for each group
interactions = network_constructor.construct_network(df, selected_features)
# Construct conmbined network
combined_graph = network_constructor.compose_all(interactions)
# Remove isolated nodes from the network
Graph_BMI = network_constructor.remove_isolated_nodes(combined_graph)
# Save to .graphml file
network_constructor.save_graph(Graph_BMI, './Example')
```
- Network Analysis
```python
from BMINet.Interaction import NetworkMetrics
metrics_calculator = NetworkMetrics(Graph_BMI)
metrics = metrics_calculator.compute_metrics()
```
> You can see more Example usage at [here](https://github.com/Spencer-JRWang/BMINet/blob/main/Example.ipynb)
# Update Log
- 2024/8/28: Version `0.0.1`, test version
- 2024/8/28: Version `0.0.2`, test version, update discription
- 2024/8/28: Version `0.0.3`, test version, fix a bug
- 2024/8/28: Version `0.0.4`, test version, fix python dependency
- 2024/8/28: Version `0.0.5`, test version, fix a bug
- 2024/8/31: Version `0.0.6`, test version, update trained model
- 2024/8/31: Version `0.0.7`, test version, fix a bug
- 2024/8/31: Version `0.0.8`, test version, fix a bug
- 2024/8/31: Version `0.0.9`, test version, fix a bug
- 2024/9/1: Version `0.0.10`, test version, fix a bug
- 2024/9/1: Version `0.0.11`, test version, fix a bug
- 2024/9/3: Version `0.0.12`, test version, fix a bug
- 2024/9/3: Version `0.0.13`, test version, fix a numpy dependency bug and use_our_model prediction
Raw data
{
"_id": null,
"home_page": null,
"name": "BMINet",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "python, BMINet, Interaction, Network, Bone-Muscle, windows, mac, linux",
"author": "Spencer Wang",
"author_email": "jrwangspencer@stu.suda.edu.cn",
"download_url": "https://files.pythonhosted.org/packages/fd/58/d3bbd1f76edeebacbb76bf8bebb6eb90d4f685bc223f520fe2c8c863ab05/bminet-0.0.13.tar.gz",
"platform": null,
"description": "\n# Introduction of BMINet\n<!-- ![framework](Example/image.png) -->\nMachine learning and network based tool for:\n- Classify and predict different disease stages precisely\n- Understand machenism using SHAP model explanation\n- Detect Bone-Muscle Interact network and detect disease modules\n# Install\n## Dependency\n- **Python>=3.9**\n## Quick install\n- Install from pypi: `pip install BMINet`\n- Or install from GitHub: \n```\ngit clone https://github.com/Spencer-JRWang/BMINet\ncd BMINet\npip install .\n```\n# Example Usage\n- First, you should prepare your data (from CT or MRI etc.): [Example Data](Example/data.txt)\n- Load your data\n```python\nimport pandas as pd\ndf = pd.read_csv('Example/data.txt', sep='\\t')\n```\n- Select features\n```python\n# Load FeatureSelector\nfrom BMINet.Interaction import FeatureSelector\nselector = FeatureSelector(core_name=\"LightGBM\")\n# Conduct feature selection from df\nselected_features = selector.select(df)\n```\n> core_name should be \"LightGBM\", \"XGBoost\" or \"CatBoost\"\n- Build stacking model\n```python\nfrom BMINet.Interaction import StackingModel\n# Load stacking model framework\n'''\ndefault: StackingModel(\n base_models = [\n ('LGBM', LGBMClassifier(verbose=-1, n_estimators=1000, max_depth=5)),\n ('XGBoost', XGBClassifier(n_estimators=1000, max_depth=5)),\n ('CatBoost', CatBoostClassifier(verbose=False, iterations=800, max_depth=5))\n ]), \n meta_model = LogisticRegression()\n'''\nModel = StackingModel()\nbest_scores = Model.stacking_model_search(df, selected_features)\n```\n> Using default base model and meta model, you can also define it yourself\n\n- Predict of each group\n```python\n# single predict\nsingle_prediction_score = Model.single_predict(\"A vs B\", [...], use_our_model=True)\n# multiple predict\nmultiple_prediction_score = Model.multiple_predict_predict(\"A vs B\", [[...], [...],], use_our_model=True)\n```\n> If you use `use_our model = True`, you are predicting disease staged based on our data and model\n> \n> If you are researching on a brand new project, use `use_our_model = False`\n\n- Basic machine learning plots\n```python\nfrom BMINet.plot import plot_ml_roc\nplot_ml_roc(best_scores)\nfrom BMINet.plot import plot_precision_recall\nplot_precision_recall(best_scores)\nfrom BMINet.plot import plot_score_histogram\nplot_score_histogram(best_scores)\nfrom BMINet.plot import plot_calibration_curve\nplot_calibration_curve(best_scores)\n```\n- Model Explanation\n```python\nfrom BMINet.Interaction import SHAPVisualizer\n# Load explanation class and train it\nshap_visualizer = SHAPVisualizer(core_name=\"LightGBM\")\nshap_visualizer.train_model(df, selected_features)\n# The dir you want to save the files\nshap_visualizer.plot_shap('./Example')\nshap_visualizer.plot_dependence('./Example')\n```\n\n- Network Construction\n```python\n# Load NetworkConstructor\nfrom BMINet.Interaction import NetworkConstructor\nnetwork_constructor = NetworkConstructor(core_name=\"LightGBM\", cutoff = 1.5)\n\n# Construct sub-network list for each group\ninteractions = network_constructor.construct_network(df, selected_features)\n# Construct conmbined network\ncombined_graph = network_constructor.compose_all(interactions)\n# Remove isolated nodes from the network\nGraph_BMI = network_constructor.remove_isolated_nodes(combined_graph)\n# Save to .graphml file\nnetwork_constructor.save_graph(Graph_BMI, './Example')\n```\n\n- Network Analysis\n```python\nfrom BMINet.Interaction import NetworkMetrics\nmetrics_calculator = NetworkMetrics(Graph_BMI)\nmetrics = metrics_calculator.compute_metrics()\n```\n\n> You can see more Example usage at [here](https://github.com/Spencer-JRWang/BMINet/blob/main/Example.ipynb)\n\n# Update Log\n- 2024/8/28: Version `0.0.1`, test version\n- 2024/8/28: Version `0.0.2`, test version, update discription\n- 2024/8/28: Version `0.0.3`, test version, fix a bug\n- 2024/8/28: Version `0.0.4`, test version, fix python dependency\n- 2024/8/28: Version `0.0.5`, test version, fix a bug\n- 2024/8/31: Version `0.0.6`, test version, update trained model\n- 2024/8/31: Version `0.0.7`, test version, fix a bug\n- 2024/8/31: Version `0.0.8`, test version, fix a bug\n- 2024/8/31: Version `0.0.9`, test version, fix a bug\n- 2024/9/1: Version `0.0.10`, test version, fix a bug\n- 2024/9/1: Version `0.0.11`, test version, fix a bug\n- 2024/9/3: Version `0.0.12`, test version, fix a bug\n- 2024/9/3: Version `0.0.13`, test version, fix a numpy dependency bug and use_our_model prediction\n",
"bugtrack_url": null,
"license": null,
"summary": "Machine Learning and Graph based tool for detecting and analyzing Bone-Muscle Interactions",
"version": "0.0.13",
"project_urls": null,
"split_keywords": [
"python",
" bminet",
" interaction",
" network",
" bone-muscle",
" windows",
" mac",
" linux"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fd58d3bbd1f76edeebacbb76bf8bebb6eb90d4f685bc223f520fe2c8c863ab05",
"md5": "494d5188423e73f5d256b36087b85c54",
"sha256": "6baeee632bc89fcbdd2fc59728e0351aef6de2cd041eb8914bed337334e0c0a9"
},
"downloads": -1,
"filename": "bminet-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "494d5188423e73f5d256b36087b85c54",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 55608,
"upload_time": "2024-09-03T12:15:31",
"upload_time_iso_8601": "2024-09-03T12:15:31.731742Z",
"url": "https://files.pythonhosted.org/packages/fd/58/d3bbd1f76edeebacbb76bf8bebb6eb90d4f685bc223f520fe2c8c863ab05/bminet-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-03 12:15:31",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "bminet"
}