-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multitask regressors to Lazy*Classifier
- Loading branch information
1 parent
cb13953
commit ddc5350
Showing
16 changed files
with
263 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mlsauce as ms | ||
from sklearn.datasets import load_iris | ||
from sklearn.preprocessing import OneHotEncoder | ||
from sklearn.linear_model import HuberRegressor, LinearRegression | ||
|
||
data = load_iris() | ||
X = data.data | ||
y = data.target | ||
y_encoded = OneHotEncoder().fit_transform(y.reshape(-1, 1)).toarray() | ||
|
||
obj = ms.MultiTaskRegressor(regr=HuberRegressor()) | ||
|
||
obj.fit(X, y_encoded) | ||
|
||
print(obj.predict(X)) | ||
|
||
obj2 = LinearRegression() | ||
|
||
obj2.fit(X, y_encoded) | ||
|
||
print(obj2.predict(X)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Metadata-Version: 2.1 | ||
Name: mlsauce | ||
Version: 0.22.0 | ||
Summary: Miscellaneous Statistical/Machine Learning tools | ||
Maintainer: T. Moudiki | ||
Maintainer-email: [email protected] | ||
License: BSD3 Clause Clear | ||
Platform: linux | ||
Platform: macosx | ||
Platform: windows | ||
Classifier: Development Status :: 2 - Pre-Alpha | ||
Classifier: Intended Audience :: Developers | ||
Classifier: License :: OSI Approved :: BSD License | ||
Classifier: Natural Language :: English | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: Programming Language :: Python :: 3.5 | ||
Classifier: Programming Language :: Python :: 3.6 | ||
Classifier: Programming Language :: Python :: 3.7 | ||
Classifier: Programming Language :: Python :: 3.8 | ||
Requires-Python: >=3.5 | ||
License-File: LICENSE | ||
Requires-Dist: numpy | ||
Requires-Dist: Cython | ||
Requires-Dist: joblib | ||
Requires-Dist: matplotlib | ||
Requires-Dist: nnetsauce | ||
Requires-Dist: pandas | ||
Requires-Dist: requests | ||
Requires-Dist: scikit-learn | ||
Requires-Dist: scipy | ||
Requires-Dist: tqdm | ||
Provides-Extra: alldeps | ||
Requires-Dist: numpy>=1.13.0; extra == "alldeps" | ||
Requires-Dist: scipy>=0.19.0; extra == "alldeps" | ||
|
||
Miscellaneous Statistical/Machine Learning tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
LICENSE | ||
README.md | ||
setup.cfg | ||
setup.py | ||
mlsauce/__init__.py | ||
mlsauce/_config.py | ||
mlsauce/setup.py | ||
mlsauce.egg-info/PKG-INFO | ||
mlsauce.egg-info/SOURCES.txt | ||
mlsauce.egg-info/dependency_links.txt | ||
mlsauce.egg-info/not-zip-safe | ||
mlsauce.egg-info/requires.txt | ||
mlsauce.egg-info/top_level.txt | ||
mlsauce/adaopt/__init__.py | ||
mlsauce/adaopt/_adaopt.py | ||
mlsauce/adaopt/_adaoptc.c | ||
mlsauce/adaopt/setup.py | ||
mlsauce/adaopt/setup2.py | ||
mlsauce/adaopt/utils_adaopt.py | ||
mlsauce/booster/__init__.py | ||
mlsauce/booster/_booster_classifier.py | ||
mlsauce/booster/_booster_regressor.py | ||
mlsauce/booster/_boosterc.c | ||
mlsauce/booster/setup.py | ||
mlsauce/booster/setup2.py | ||
mlsauce/booster/utils_booster.py | ||
mlsauce/datasets/__init__.py | ||
mlsauce/datasets/dowload.py | ||
mlsauce/elasticnet/__init__.py | ||
mlsauce/elasticnet/_enet.py | ||
mlsauce/elasticnet/enet.py | ||
mlsauce/elasticnet/utils_enet.py | ||
mlsauce/lasso/__init__.py | ||
mlsauce/lasso/_lasso.py | ||
mlsauce/lasso/_lassoc.c | ||
mlsauce/lasso/setup.py | ||
mlsauce/lasso/setup2.py | ||
mlsauce/lasso/utils_lasso.py | ||
mlsauce/lazybooster/__init__.py | ||
mlsauce/lazybooster/config.py | ||
mlsauce/lazybooster/lazyboosterclassif.py | ||
mlsauce/lazybooster/lazyboosterregression.py | ||
mlsauce/multitaskregressor/__init__.py | ||
mlsauce/multitaskregressor/mtaskregr.py | ||
mlsauce/nonconformist/__init__.py | ||
mlsauce/nonconformist/acp.py | ||
mlsauce/nonconformist/base.py | ||
mlsauce/nonconformist/cp.py | ||
mlsauce/nonconformist/evaluation.py | ||
mlsauce/nonconformist/icp.py | ||
mlsauce/nonconformist/nc.py | ||
mlsauce/nonconformist/util.py | ||
mlsauce/predictioninterval/__init__.py | ||
mlsauce/predictioninterval/predictioninterval.py | ||
mlsauce/ridge/__init__.py | ||
mlsauce/ridge/_ridge.py | ||
mlsauce/ridge/_ridgec.c | ||
mlsauce/ridge/setup.py | ||
mlsauce/ridge/setup2.py | ||
mlsauce/ridge/utils_ridge.py | ||
mlsauce/stump/__init__.py | ||
mlsauce/stump/_stump_classifier.py | ||
mlsauce/stump/_stumpc.c | ||
mlsauce/stump/setup.py | ||
mlsauce/stump/setup2.py | ||
mlsauce/stump/utils_stump.py | ||
mlsauce/utils/__init__.py | ||
mlsauce/utils/get_beta.py | ||
mlsauce/utils/progress_bar.py | ||
mlsauce/utils/memoryuse/__init__.py | ||
mlsauce/utils/memoryuse/mem_usage.py | ||
mlsauce/utils/misc/__init__.py | ||
mlsauce/utils/misc/misc.py | ||
mlsauce/utils/sampling/__init__.py | ||
mlsauce/utils/sampling/rowsubsampling.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
numpy | ||
Cython | ||
joblib | ||
matplotlib | ||
nnetsauce | ||
pandas | ||
requests | ||
scikit-learn | ||
scipy | ||
tqdm | ||
|
||
[alldeps] | ||
numpy>=1.13.0 | ||
scipy>=0.19.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mlsauce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .mtaskregr import MultiTaskRegressor | ||
|
||
__all__ = ['MultiTaskRegressor'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from copy import deepcopy | ||
from sklearn.base import BaseEstimator, RegressorMixin | ||
from ..utils import is_multitask_estimator | ||
|
||
class MultiTaskRegressor(BaseEstimator, RegressorMixin): | ||
""" | ||
A class for multi-task regression | ||
Parameters | ||
---------- | ||
regr: object | ||
A regressor object | ||
Attributes | ||
---------- | ||
objs: list | ||
A list containing the fitted regressor objects | ||
""" | ||
def __init__(self, regr): | ||
assert is_multitask_estimator(regr) == False, "The regressor is already a multi-task regressor" | ||
self.regr = regr | ||
self.objs = [] | ||
|
||
def fit(self, X, y): | ||
""" | ||
Fit the regressor | ||
Parameters | ||
---------- | ||
X: array-like | ||
The input data | ||
y: array-like | ||
The target values | ||
""" | ||
n_tasks = y.shape[1] | ||
assert n_tasks > 1, "The number of columns in y must be greater than 1" | ||
self.n_outputs_ = n_tasks | ||
try: | ||
for i in range(n_tasks): | ||
self.regr.fit(X, y.iloc[:, i].values) | ||
self.objs.append(deepcopy(self.regr)) | ||
except Exception: | ||
for i in range(n_tasks): | ||
self.regr.fit(X, y[:, i]) | ||
self.objs.append(deepcopy(self.regr)) | ||
return self | ||
|
||
def predict(self, X): | ||
""" | ||
Predict the target values | ||
Parameters | ||
---------- | ||
X: array-like | ||
The input data | ||
Returns | ||
------- | ||
y_pred: array-like | ||
The predicted target values | ||
""" | ||
assert len(self.objs) > 0, "The regressor has not been fitted yet" | ||
y_pred = np.zeros((X.shape[0], self.n_outputs_)) | ||
for i in range(self.n_outputs_): | ||
y_pred[:, i] = self.objs[i].predict(X) | ||
return y_pred |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ | |
MAINTAINER_EMAIL = '[email protected]' | ||
LICENSE = 'BSD3 Clause Clear' | ||
|
||
__version__ = '0.21.0' | ||
__version__ = '0.22.0' | ||
|
||
VERSION = __version__ | ||
|
||
|