This commit is contained in:
mathew 2017-05-20 09:55:02 +01:00
Родитель 85edfe7c87
Коммит 55567a8bb4
4 изменённых файлов: 0 добавлений и 871 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,235 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"import pandas as pd\n",
"from sklearn.preprocessing import StandardScaler\n",
"\n",
"from sklearn.pipeline import Pipeline, FeatureUnion\n",
"\n",
"from sklearn.model_selection import cross_val_score, cross_val_predict\n",
"from xgboost import XGBClassifier\n",
"import numpy as np\n",
"import itertools\n",
"import seaborn\n",
"from sklearn.metrics import roc_auc_score\n",
"from experiments.libs import loaders\n",
"from sklearn.model_selection import StratifiedKFold\n",
"\n",
"from sklearn.svm import LinearSVC\n",
"from sklearn.decomposition import PCA\n",
"from sklearn.metrics import roc_auc_score\n",
"from xgboost import XGBModel\n",
"\n",
"from lightgbm import LGBMClassifier\n",
"\n",
"import mne\n",
"from scipy.io import loadmat\n",
"from libs.loaders import load_bci\n",
"from itertools import zip_longest\n",
"from copy import deepcopy\n",
"\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pipeline_steps = [('scale', StandardScaler())]\n",
"continuous_pipeline = Pipeline(steps=pipeline_steps)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"featurisers = [('continuous', continuous_pipeline)]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"xgb_clf_pipeline = Pipeline(steps=[('features', FeatureUnion(featurisers)),\n",
" ('clf', XGBClassifier(max_depth=2, \n",
" learning_rate=0.1, \n",
" scale_pos_weight=2,\n",
" n_estimators=100,\n",
" gamma=0.1,\n",
" subsample=1))]) "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"lgbm_clf_pipeline = Pipeline(steps=[('features', FeatureUnion(featurisers)),\n",
" ('clf', LGBMClassifier(num_leaves=2**2,\n",
" learning_rate=0.1, \n",
" scale_pos_weight=2,\n",
" n_estimators=100,\n",
" subsample=1))]) "
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"X, y, X_test, y_test = load_bci()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 1min 38s, sys: 688 ms, total: 1min 39s\n",
"Wall time: 5.59 s\n"
]
},
{
"data": {
"text/plain": [
"Pipeline(steps=[('features', FeatureUnion(n_jobs=1,\n",
" transformer_list=[('continuous', Pipeline(steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True))]))],\n",
" transformer_weights=None)), ('clf', XGBClassifier(base_score=0.5, colsample_bylevel=1, colsample_bytree=1,\n",
" gamma=0...logistic', reg_alpha=0, reg_lambda=1,\n",
" scale_pos_weight=2, seed=0, silent=True, subsample=1))])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"xgb_clf_pipeline.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.68251896814231094"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_pred = xgb_clf_pipeline.predict_proba(X_test)\n",
"roc_auc_score(y_test, y_pred[:, 1])"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 17.3 s, sys: 168 ms, total: 17.5 s\n",
"Wall time: 2.4 s\n"
]
},
{
"data": {
"text/plain": [
"Pipeline(steps=[('features', FeatureUnion(n_jobs=1,\n",
" transformer_list=[('continuous', Pipeline(steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True))]))],\n",
" transformer_weights=None)), ('clf', LGBMClassifier(boosting_type='gbdt', colsample_bytree=1, drop_rate=0.1,\n",
" is_un... subsample_for_bin=50000, subsample_freq=1, uniform_drop=False,\n",
" xgboost_dart_mode=False))])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"lgbm_clf_pipeline.fit(X, y)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

Просмотреть файл

@ -1,95 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Playground\n",
"\n",
"Playground notebook to quickly test code."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"System version: 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06) \n",
"[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]\n"
]
}
],
"source": [
"import os,sys\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from lightgbm.sklearn import LGBMRegressor\n",
"import xgboost as xgb\n",
"\n",
"from libs.timer import Timer\n",
"\n",
"print(\"System version: {}\".format(sys.version))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.000576000000000132\n"
]
}
],
"source": [
"with Timer() as t:\n",
" for i in range(10000):\n",
" r = 1\n",
"print(t.interval)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

Просмотреть файл