restructure project again

This commit is contained in:
hobogalaxy committed 2020-11-27 01:19:11 +01:00
1 parent 20c451bc3d
commit ee7006a92a
24 files changed
+208 -633

No files matched your search

View File
Whitespace-only changes.
-372
View File
@@ -1,372 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import modules from parent directory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"# add directory above current directory to path\n",
"import sys\n",
"sys.path.insert(0, '..')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"# now we can import modules from parent directory\n",
"import train\n",
"import pipeline_modules"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define function to print object length with commas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"showlen = lambda data: print(f\"{len(data):,}\")\n",
"showlen([0 for i in range(2395940)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create quick progress bars with tqdm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"scrolled": true
},
"outputs": [],
"source": [
"from tqdm import tqdm\n",
"import time\n",
"\n",
"for i in tqdm(range(10)):\n",
" time.sleep(1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"source": [
"### Prettier ipywidgets version of the progress bar specifically for the notebook environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from tqdm.auto import tqdm\n",
"\n",
"for i in tqdm(range(10)):\n",
" time.sleep(1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"source": [
"### Beyond basic for loops, you can also use it in list comprehensions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"some_list = [x**2 for x in tqdm(10*[0])]"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"source": [
"### You can even use it with multiprocessing\n",
"https://stackoverflow.com/questions/41920124/multiprocessing-use-tqdm-to-display-a-progress-bar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### If you’re iterating over a generator, tqdm won’t know the length and the progress bar will be more limited but if you know or can calculate the total length you can supply that as an argument"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# generator expressions are surrounded by parenthesis ()\n",
"generator = (x**2 for x in [1, 2, 3, 4])\n",
"# print(next(generator))\n",
"\n",
"some_list = [x for x in tqdm(generator, total=4)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Jupyter Notebook Shortcuts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Esc will take you into command mode where you can navigate around your notebook with arrow keys.\n",
"- While in command mode:\n",
" - A to insert a new cell above the current cell, B to insert a new cell below.\n",
" - M to change the current cell to Markdown, Y to change it back to code\n",
" - D + D (press the key twice) to delete the current cell\n",
" - Enter will take you from command mode back into edit mode for the given cell.\n",
"- Shift + Tab will show you the Docstring (documentation) for the the object you have just typed in a code cell – you can keep pressing this short cut to cycle through a few modes of documentation.\n",
"- Ctrl + Shift + - will split the current cell into two from where your cursor is.\n",
"- Esc + O Toggle cell output.\n",
"- Select Multiple Cells:\n",
" - Shift + J or Shift + Down selects the next sell in a downwards direction. You can also select sells in an upwards direction by using Shift + K or Shift + Up.\n",
" - Once cells are selected, you can then delete / copy / cut / paste / run them as a batch. This is helpful when you need to move parts of a notebook.\n",
" - You can also use Shift + M to merge multiple cells."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from IPython.display import IFrame, HTML, YouTubeVideo\n",
"# YouTubeVideo(\"ZbrRrXiWBKc\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from ipywidgets import FloatSlider, interactive, IntSlider"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"def simple_ex(amplitude=2.0, phase=0.0):\n",
" x = np.linspace(-2*np.pi, 2*np.pi, 1000)\n",
" y = amplitude * np.sin(x + phase)\n",
" plt.rcParams['figure.figsize'] = 8,6\n",
" plt.figure()\n",
" plt.plot(x, y)\n",
" plt.xlim(-3, 3)\n",
" plt.ylim(-2*np.pi, 2*np.pi)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"amplitude_slider = FloatSlider(value=2.0, min=-10, max=10.0, step=.05)\n",
"phase_slider = FloatSlider(value=0.0, min=-np.pi, max=np.pi, step=.05)\n",
"\n",
"w = interactive(simple_ex,\n",
" amplitude=amplitude_slider,\n",
" phase=phase_slider\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('loan_train.csv')\n",
"\n",
"import pandas_profiling\n",
"report = pandas_profiling.ProfileReport(data)\n",
"\n",
"report"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# print many outputs in the same cell!\n",
"from IPython.core.interactiveshell import InteractiveShell\n",
"InteractiveShell.ast_node_interactivity = \"all\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"%history -t"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"is_executing": false,
"name": "#%% md\n"
}
},
"source": [
"https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"\n"
]
}
],
"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.7.4"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"metadata": {
"collapsed": false
},
"source": []
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}