Machine Learning and Graph based tool for detecting and analyzing Bone-Muscle Interactions
Project description
Introduction of BMINet
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
- Load your data
import pandas as pd
df = pd.read_csv('Example/data.txt', sep='\t')
- Select features
# 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 linear formula model
from BMINet.Model import Lasso_Formula
formula = Lasso_Formula(df, disease_pairs=("A", "B"))
print(formula)
Also Ridge, ElasticNet and Simple Linear
- Build stacking model
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
# 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 modelIf you are researching on a brand new project, use
use_our_model = False
- Basic machine learning plots
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
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
# 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
from BMINet.Interaction import NetworkMetrics
metrics_calculator = NetworkMetrics(Graph_BMI)
metrics = metrics_calculator.compute_metrics()
You can see more Example usage at here
Update Log
- 2024/9/5: Version
0.1.0
, fix CatBoost bug - 2024/9/5: Version
0.1.1
, update prediction threholds - 2024/11/8: Version
0.1.2
, update linear formula model - 2024/11/26: Version
0.1.3
, add matrix visulization
BMINet is developed by Jingran Wang
Department of Orthopedic Surgery, The First Affiliated Hospital of Soochow University
MOE Key Laboratory of Geriatric Diseases and Immunology, Suzhou Key Laboratory of Pathogen Bioscience and Anti-Infective Medicine
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file bminet-0.1.4.tar.gz
.
File metadata
- Download URL: bminet-0.1.4.tar.gz
- Upload date:
- Size: 118.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8856a9ae0b46ee78c9b8cc436c699eff2e70e3a3abae3fd178c55c1c0d92c5f |
|
MD5 | 5b774ae46561c8a49f8035f5e7afec0a |
|
BLAKE2b-256 | 1a2d5c019a9c55f378e40f48204ff19bfd13ae5dd7c2654fe4802ad2537a896c |