Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft - sklearn-api #29

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zoofs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from zoofs.gravitationaloptimization import GravitationalOptimization
from zoofs.baseoptimizationalgorithm import BaseOptimizationAlgorithm
from zoofs.harrishawkoptimization import HarrisHawkOptimization

__all__ = ["feature_selection"]
181 changes: 181 additions & 0 deletions zoofs/feature_selection/DragonFly.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# from dragon_fly import DragonFlyFeatureSelectionCV\n",
"from zoofs.feature_selection import DragonFlySelectionCV\n",
"from sklearn.linear_model import Lasso\n",
"from sklearn.datasets import load_diabetes"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"selector = DragonFlySelectionCV(Lasso())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"X,y = load_diabetes(return_X_y=True)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"self.best_features_\n",
"[0 1 2 3 4 5 6 7 8 9]\n"
]
},
{
"data": {
"text/plain": [
"DragonFlyFeatureSelectionCV(estimator=Lasso())"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"selector.fit(X,y)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"bool_ = selector.transform(X)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n",
" 0.01990842, -0.01764613],\n",
" [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
" -0.06832974, -0.09220405],\n",
" [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n",
" 0.00286377, -0.02593034],\n",
" ...,\n",
" [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n",
" -0.04687948, 0.01549073],\n",
" [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n",
" 0.04452837, -0.02593034],\n",
" [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
" -0.00421986, 0.00306441]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bool_"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(442, 10)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bool_.shape"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.pipeline import Pipeline"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "Pipeline.__init__() takes 2 positional arguments but 3 were given",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m pipe \u001b[38;5;241m=\u001b[39m \u001b[43mPipeline\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mselector\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mselector\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mestimator\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mLasso\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[1;31mTypeError\u001b[0m: Pipeline.__init__() takes 2 positional arguments but 3 were given"
]
}
],
"source": [
"pipe = Pipeline([\"selector\", selector], [\"estimator\", Lasso()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "py310",
"language": "python",
"name": "py310"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
5 changes: 5 additions & 0 deletions zoofs/feature_selection/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .dragonfly import DragonFlySelectionCV

__all__ = [
"DragonFlySelectionCV",
]
Loading