Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
Update usage.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
teobucci committed Feb 16, 2024
1 parent ee5b30a commit b23797f
Showing 1 changed file with 111 additions and 4 deletions.
115 changes: 111 additions & 4 deletions docs/source/notebooks/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,124 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" x1 x2 x3\n",
"0 1.764052 0.555963 -1.532921\n",
"1 0.400157 0.892474 -1.711970\n",
"2 0.978738 -0.422315 0.046135\n",
"3 2.240893 0.104714 -0.958374\n",
"4 1.867558 0.228053 -0.080812\n",
".. ... ... ...\n",
"995 0.412871 0.097751 2.079177\n",
"996 -0.198399 1.401523 -0.907466\n",
"997 0.094192 0.158434 -0.192404\n",
"998 -1.147611 -1.141901 -1.212516\n",
"999 -0.358114 -1.310970 -0.080599\n",
"\n",
"[1000 rows x 3 columns]\n",
"0 1.400443\n",
"1 1.424361\n",
"2 0.873649\n",
"3 2.523680\n",
"4 0.276468\n",
" ... \n",
"995 2.488424\n",
"996 1.042324\n",
"997 0.989404\n",
"998 -3.272610\n",
"999 -1.335277\n",
"Name: y, Length: 1000, dtype: float64\n",
"['x1', 'x2', 'x3']\n"
]
}
],
"source": [
"import pandas as pd"
"import pandas as pd\n",
"import tefs\n",
"\n",
"# Generate some random data\n",
"import numpy as np\n",
"np.random.seed(0)\n",
"n = 1000\n",
"x1 = np.random.normal(size=n)\n",
"x2 = np.random.normal(size=n)\n",
"x3 = np.random.normal(size=n)\n",
"x4 = x1 + x2 + x3 + np.random.normal(size=n)\n",
"y = x1 + x2 + x3 + np.random.normal(size=n)\n",
"data = pd.DataFrame({'x1': x1, 'x2': x2, 'x3': x3, 'x4': x4, 'y': y})\n",
"\n",
"# Define features and target\n",
"features = data[['x1', 'x2', 'x3']]\n",
"target = data['y']\n",
"features_names = list(features.columns)\n",
"\n",
"# Set k using the rule of thumb\n",
"n_samples = len(data)\n",
"k = n_samples // 10\n",
"direction = 'forward' # or 'backward'\n",
"lag_features = 1\n",
"lag_target = 1\n",
"\n",
"print(features)\n",
"print(target)\n",
"print(features_names)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding feature: x2 with TE score: -0.002435012237684899\n",
"Adding feature: x1 with TE score: -0.0015847873844891665\n",
"Adding feature: x3 with TE score: -0.001428146893958049\n"
]
}
],
"source": [
"\n",
"# Perform feature selection\n",
"result = tefs.fs(\n",
" features=features.values,\n",
" target=target.values,\n",
" k=k,\n",
" direction=direction,\n",
" lag_features=lag_features,\n",
" lag_target=lag_target,\n",
" verbose=1,\n",
" var_names=features_names, # optional\n",
" n_jobs=4,\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit b23797f

Please sign in to comment.