Skip to main content

InfoDESReg: Dynamic Ensemble Selection for Regression tasks

Project description

InfoDESReg

Installation

pip install infodesreg

Example

Loading necessary libraries and dataset:

import pandas as pd 

# models 
from xgboost import XGBRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression 

# metrics 
from sklearn.model_selection import train_test_split  
from sklearn.preprocessing import LabelEncoder
from ucimlrepo import fetch_ucirepo

# dataset
from ucimlrepo import fetch_ucirepo   

# InfoDESReg 
from infodesreg import DES

Loading data:

abalone = fetch_ucirepo(id=1) 
X = abalone.data.features 
y = abalone.data.targets  

le = LabelEncoder() 
X['Sex'] = le.fit_transform(X['Sex'])  

Split the dataset into training, validation for DES (DSEL) and testing.

TEST_SIZE = 0.2 

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=TEST_SIZE, random_state=42) 
X_train, X_dsel, y_train, y_dsel = train_test_split(X_train, y_train, test_size=0.2, random_state=42)   
  1. Models pool generation
pool_models = [
    XGBRegressor(random_state=42), 
    RandomForestRegressor(random_state=42), 
    LinearRegression(), 
    KNeighborsRegressor(), 
]
  1. Train the models (pool):
for model in pool_models: 
    model.fit(X_train, y_train)  
  1. Usage of our library:
des = DES(pool_regressors=pool_models, 
          k=6, 
          knn_metric='minkowski', 
          metrics='mape', 
          threshold=0.1)

des.fit(X_dsel, y_dsel) 
  1. Testing
des.score(X_test, y_test) # based on MSE 
  1. Explainability
index = 47
X_test.iloc[index]

prediction, contribution_df, neighbors_df = des.predict_xai(X_test.iloc[[index]])

print(prediction) 

The content of contribution data frame:

Model Predictions Competence Weights
XGBRegressor 9.133 0.064 15.609
RandomForestRegressor 8.890 0.078 12.853
LinearRegression 8.913 0.090 11.141
KNeighborsRegressor 9.000 0.072 13.846

The samples in the region of competence (neighbors_df):

Sex Length Diameter Height Whole_weight Shucked_weight Viscera_weight Shell_weight Target
2 0.565 0.44 0.125 0.802 0.3595 0.1825 0.215 9
2 0.55 0.425 0.15 0.8315 0.411 0.1765 0.2165 10
2 0.56 0.415 0.13 0.7615 0.3695 0.17 0.1955 8
2 0.545 0.41 0.12 0.793 0.434 0.1405 0.19 9
2 0.56 0.415 0.145 0.852 0.43 0.1885 0.205 8
2 0.54 0.42 0.135 0.8075 0.3485 0.1795 0.235 11

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

infodesreg-0.0.9.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infodesreg-0.0.9-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file infodesreg-0.0.9.tar.gz.

File metadata

  • Download URL: infodesreg-0.0.9.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for infodesreg-0.0.9.tar.gz
Algorithm Hash digest
SHA256 53a8796fe11117e13b36558ebab8617833675a92109a777a54b9aef29533f843
MD5 e7093cee8618b6d9b0bd945dfb46d9b1
BLAKE2b-256 29f8e775c134188a5e50e7b334d9a6f72c73739b509ef8293ecf7f1e6396346e

See more details on using hashes here.

File details

Details for the file infodesreg-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: infodesreg-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for infodesreg-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f54b10ee03cb8eadc39d52b5a926052906a97aec4eba2e067692a52397cef522
MD5 78e1a44b259fae3db5632af0f641f407
BLAKE2b-256 85af01ae3ad9da9aaa976bf5e618eace7ab85da764b507cf1d021b555fc2f715

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page