Package: reflame
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 licenseProvided Estimator: FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifierTotal Official Metaheuristic-based Flnn Regression: > 200 ModelsTotal Official Metaheuristic-based Flnn Classification: > 200 ModelsSupported 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.ioPython versions:>= 3.8.xDependencies:numpy, scipy, scikit-learn, pandas, mealpy, permetrics, torch, skorchCitation RequestIf 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 followingthis linkPlease include these citations if you plan to use this library:@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}
}InstallationInstall thecurrent PyPI release:$pipinstallreflame==1.0.1Install directly from source code$gitclonehttps://github.com/thieu1995/reflame.git
$cdreflame
$pythonsetup.pyinstallIn case, you want to install the development version from Github:$pipinstallgit+https://github.com/thieu1995/reflameAfter installation, you can import Reflame as any other Python module:$python
>>>importreflame
>>>reflame.__version__ExamplesIn 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.### Step 1: Importing the librariesimportpandasaspdfromsklearn.model_selectionimporttrain_test_splitfromsklearn.preprocessingimportMinMaxScaler,LabelEncoderfromreflameimportFlnnRegressor,FlnnClassifier,MhaFlnnRegressor,MhaFlnnClassifier#### Step 2: Reading the datasetdataset=pd.read_csv('Position_Salaries.csv')X=dataset.iloc[:,1:2].valuesy=dataset.iloc[:,2].values#### Step 3: Next, split dataset into train and test setX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,shuffle=True,random_state=100)#### Step 4: Feature Scalingscaler_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 onlyle_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 problemregressor=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 problemclassifer=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 problemprint(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 problemprint(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 resulty_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### Step 1: Importing the librariesfromreflameimportData,FlnnRegressor,FlnnClassifier,MhaFlnnRegressor,MhaFlnnClassifierfromsklearn.datasetsimportload_digits#### Step 2: Reading the datasetX,y=load_digits(return_X_y=True)data=Data(X,y)#### Step 3: Next, split dataset into train and test setdata.split_train_test(test_size=0.2,shuffle=True,random_state=100)#### Step 4: Feature Scalingdata.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 onlydata.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 problemregressor=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 problemclassifer=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 problemprint(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 problemprint(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 resulty_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.Where do I find the supported metrics like above ["AS", "PS", "RS"]. What is that?
You can find it here:https://github.com/thieu1995/permetricsor use thisfromreflameimportMhaFlnnClassifier,MhaFlnnRegressorprint(MhaFlnnRegressor.SUPPORTED_REG_OBJECTIVES)print(MhaFlnnClassifier.SUPPORTED_CLS_OBJECTIVES)I got this type of errorraiseValueError("Existed at least one new label in y_pred.")ValueError:Existedatleastonenewlabeliny_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.importpandasaspdfromimblearn.over_samplingimportSMOTEfromreflameimportDatadataset=pd.read_csv('examples/dataset.csv',index_col=0).valuesX,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.importpandasaspdfromreflameimportDatadataset=pd.read_csv('examples/dataset.csv',index_col=0).valuesX,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 valueSupport (questions, problems)Official LinksOfficial source code repo:https://github.com/thieu1995/reflameOfficial document:https://reflame.readthedocs.io/Download releases:https://pypi.org/project/reflame/Issue tracker:https://github.com/thieu1995/reflame/issuesNotable changes log:https://github.com/thieu1995/reflame/blob/master/ChangeLog.mdOfficial chat group:https://t.me/+fRVCJGuGJg1mNDg1This project also related to our another projects which are "optimization" and "machine learning", check it here:https://github.com/thieu1995/mealpyhttps://github.com/thieu1995/metaheuristicshttps://github.com/thieu1995/opfunuhttps://github.com/thieu1995/enoppyhttps://github.com/thieu1995/permetricshttps://github.com/thieu1995/MetaClusterhttps://github.com/thieu1995/pfevaluatorhttps://github.com/thieu1995/intelelmhttps://github.com/aiir-team