Skip to content

Commit

Permalink
Fixed compatibility issues in example notebook for recent versions of…
Browse files Browse the repository at this point in the history
… Python 3 and pandas.
  • Loading branch information
Mark Peng committed Dec 27, 2018
1 parent f68cfcd commit badc33e
Showing 1 changed file with 50 additions and 36 deletions.
86 changes: 50 additions & 36 deletions boruta/examples/Madalon_Data_Set.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
Expand All @@ -53,21 +51,18 @@
" # URLS for dataset via UCI\n",
" train_data_url='https://archive.ics.uci.edu/ml/machine-learning-databases/madelon/MADELON/madelon_train.data'\n",
" train_label_url='https://archive.ics.uci.edu/ml/machine-learning-databases/madelon/MADELON/madelon_train.labels'\n",
" \n",
" \n",
"\n",
" X_data = pd.read_csv(train_data_url, sep=\" \", header=None)\n",
" y_data = pd.read_csv(train_label_url, sep=\" \", header=None)\n",
" data = X_data.ix[:,0:499]\n",
" data['target'] = y_data[0] \n",
" data = X_data.loc[:, :499]\n",
" data['target'] = y_data[0]\n",
" return data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"data = load_data()"
Expand All @@ -76,9 +71,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -267,13 +260,11 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"y=data.pop('target')\n",
"X=data.copy()"
"y = data.pop('target')\n",
"X = data.copy().values"
]
},
{
Expand All @@ -293,9 +284,9 @@
},
"outputs": [],
"source": [
"rf = RandomForestClassifier(n_jobs=-1, class_weight='auto', max_depth=7)\n",
"# define Boruta feature selection method\n",
"feat_selector = BorutaPy(rf, n_estimators='auto', verbose=2)"
"rf = RandomForestClassifier(n_jobs=-1, class_weight=None, max_depth=7, random_state=0)\n",
"# Define Boruta feature selection method\n",
"feat_selector = BorutaPy(rf, n_estimators='auto', verbose=2, random_state=0)"
]
},
{
Expand All @@ -308,12 +299,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"feat_selector.fit(X,y)"
"feat_selector.fit(X, y)"
]
},
{
Expand All @@ -328,15 +317,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# check selected features\n",
"# Check selected features\n",
"print(feat_selector.support_)\n",
"#select the chosen features from our dataframe.\n",
"selected = X.ix[:,feat_selector.support_]\n",
"# Select the chosen features from our dataframe.\n",
"selected = X[:, feat_selector.support_]\n",
"print (\"\")\n",
"print (\"Selected Feature Matrix Shape\")\n",
"print (selected.shape)"
Expand All @@ -352,9 +339,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"feat_selector.ranking_"
Expand Down Expand Up @@ -386,9 +371,38 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.6.5"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

0 comments on commit badc33e

Please sign in to comment.