Dragon Fly Optimization¶
Installation¶
In [2]:
!pip install zoofs==0.1.24
Collecting zoofs==0.1.24 Downloading zoofs-0.1.24.tar.gz (28 kB) Requirement already satisfied: pandas>=1.3.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs==0.1.24) (1.3.2) Requirement already satisfied: numpy in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs==0.1.24) (1.21.2) Requirement already satisfied: scipy>=1.4.1 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs==0.1.24) (1.7.1) Requirement already satisfied: plotly>=5.6.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs==0.1.24) (5.6.0) Requirement already satisfied: colorlog>=6.6.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs==0.1.24) (6.6.0) Requirement already satisfied: colorama in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from colorlog>=6.6.0->zoofs==0.1.24) (0.4.4) Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from pandas>=1.3.0->zoofs==0.1.24) (2.8.2) Requirement already satisfied: pytz>=2017.3 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from pandas>=1.3.0->zoofs==0.1.24) (2021.1) Requirement already satisfied: tenacity>=6.2.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from plotly>=5.6.0->zoofs==0.1.24) (8.0.1) Requirement already satisfied: six in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from plotly>=5.6.0->zoofs==0.1.24) (1.16.0) Building wheels for collected packages: zoofs Building wheel for zoofs (setup.py): started Building wheel for zoofs (setup.py): finished with status 'done' Created wheel for zoofs: filename=zoofs-0.1.24-py3-none-any.whl size=27722 sha256=580564be9e188483eaebe97ebf28096152d7600f4b04330af9ce2f81b31fd37f Stored in directory: c:\users\user\appdata\local\pip\cache\wheels\61\67\35\51d8acdeae92edd559eccf1283366908b6f42c0dc15be9b38a Successfully built zoofs Installing collected packages: zoofs Attempting uninstall: zoofs Found existing installation: zoofs 0.1.23 Uninstalling zoofs-0.1.23: Successfully uninstalled zoofs-0.1.23 Successfully installed zoofs-0.1.24
WARNING: You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgrading via the 'c:\users\user\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command.
Load Breast cancer dataset¶
In [3]:
from sklearn.datasets import load_breast_cancer
import pandas as pd
data = load_breast_cancer()
X_train=pd.DataFrame(data['data'],columns=data['feature_names'])
y_train=pd.Series(data['target'])
Importing Zoofs Algo¶
In [4]:
from zoofs import DragonFlyOptimization
Setting up Objective function and fitting algo¶
In [5]:
from sklearn.metrics import log_loss
# define your own objective function, make sure the function receives four parameters,
# fit your model and return the objective value !
def objective_function_topass(model,X_train, y_train, X_valid, y_valid):
model.fit(X_train,y_train)
P=log_loss(y_valid,model.predict_proba(X_valid))
return P
# create object of algorithm
algo_object=DragonFlyOptimization(objective_function_topass,n_iteration=20,method='linear',
population_size=20,minimize=True)
import lightgbm as lgb
lgb_model = lgb.LGBMClassifier()
# fit the algorithm
algo_object.fit(lgb_model,X_train, y_train, X_train, y_train,verbose=True)
#plot your results
[ 2022-03-03 01:30:48,867 ] Finished iteration #0 with objective value 0.00042688493007979523. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:50,737 ] Finished iteration #1 with objective value 0.0004796281004668964. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:52,479 ] Finished iteration #2 with objective value 0.00048376590822600817. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:54,171 ] Finished iteration #3 with objective value 0.0004998724444697643. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:56,029 ] Finished iteration #4 with objective value 0.0005036852166138854. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:57,911 ] Finished iteration #5 with objective value 0.00046699316834635933. Current best value is 0.00042688493007979523 [ 2022-03-03 01:30:59,430 ] Finished iteration #6 with objective value 0.00046760312762003707. Current best value is 0.00042688493007979523 [ 2022-03-03 01:31:01,082 ] Finished iteration #7 with objective value 0.00042005690812107934. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:02,671 ] Finished iteration #8 with objective value 0.0005586242504837262. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:04,219 ] Finished iteration #9 with objective value 0.00045150269963537893. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:05,781 ] Finished iteration #10 with objective value 0.0004850606235918851. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:07,362 ] Finished iteration #11 with objective value 0.0004702033038147291. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:08,935 ] Finished iteration #12 with objective value 0.00048823263477758023. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:10,501 ] Finished iteration #13 with objective value 0.000531190727948647. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:12,026 ] Finished iteration #14 with objective value 0.00046054953525202937. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:13,638 ] Finished iteration #15 with objective value 0.0004799417423159305. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:15,612 ] Finished iteration #16 with objective value 0.0004927318414383095. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:17,332 ] Finished iteration #17 with objective value 0.0004987387937643816. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:18,957 ] Finished iteration #18 with objective value 0.000509979236724887. Current best value is 0.00042005690812107934 [ 2022-03-03 01:31:20,676 ] Finished iteration #19 with objective value 0.0004915487763485854. Current best value is 0.00042005690812107934
Out[5]:
['mean radius', 'mean texture', 'mean area', 'mean smoothness', 'mean compactness', 'mean concave points', 'mean symmetry', 'mean fractal dimension', 'radius error', 'perimeter error', 'area error', 'smoothness error', 'concavity error', 'worst radius', 'worst texture', 'worst area', 'worst smoothness', 'worst symmetry', 'worst fractal dimension']
Plotting the Results¶
In [6]:
algo_object.plot_history()