reflame


Namereflame JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/thieu1995/reflame
SummaryRevolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library
upload_time2023-11-26 04:21:07
maintainer
docs_urlNone
authorThieu
requires_python>=3.8
licenseGPLv3
keywords functional link neural network machine learning artificial intelligence deep learning neural networks single hidden layer network random projection flann functional link artificial neural network classification regression supervised learning online learning generalization ensemble learning optimization algorithms kernel flnn cross-validationgenetic algorithm (ga) particle swarm optimization (pso) ant colony optimization (aco) differential evolution (de) simulated annealing grey wolf optimizer (gwo) whale optimization algorithm (woa) confusion matrix recall precision accuracy pearson correlation coefficient (pcc) spearman correlation coefficient (scc) relief relief-f multi-objectives optimization problems stochastic optimization global optimization convergence analysis search space exploration local search computational intelligence robust optimization performance analysis intelligent optimization simulations
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<p align="center">
<img style="max-width:100%;" src="https://thieu1995.github.io/post/2023-08/reflame.png" alt="Reflame"/>
</p>


---

[![GitHub release](https://img.shields.io/badge/release-1.0.1-yellow.svg)](https://github.com/thieu1995/reflame/releases)
[![Wheel](https://img.shields.io/pypi/wheel/gensim.svg)](https://pypi.python.org/pypi/reflame) 
[![PyPI version](https://badge.fury.io/py/reflame.svg)](https://badge.fury.io/py/reflame)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/reflame.svg)
![PyPI - Status](https://img.shields.io/pypi/status/reflame.svg)
![PyPI - Downloads](https://img.shields.io/pypi/dm/reflame.svg)
[![Downloads](https://pepy.tech/badge/reflame)](https://pepy.tech/project/reflame)
[![Tests & Publishes to PyPI](https://github.com/thieu1995/reflame/actions/workflows/publish-package.yaml/badge.svg)](https://github.com/thieu1995/reflame/actions/workflows/publish-package.yaml)
![GitHub Release Date](https://img.shields.io/github/release-date/thieu1995/reflame.svg)
[![Documentation Status](https://readthedocs.org/projects/reflame/badge/?version=latest)](https://reflame.readthedocs.io/en/latest/?badge=latest)
[![Chat](https://img.shields.io/badge/Chat-on%20Telegram-blue)](https://t.me/+fRVCJGuGJg1mNDg1)
![GitHub contributors](https://img.shields.io/github/contributors/thieu1995/reflame.svg)
[![GitTutorial](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10067995.svg)](https://doi.org/10.5281/zenodo.10067995)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)


Reflame (REvolutionizing Functional Link Artificial neural networks by MEtaheuristic algorithms) is a Python library that 
implements a framework for training Functional Link Neural Network (FLNN) networks using Metaheuristic Algorithms. It 
provides a comparable alternative to the traditional FLNN network and is compatible with the Scikit-Learn library. 
With Reflame, you can perform searches and hyperparameter tuning using the functionalities provided by the Scikit-Learn library.

* **Free software:** GNU General Public License (GPL) V3 license
* **Provided Estimator**: FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier
* **Total Official Metaheuristic-based Flnn Regression**: > 200 Models 
* **Total Official Metaheuristic-based Flnn Classification**: > 200 Models
* **Supported performance metrics**: >= 67 (47 regressions and 20 classifications)
* **Supported objective functions (as fitness functions or loss functions)**: >= 67 (47 regressions and 20 classifications)
* **Documentation:** https://reflame.readthedocs.io
* **Python versions:** >= 3.8.x
* **Dependencies:** numpy, scipy, scikit-learn, pandas, mealpy, permetrics, torch, skorch


# Citation Request 

If you want to understand how Metaheuristic is applied to Functional Link Neural Network, you need to read the paper 
titled "A resource usage prediction system using functional-link and genetic algorithm neural network for multivariate cloud metrics". 
The paper can be accessed at the following [this link](https://doi.org/10.1109/SOCA.2018.00014)


Please include these citations if you plan to use this library:

```code
@software{nguyen_van_thieu_2023_8249046,
  author       = {Nguyen Van Thieu},
  title        = {Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library},
  month        = 11,
  year         = 2023,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.8249045},
  url          = {https://github.com/thieu1995/reflame}
}

@article{van2023mealpy,
  title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
  author={Van Thieu, Nguyen and Mirjalili, Seyedali},
  journal={Journal of Systems Architecture},
  year={2023},
  publisher={Elsevier},
  doi={10.1016/j.sysarc.2023.102871}
}

@inproceedings{nguyen2019building,
	author = {Thieu Nguyen and Binh Minh Nguyen and Giang Nguyen},
	booktitle = {International Conference on Theory and Applications of Models of Computation},
	organization = {Springer},
	pages = {501--517},
	title = {Building Resource Auto-scaler with Functional-Link Neural Network and Adaptive Bacterial Foraging Optimization},
	year = {2019},
	url={https://doi.org/10.1007/978-3-030-14812-6_31},
	doi={10.1007/978-3-030-14812-6_31}
}

@inproceedings{nguyen2018resource,
	author = {Thieu Nguyen and Nhuan Tran and Binh Minh Nguyen and Giang Nguyen},
	booktitle = {2018 IEEE 11th Conference on Service-Oriented Computing and Applications (SOCA)},
	organization = {IEEE},
	pages = {49--56},
	title = {A Resource Usage Prediction System Using Functional-Link and Genetic Algorithm Neural Network for Multivariate Cloud Metrics},
	year = {2018},
	url={https://doi.org/10.1109/SOCA.2018.00014},
	doi={10.1109/SOCA.2018.00014}
}

```

# Installation

* Install the [current PyPI release](https://pypi.python.org/pypi/reflame):
```sh 
$ pip install reflame==1.0.1
```

* Install directly from source code
```sh 
$ git clone https://github.com/thieu1995/reflame.git
$ cd reflame
$ python setup.py install
```

* In case, you want to install the development version from Github:
```sh 
$ pip install git+https://github.com/thieu1995/reflame 
```

After installation, you can import Reflame as any other Python module:

```sh
$ python
>>> import reflame
>>> reflame.__version__
```

### Examples

In this section, we will explore the usage of the Reflame model with the assistance of a dataset. While all the 
preprocessing steps mentioned below can be replicated using Scikit-Learn, we have implemented some utility functions 
to provide users with convenience and faster usage.  

#### Combine Reflame library like a normal library with scikit-learn.

```python
### Step 1: Importing the libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler, LabelEncoder
from reflame import FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier

#### Step 2: Reading the dataset
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

#### Step 3: Next, split dataset into train and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=True, random_state=100)

#### Step 4: Feature Scaling
scaler_X = MinMaxScaler()
scaler_X.fit(X_train)
X_train = scaler_X.transform(X_train)
X_test = scaler_X.transform(X_test)

le_y = LabelEncoder()  # This is for classification problem only
le_y.fit(y)
y_train = le_y.transform(y_train)
y_test = le_y.transform(y_test)

#### Step 5: Fitting FLNN-based model to the dataset

##### 5.1: Use standard FLNN model for regression problem
regressor = FlnnRegressor(expand_name="chebyshev", n_funcs=4, act_name="elu",
                      obj_name="MSE", max_epochs=100, batch_size=32, optimizer="SGD", verbose=True)
regressor.fit(X_train, y_train)

##### 5.2: Use standard FLNN model for classification problem 
classifer = FlnnClassifier(expand_name="chebyshev", n_funcs=4, act_name="sigmoid",
                      obj_name="BCEL", max_epochs=100, batch_size=32, optimizer="SGD", verbose=True)
classifer.fit(X_train, y_train)

##### 5.3: Use Metaheuristic-based FLNN model for regression problem
print(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)
print(MhaFlnnClassifier.SUPPORTED_REG_OBJECTIVES)
opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
model = MhaFlnnRegressor(expand_name="chebyshev", n_funcs=3, act_name="elu", 
                         obj_name="RMSE", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=True)
regressor.fit(X_train, y_train)

##### 5.4: Use Metaheuristic-based FLNN model for classification problem
print(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)
print(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)
opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
classifier = MhaFlnnClassifier(expand_name="chebyshev", n_funcs=4, act_name="sigmoid",
                          obj_name="NPV", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=True)
classifier.fit(X_train, y_train)

#### Step 6: Predicting a new result
y_pred = regressor.predict(X_test)

y_pred_cls = classifier.predict(X_test)
y_pred_label = le_y.inverse_transform(y_pred_cls)

#### Step 7: Calculate metrics using score or scores functions.
print("Try my AS metric with score function")
print(regressor.score(X_test, y_test, method="AS"))

print("Try my multiple metrics with scores function")
print(classifier.scores(X_test, y_test, list_methods=["AS", "PS", "F1S", "CEL", "BSL"]))
```

#### Utilities everything that Reflame provided

```python
### Step 1: Importing the libraries
from reflame import Data, FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier
from sklearn.datasets import load_digits

#### Step 2: Reading the dataset
X, y = load_digits(return_X_y=True)
data = Data(X, y)

#### Step 3: Next, split dataset into train and test set
data.split_train_test(test_size=0.2, shuffle=True, random_state=100)

#### Step 4: Feature Scaling
data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=("minmax"))
data.X_test = scaler_X.transform(data.X_test)

data.y_train, scaler_y = data.encode_label(data.y_train)  # This is for classification problem only
data.y_test = scaler_y.transform(data.y_test)

#### Step 5: Fitting FLNN-based model to the dataset

##### 5.1: Use standard FLNN model for regression problem
regressor = FlnnRegressor(expand_name="chebyshev", n_funcs=4, act_name="tanh",
                      obj_name="MSE", max_epochs=100, batch_size=32, optimizer="SGD", verbose=True)
regressor.fit(data.X_train, data.y_train)

##### 5.2: Use standard FLNN model for classification problem 
classifer = FlnnClassifier(expand_name="chebyshev", n_funcs=4, act_name="tanh",
                      obj_name="BCEL", max_epochs=100, batch_size=32, optimizer="SGD", verbose=True)
classifer.fit(data.X_train, data.y_train)

##### 5.3: Use Metaheuristic-based FLNN model for regression problem
print(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)
print(MhaFlnnClassifier.SUPPORTED_REG_OBJECTIVES)
opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
model = MhaFlnnRegressor(expand_name="chebyshev", n_funcs=3, act_name="elu", 
                         obj_name="RMSE", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=True)
regressor.fit(data.X_train, data.y_train)

##### 5.4: Use Metaheuristic-based FLNN model for classification problem
print(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)
print(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)
opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
classifier = MhaFlnnClassifier(expand_name="chebyshev", n_funcs=4, act_name="sigmoid",
                          obj_name="NPV", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=True)
classifier.fit(data.X_train, data.y_train)

#### Step 6: Predicting a new result
y_pred = regressor.predict(data.X_test)

y_pred_cls = classifier.predict(data.X_test)
y_pred_label = scaler_y.inverse_transform(y_pred_cls)

#### Step 7: Calculate metrics using score or scores functions.
print("Try my AS metric with score function")
print(regressor.score(data.X_test, data.y_test, method="AS"))

print("Try my multiple metrics with scores function")
print(classifier.scores(data.X_test, data.y_test, list_methods=["AS", "PS", "F1S", "CEL", "BSL"]))
```

A real-world dataset contains features that vary in magnitudes, units, and range. We would suggest performing 
normalization when the scale of a feature is irrelevant or misleading. Feature Scaling basically helps to normalize 
the data within a particular range.



1) Where do I find the supported metrics like above ["AS", "PS", "RS"]. What is that?
You can find it here: https://github.com/thieu1995/permetrics or use this

```python
from reflame import MhaFlnnClassifier, MhaFlnnRegressor

print(MhaFlnnRegressor.SUPPORTED_REG_OBJECTIVES)
print(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)
```

2) I got this type of error
```python
raise ValueError("Existed at least one new label in y_pred.")
ValueError: Existed at least one new label in y_pred.
``` 
How to solve this?

+ This occurs only when you are working on a classification problem with a small dataset that has many classes. For 
  instance, the "Zoo" dataset contains only 101 samples, but it has 7 classes. If you split the dataset into a 
  training and testing set with a ratio of around 80% - 20%, there is a chance that one or more classes may appear 
  in the testing set but not in the training set. As a result, when you calculate the performance metrics, you may 
  encounter this error. You cannot predict or assign new data to a new label because you have no knowledge about the 
  new label. There are several solutions to this problem.

+ 1st: Use the SMOTE method to address imbalanced data and ensure that all classes have the same number of samples.

```python
import pandas as pd
from imblearn.over_sampling import SMOTE
from reflame import Data

dataset = pd.read_csv('examples/dataset.csv', index_col=0).values
X, y = dataset[:, 0:-1], dataset[:, -1]

X_new, y_new = SMOTE().fit_resample(X, y)
data = Data(X_new, y_new)
```

+ 2nd: Use different random_state numbers in split_train_test() function.

```python
import pandas as pd
from reflame import Data

dataset = pd.read_csv('examples/dataset.csv', index_col=0).values
X, y = dataset[:, 0:-1], dataset[:, -1]
data = Data(X, y)
data.split_train_test(test_size=0.2, random_state=10)  # Try different random_state value 
```


# Support (questions, problems)

### Official Links 

* Official source code repo: https://github.com/thieu1995/reflame
* Official document: https://reflame.readthedocs.io/
* Download releases: https://pypi.org/project/reflame/
* Issue tracker: https://github.com/thieu1995/reflame/issues
* Notable changes log: https://github.com/thieu1995/reflame/blob/master/ChangeLog.md
* Official chat group: https://t.me/+fRVCJGuGJg1mNDg1

* This project also related to our another projects which are "optimization" and "machine learning", check it here:
    * https://github.com/thieu1995/mealpy
    * https://github.com/thieu1995/metaheuristics
    * https://github.com/thieu1995/opfunu
    * https://github.com/thieu1995/enoppy
    * https://github.com/thieu1995/permetrics
    * https://github.com/thieu1995/MetaCluster
    * https://github.com/thieu1995/pfevaluator
    * https://github.com/thieu1995/intelelm
    * https://github.com/aiir-team

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thieu1995/reflame",
    "name": "reflame",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "functional link neural network,machine learning,artificial intelligence,deep learning,neural networks,single hidden layer network,random projection,FLANN,functional link artificial neural network,classification,regression,supervised learning,online learning,generalization,ensemble learning,optimization algorithms,Kernel FLNN,Cross-validationGenetic algorithm (GA),Particle swarm optimization (PSO),Ant colony optimization (ACO),Differential evolution (DE),Simulated annealing,Grey wolf optimizer (GWO),Whale Optimization Algorithm (WOA),confusion matrix,recall,precision,accuracy,pearson correlation coefficient (PCC),spearman correlation coefficient (SCC),relief,relief-f,multi-objectives optimization problems,Stochastic optimization,Global optimization,Convergence analysis,Search space exploration,Local search,Computational intelligence,Robust optimization,Performance analysis,Intelligent optimization,Simulations",
    "author": "Thieu",
    "author_email": "nguyenthieu2102@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/96/19/4902d7201e03001466493b733ab3038339c3a3ba763da7b36e1d822df67e/reflame-1.0.1.tar.gz",
    "platform": null,
    "description": "\n<p align=\"center\">\n<img style=\"max-width:100%;\" src=\"https://thieu1995.github.io/post/2023-08/reflame.png\" alt=\"Reflame\"/>\n</p>\n\n\n---\n\n[![GitHub release](https://img.shields.io/badge/release-1.0.1-yellow.svg)](https://github.com/thieu1995/reflame/releases)\n[![Wheel](https://img.shields.io/pypi/wheel/gensim.svg)](https://pypi.python.org/pypi/reflame) \n[![PyPI version](https://badge.fury.io/py/reflame.svg)](https://badge.fury.io/py/reflame)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/reflame.svg)\n![PyPI - Status](https://img.shields.io/pypi/status/reflame.svg)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/reflame.svg)\n[![Downloads](https://pepy.tech/badge/reflame)](https://pepy.tech/project/reflame)\n[![Tests & Publishes to PyPI](https://github.com/thieu1995/reflame/actions/workflows/publish-package.yaml/badge.svg)](https://github.com/thieu1995/reflame/actions/workflows/publish-package.yaml)\n![GitHub Release Date](https://img.shields.io/github/release-date/thieu1995/reflame.svg)\n[![Documentation Status](https://readthedocs.org/projects/reflame/badge/?version=latest)](https://reflame.readthedocs.io/en/latest/?badge=latest)\n[![Chat](https://img.shields.io/badge/Chat-on%20Telegram-blue)](https://t.me/+fRVCJGuGJg1mNDg1)\n![GitHub contributors](https://img.shields.io/github/contributors/thieu1995/reflame.svg)\n[![GitTutorial](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10067995.svg)](https://doi.org/10.5281/zenodo.10067995)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\n\nReflame (REvolutionizing Functional Link Artificial neural networks by MEtaheuristic algorithms) is a Python library that \nimplements a framework for training Functional Link Neural Network (FLNN) networks using Metaheuristic Algorithms. It \nprovides a comparable alternative to the traditional FLNN network and is compatible with the Scikit-Learn library. \nWith Reflame, you can perform searches and hyperparameter tuning using the functionalities provided by the Scikit-Learn library.\n\n* **Free software:** GNU General Public License (GPL) V3 license\n* **Provided Estimator**: FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier\n* **Total Official Metaheuristic-based Flnn Regression**: > 200 Models \n* **Total Official Metaheuristic-based Flnn Classification**: > 200 Models\n* **Supported performance metrics**: >= 67 (47 regressions and 20 classifications)\n* **Supported objective functions (as fitness functions or loss functions)**: >= 67 (47 regressions and 20 classifications)\n* **Documentation:** https://reflame.readthedocs.io\n* **Python versions:** >= 3.8.x\n* **Dependencies:** numpy, scipy, scikit-learn, pandas, mealpy, permetrics, torch, skorch\n\n\n# Citation Request \n\nIf you want to understand how Metaheuristic is applied to Functional Link Neural Network, you need to read the paper \ntitled \"A resource usage prediction system using functional-link and genetic algorithm neural network for multivariate cloud metrics\". \nThe paper can be accessed at the following [this link](https://doi.org/10.1109/SOCA.2018.00014)\n\n\nPlease include these citations if you plan to use this library:\n\n```code\n@software{nguyen_van_thieu_2023_8249046,\n  author       = {Nguyen Van Thieu},\n  title        = {Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library},\n  month        = 11,\n  year         = 2023,\n  publisher    = {Zenodo},\n  doi          = {10.5281/zenodo.8249045},\n  url          = {https://github.com/thieu1995/reflame}\n}\n\n@article{van2023mealpy,\n  title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},\n  author={Van Thieu, Nguyen and Mirjalili, Seyedali},\n  journal={Journal of Systems Architecture},\n  year={2023},\n  publisher={Elsevier},\n  doi={10.1016/j.sysarc.2023.102871}\n}\n\n@inproceedings{nguyen2019building,\n\tauthor = {Thieu Nguyen and Binh Minh Nguyen and Giang Nguyen},\n\tbooktitle = {International Conference on Theory and Applications of Models of Computation},\n\torganization = {Springer},\n\tpages = {501--517},\n\ttitle = {Building Resource Auto-scaler with Functional-Link Neural Network and Adaptive Bacterial Foraging Optimization},\n\tyear = {2019},\n\turl={https://doi.org/10.1007/978-3-030-14812-6_31},\n\tdoi={10.1007/978-3-030-14812-6_31}\n}\n\n@inproceedings{nguyen2018resource,\n\tauthor = {Thieu Nguyen and Nhuan Tran and Binh Minh Nguyen and Giang Nguyen},\n\tbooktitle = {2018 IEEE 11th Conference on Service-Oriented Computing and Applications (SOCA)},\n\torganization = {IEEE},\n\tpages = {49--56},\n\ttitle = {A Resource Usage Prediction System Using Functional-Link and Genetic Algorithm Neural Network for Multivariate Cloud Metrics},\n\tyear = {2018},\n\turl={https://doi.org/10.1109/SOCA.2018.00014},\n\tdoi={10.1109/SOCA.2018.00014}\n}\n\n```\n\n# Installation\n\n* Install the [current PyPI release](https://pypi.python.org/pypi/reflame):\n```sh \n$ pip install reflame==1.0.1\n```\n\n* Install directly from source code\n```sh \n$ git clone https://github.com/thieu1995/reflame.git\n$ cd reflame\n$ python setup.py install\n```\n\n* In case, you want to install the development version from Github:\n```sh \n$ pip install git+https://github.com/thieu1995/reflame \n```\n\nAfter installation, you can import Reflame as any other Python module:\n\n```sh\n$ python\n>>> import reflame\n>>> reflame.__version__\n```\n\n### Examples\n\nIn this section, we will explore the usage of the Reflame model with the assistance of a dataset. While all the \npreprocessing steps mentioned below can be replicated using Scikit-Learn, we have implemented some utility functions \nto provide users with convenience and faster usage.  \n\n#### Combine Reflame library like a normal library with scikit-learn.\n\n```python\n### Step 1: Importing the libraries\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import MinMaxScaler, LabelEncoder\nfrom reflame import FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier\n\n#### Step 2: Reading the dataset\ndataset = pd.read_csv('Position_Salaries.csv')\nX = dataset.iloc[:, 1:2].values\ny = dataset.iloc[:, 2].values\n\n#### Step 3: Next, split dataset into train and test set\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=True, random_state=100)\n\n#### Step 4: Feature Scaling\nscaler_X = MinMaxScaler()\nscaler_X.fit(X_train)\nX_train = scaler_X.transform(X_train)\nX_test = scaler_X.transform(X_test)\n\nle_y = LabelEncoder()  # This is for classification problem only\nle_y.fit(y)\ny_train = le_y.transform(y_train)\ny_test = le_y.transform(y_test)\n\n#### Step 5: Fitting FLNN-based model to the dataset\n\n##### 5.1: Use standard FLNN model for regression problem\nregressor = FlnnRegressor(expand_name=\"chebyshev\", n_funcs=4, act_name=\"elu\",\n                      obj_name=\"MSE\", max_epochs=100, batch_size=32, optimizer=\"SGD\", verbose=True)\nregressor.fit(X_train, y_train)\n\n##### 5.2: Use standard FLNN model for classification problem \nclassifer = FlnnClassifier(expand_name=\"chebyshev\", n_funcs=4, act_name=\"sigmoid\",\n                      obj_name=\"BCEL\", max_epochs=100, batch_size=32, optimizer=\"SGD\", verbose=True)\nclassifer.fit(X_train, y_train)\n\n##### 5.3: Use Metaheuristic-based FLNN model for regression problem\nprint(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)\nprint(MhaFlnnClassifier.SUPPORTED_REG_OBJECTIVES)\nopt_paras = {\"name\": \"GA\", \"epoch\": 10, \"pop_size\": 30}\nmodel = MhaFlnnRegressor(expand_name=\"chebyshev\", n_funcs=3, act_name=\"elu\", \n                         obj_name=\"RMSE\", optimizer=\"BaseGA\", optimizer_paras=opt_paras, verbose=True)\nregressor.fit(X_train, y_train)\n\n##### 5.4: Use Metaheuristic-based FLNN model for classification problem\nprint(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)\nprint(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)\nopt_paras = {\"name\": \"GA\", \"epoch\": 10, \"pop_size\": 30}\nclassifier = MhaFlnnClassifier(expand_name=\"chebyshev\", n_funcs=4, act_name=\"sigmoid\",\n                          obj_name=\"NPV\", optimizer=\"BaseGA\", optimizer_paras=opt_paras, verbose=True)\nclassifier.fit(X_train, y_train)\n\n#### Step 6: Predicting a new result\ny_pred = regressor.predict(X_test)\n\ny_pred_cls = classifier.predict(X_test)\ny_pred_label = le_y.inverse_transform(y_pred_cls)\n\n#### Step 7: Calculate metrics using score or scores functions.\nprint(\"Try my AS metric with score function\")\nprint(regressor.score(X_test, y_test, method=\"AS\"))\n\nprint(\"Try my multiple metrics with scores function\")\nprint(classifier.scores(X_test, y_test, list_methods=[\"AS\", \"PS\", \"F1S\", \"CEL\", \"BSL\"]))\n```\n\n#### Utilities everything that Reflame provided\n\n```python\n### Step 1: Importing the libraries\nfrom reflame import Data, FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier\nfrom sklearn.datasets import load_digits\n\n#### Step 2: Reading the dataset\nX, y = load_digits(return_X_y=True)\ndata = Data(X, y)\n\n#### Step 3: Next, split dataset into train and test set\ndata.split_train_test(test_size=0.2, shuffle=True, random_state=100)\n\n#### Step 4: Feature Scaling\ndata.X_train, scaler_X = data.scale(data.X_train, scaling_methods=(\"minmax\"))\ndata.X_test = scaler_X.transform(data.X_test)\n\ndata.y_train, scaler_y = data.encode_label(data.y_train)  # This is for classification problem only\ndata.y_test = scaler_y.transform(data.y_test)\n\n#### Step 5: Fitting FLNN-based model to the dataset\n\n##### 5.1: Use standard FLNN model for regression problem\nregressor = FlnnRegressor(expand_name=\"chebyshev\", n_funcs=4, act_name=\"tanh\",\n                      obj_name=\"MSE\", max_epochs=100, batch_size=32, optimizer=\"SGD\", verbose=True)\nregressor.fit(data.X_train, data.y_train)\n\n##### 5.2: Use standard FLNN model for classification problem \nclassifer = FlnnClassifier(expand_name=\"chebyshev\", n_funcs=4, act_name=\"tanh\",\n                      obj_name=\"BCEL\", max_epochs=100, batch_size=32, optimizer=\"SGD\", verbose=True)\nclassifer.fit(data.X_train, data.y_train)\n\n##### 5.3: Use Metaheuristic-based FLNN model for regression problem\nprint(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)\nprint(MhaFlnnClassifier.SUPPORTED_REG_OBJECTIVES)\nopt_paras = {\"name\": \"GA\", \"epoch\": 10, \"pop_size\": 30}\nmodel = MhaFlnnRegressor(expand_name=\"chebyshev\", n_funcs=3, act_name=\"elu\", \n                         obj_name=\"RMSE\", optimizer=\"BaseGA\", optimizer_paras=opt_paras, verbose=True)\nregressor.fit(data.X_train, data.y_train)\n\n##### 5.4: Use Metaheuristic-based FLNN model for classification problem\nprint(MhaFlnnClassifier.SUPPORTED_OPTIMIZERS)\nprint(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)\nopt_paras = {\"name\": \"GA\", \"epoch\": 10, \"pop_size\": 30}\nclassifier = MhaFlnnClassifier(expand_name=\"chebyshev\", n_funcs=4, act_name=\"sigmoid\",\n                          obj_name=\"NPV\", optimizer=\"BaseGA\", optimizer_paras=opt_paras, verbose=True)\nclassifier.fit(data.X_train, data.y_train)\n\n#### Step 6: Predicting a new result\ny_pred = regressor.predict(data.X_test)\n\ny_pred_cls = classifier.predict(data.X_test)\ny_pred_label = scaler_y.inverse_transform(y_pred_cls)\n\n#### Step 7: Calculate metrics using score or scores functions.\nprint(\"Try my AS metric with score function\")\nprint(regressor.score(data.X_test, data.y_test, method=\"AS\"))\n\nprint(\"Try my multiple metrics with scores function\")\nprint(classifier.scores(data.X_test, data.y_test, list_methods=[\"AS\", \"PS\", \"F1S\", \"CEL\", \"BSL\"]))\n```\n\nA real-world dataset contains features that vary in magnitudes, units, and range. We would suggest performing \nnormalization when the scale of a feature is irrelevant or misleading. Feature Scaling basically helps to normalize \nthe data within a particular range.\n\n\n\n1) Where do I find the supported metrics like above [\"AS\", \"PS\", \"RS\"]. What is that?\nYou can find it here: https://github.com/thieu1995/permetrics or use this\n\n```python\nfrom reflame import MhaFlnnClassifier, MhaFlnnRegressor\n\nprint(MhaFlnnRegressor.SUPPORTED_REG_OBJECTIVES)\nprint(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)\n```\n\n2) I got this type of error\n```python\nraise ValueError(\"Existed at least one new label in y_pred.\")\nValueError: Existed at least one new label in y_pred.\n``` \nHow to solve this?\n\n+ This occurs only when you are working on a classification problem with a small dataset that has many classes. For \n  instance, the \"Zoo\" dataset contains only 101 samples, but it has 7 classes. If you split the dataset into a \n  training and testing set with a ratio of around 80% - 20%, there is a chance that one or more classes may appear \n  in the testing set but not in the training set. As a result, when you calculate the performance metrics, you may \n  encounter this error. You cannot predict or assign new data to a new label because you have no knowledge about the \n  new label. There are several solutions to this problem.\n\n+ 1st: Use the SMOTE method to address imbalanced data and ensure that all classes have the same number of samples.\n\n```python\nimport pandas as pd\nfrom imblearn.over_sampling import SMOTE\nfrom reflame import Data\n\ndataset = pd.read_csv('examples/dataset.csv', index_col=0).values\nX, y = dataset[:, 0:-1], dataset[:, -1]\n\nX_new, y_new = SMOTE().fit_resample(X, y)\ndata = Data(X_new, y_new)\n```\n\n+ 2nd: Use different random_state numbers in split_train_test() function.\n\n```python\nimport pandas as pd\nfrom reflame import Data\n\ndataset = pd.read_csv('examples/dataset.csv', index_col=0).values\nX, y = dataset[:, 0:-1], dataset[:, -1]\ndata = Data(X, y)\ndata.split_train_test(test_size=0.2, random_state=10)  # Try different random_state value \n```\n\n\n# Support (questions, problems)\n\n### Official Links \n\n* Official source code repo: https://github.com/thieu1995/reflame\n* Official document: https://reflame.readthedocs.io/\n* Download releases: https://pypi.org/project/reflame/\n* Issue tracker: https://github.com/thieu1995/reflame/issues\n* Notable changes log: https://github.com/thieu1995/reflame/blob/master/ChangeLog.md\n* Official chat group: https://t.me/+fRVCJGuGJg1mNDg1\n\n* This project also related to our another projects which are \"optimization\" and \"machine learning\", check it here:\n    * https://github.com/thieu1995/mealpy\n    * https://github.com/thieu1995/metaheuristics\n    * https://github.com/thieu1995/opfunu\n    * https://github.com/thieu1995/enoppy\n    * https://github.com/thieu1995/permetrics\n    * https://github.com/thieu1995/MetaCluster\n    * https://github.com/thieu1995/pfevaluator\n    * https://github.com/thieu1995/intelelm\n    * https://github.com/aiir-team\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library",
    "version": "1.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/thieu1995/reflame/issues",
        "Change Log": "https://github.com/thieu1995/reflame/blob/master/ChangeLog.md",
        "Documentation": "https://reflame.readthedocs.io/",
        "Forum": "https://t.me/+fRVCJGuGJg1mNDg1",
        "Homepage": "https://github.com/thieu1995/reflame",
        "Source Code": "https://github.com/thieu1995/reflame"
    },
    "split_keywords": [
        "functional link neural network",
        "machine learning",
        "artificial intelligence",
        "deep learning",
        "neural networks",
        "single hidden layer network",
        "random projection",
        "flann",
        "functional link artificial neural network",
        "classification",
        "regression",
        "supervised learning",
        "online learning",
        "generalization",
        "ensemble learning",
        "optimization algorithms",
        "kernel flnn",
        "cross-validationgenetic algorithm (ga)",
        "particle swarm optimization (pso)",
        "ant colony optimization (aco)",
        "differential evolution (de)",
        "simulated annealing",
        "grey wolf optimizer (gwo)",
        "whale optimization algorithm (woa)",
        "confusion matrix",
        "recall",
        "precision",
        "accuracy",
        "pearson correlation coefficient (pcc)",
        "spearman correlation coefficient (scc)",
        "relief",
        "relief-f",
        "multi-objectives optimization problems",
        "stochastic optimization",
        "global optimization",
        "convergence analysis",
        "search space exploration",
        "local search",
        "computational intelligence",
        "robust optimization",
        "performance analysis",
        "intelligent optimization",
        "simulations"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b2c78f6edad6c213cd7c055cefeb6a16d70da0c6f1b12c9f3a2ba182ba2a758",
                "md5": "d36ae54e703e5df2212d6ec8369a6ce9",
                "sha256": "c3aaf2b5443db57fb8c6847553478a220a073a2e6e9901c172cc0e4263632a41"
            },
            "downloads": -1,
            "filename": "reflame-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d36ae54e703e5df2212d6ec8369a6ce9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 43632,
            "upload_time": "2023-11-26T04:21:05",
            "upload_time_iso_8601": "2023-11-26T04:21:05.821981Z",
            "url": "https://files.pythonhosted.org/packages/0b/2c/78f6edad6c213cd7c055cefeb6a16d70da0c6f1b12c9f3a2ba182ba2a758/reflame-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96194902d7201e03001466493b733ab3038339c3a3ba763da7b36e1d822df67e",
                "md5": "09da4d1ce693b5dd615ef702eb13c4ae",
                "sha256": "e42aa47d82ffadfc58d31452992be74a14285024426f0e6b6cc936eb40c92bde"
            },
            "downloads": -1,
            "filename": "reflame-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "09da4d1ce693b5dd615ef702eb13c4ae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 42495,
            "upload_time": "2023-11-26T04:21:07",
            "upload_time_iso_8601": "2023-11-26T04:21:07.051696Z",
            "url": "https://files.pythonhosted.org/packages/96/19/4902d7201e03001466493b733ab3038339c3a3ba763da7b36e1d822df67e/reflame-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-26 04:21:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thieu1995",
    "github_project": "reflame",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "reflame"
}
        
Elapsed time: 3.53061s