Grey Wolf Optimization¶
Installation¶
In [1]:
!pip install zoofs
Requirement already satisfied: zoofs in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (0.1.2) Requirement already satisfied: plotly in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs) (5.3.1) Requirement already satisfied: numpy in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs) (1.21.2) Requirement already satisfied: scipy in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs) (1.7.1) Requirement already satisfied: pandas in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from zoofs) (1.3.2) Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from pandas->zoofs) (2.8.2) Requirement already satisfied: pytz>=2017.3 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from pandas->zoofs) (2021.1) Requirement already satisfied: six>=1.5 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from python-dateutil>=2.7.3->pandas->zoofs) (1.16.0) Requirement already satisfied: tenacity>=6.2.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from plotly->zoofs) (8.0.1)
WARNING: You are using pip version 21.1.1; however, version 21.2.4 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 [2]:
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 [3]:
from zoofs import GreyWolfOptimization
Setting up Objective function and fitting algo¶
In [4]:
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=GreyWolfOptimization(objective_function_topass,n_iteration=10,
population_size=10,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
Best value of metric across iteration Best value of metric across population Iteration 0 0.0004348402642953398 0.0004348402642953398 Iteration 1 0.0004252355901921451 0.0004252355901921451 Iteration 2 0.000440584655018103 0.0004252355901921451 Iteration 3 0.0004136442607097853 0.0004136442607097853 Iteration 4 0.00043737218728283616 0.0004136442607097853 Iteration 5 0.00041228365686250113 0.00041228365686250113 Iteration 6 0.00043737218728283616 0.00041228365686250113 Iteration 7 0.0004136442607097853 0.00041228365686250113 Iteration 8 0.00041228365686250113 0.00041228365686250113 Iteration 9 0.0004198579115728509 0.00041228365686250113
Out[4]:
['mean radius', 'mean texture', 'mean perimeter', 'mean area', 'mean compactness', 'mean concavity', 'mean concave points', 'mean symmetry', 'mean fractal dimension', 'radius error', 'texture error', 'perimeter error', 'area error', 'smoothness error', 'compactness error', 'concavity error', 'concave points error', 'symmetry error', 'fractal dimension error', 'worst radius', 'worst texture', 'worst perimeter', 'worst area', 'worst smoothness', 'worst compactness', 'worst concavity', 'worst concave points', 'worst symmetry', 'worst fractal dimension']
Plotting the Results¶
In [5]:
algo_object.plot_history()
In [ ]: