diff --git a/README.md b/README.md index 96ef48f..3798041 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,12 @@ And open the resulting `index.html` in your browser to see the results. Here is what I get in my django website:  + +## Automating notebook execution and rendering + +Inside a docker container of the jupyter/datascience-notebook image, run the container and run bash. + +* Mount the root directory of the repository onto /home/jovian/work before launching (docker run -v `pwd`:/home/jovyan/work/ -d -p 8888:8888 jupyter/datascience-notebook) +* Execute bash inside the container (docker exec -it [containerId] bash) +* Run launchAndRender.sh [notebookName]. The notebook will be expected atthe "notebooks" folder, and should be [notebookName].ipynb +* A [notebookName].html file will be output \ No newline at end of file diff --git a/css/notebook.css b/css/notebook.css index d7dec4b..e75feae 100644 --- a/css/notebook.css +++ b/css/notebook.css @@ -559,3 +559,33 @@ div.output_javascript:empty { .th { text-center: left; } + + +.dataframe tbody tr { + text-align: right; + vertical-align: middle; + padding: 0.5em 0.5em; + line-height: normal; + white-space: normal; + max-width: none; + border: none; +} + +.dataframe tr:nth-child(odd) td { + background-color: #f5f5f5; + /* font-weight: bold; */ +} + +.dataframe th { + text-align: right; + vertical-align: middle; + padding: 0.5em 0.5em; + line-height: normal; + white-space: normal; + max-width: none; + border: none; +} + +.dataframe table { + border: none; +} \ No newline at end of file diff --git a/exportToBlogpost.sh b/exportToBlogpost.sh new file mode 100644 index 0000000..51def5d --- /dev/null +++ b/exportToBlogpost.sh @@ -0,0 +1,33 @@ +#!/usr/bin/bash + +#run nbconvert on a notebook, copy to the templates folter, create a new template and render. + +#First argument: File name of the notebook to work on: e.g., if the notebook is analysis.ipynb, argument is analysis. +#Second argument: Output directory. +#Third argument: title of the post +TITLE=$3 +OUTPUT_DIR=$2 +POST_DATE=`date +'%Y'-%m-%d` +cd notebooks/ +echo "Converting" +jupyter nbconvert --to markdown $1.ipynb + +cd .. +echo "Appending to base post" +cp ./base_post.md $OUTPUT_DIR/$POST_DATE-$1.md + +echo "Copying images" +mkdir $OUTPUT_DIR/images/ +cat ./notebooks/$1.md | tee -a $OUTPUT_DIR/$POST_DATE-$1.md +cp ./notebooks/$1_files/* $OUTPUT_DIR/images/ +echo "Replacing $1" + +sed -ri "s/__TITLE__/$TITLE/g" $OUTPUT_DIR/$POST_DATE-$1.md +sed -ri "s/__DATE__/$POST_DATE/g" $OUTPUT_DIR/$POST_DATE-$1.md +sed -ri "s/$1_files/\/assets\/images\//g" $OUTPUT_DIR/$POST_DATE-$1.md + +#cd .. + +#sed -r "s/FNAME/'$1.html'/g" ./templates/main.html > ./templates/main_$1.html + +#python render.py main_$1.html output_$1.html diff --git a/index.html b/index.html index 246d805..371bf19 100644 --- a/index.html +++ b/index.html @@ -141,7 +141,7 @@
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
@@ -178,7 +178,7 @@
def make_sample(nexamples, means=([0.,0.],[1.,1.]), sigma=1.):
normal = np.random.multivariate_normal
# squared width:
@@ -220,7 +220,7 @@
sgx, sgy = make_sample(30)
tgx, tgy = make_sample(200)
@@ -236,7 +236,7 @@ # note how the two categories are plotted
# together in one go by providing the
# label array as color argument (c=sgy)
@@ -261,7 +261,7 @@
-
-
+
from sklearn.neural_network import MLPClassifier
mlp = MLPClassifier(hidden_layer_sizes=(50,50,50), activation='relu', max_iter=10000, random_state=1)
@@ -357,7 +357,7 @@
-
+
def plot_result(sample, targets, linrange=(-5,5,101)):
xmin, xmax, npoints = linrange
gridx1, gridx2 = np.meshgrid(np.linspace(xmin,xmax,npoints), np.linspace(xmin,xmax,npoints))
@@ -382,7 +382,7 @@
-
+
plot_result(sgx,sgy)
@@ -394,7 +394,7 @@
-
-
+
plot_result(tgx,tgy)
@@ -435,7 +435,7 @@
-
-
+
mlp = MLPClassifier(hidden_layer_sizes=(5,), activation='relu', max_iter=10000, random_state=1)
mlp.fit(sgx,sgy)
plot_result(tgx,tgy)
@@ -489,7 +489,7 @@
-
-
+
sgx, sgy = make_sample(10000)
mlp = MLPClassifier(hidden_layer_sizes=(50,50,50), activation='relu', max_iter=10000, random_state=1)
mlp.fit(sgx,sgy)
@@ -533,7 +533,7 @@
-
-
+
sgxa, sgya = make_sample(1000, ([0.,0],[3.,3.]), 0.3)
sgxb, sgyb = make_sample(1000, ([1.,1],[4.,4.]), 0.3)
sgxc, sgyc = make_sample(1000, ([5.,5.],[-2.,-2.]), 0.6)
@@ -603,7 +603,7 @@
-
+
plt.scatter(sgx[:,0], sgx[:,1], alpha=0.5, c=sgy)
plt.xlabel('x1')
plt.ylabel('x2')
@@ -625,7 +625,7 @@
-
-
+
mlp = MLPClassifier(hidden_layer_sizes=(3,), activation='relu', max_iter=10000, random_state=1)
mlp.fit(sgx,sgy)
@@ -685,7 +685,7 @@
-
+
plot_result(sgx,sgy,linrange=(-4,7,201))
@@ -697,7 +697,7 @@
-
-
+
mlp = MLPClassifier(hidden_layer_sizes=(5,), activation='relu', max_iter=10000, random_state=1)
mlp.fit(sgx,sgy)
plot_result(sgx,sgy,linrange=(-4,7,201))
@@ -748,7 +748,7 @@
-
-
+
mlp = MLPClassifier(hidden_layer_sizes=(50,50,50), activation='relu', max_iter=10000, random_state=1)
mlp.fit(sgx,sgy)
plot_result(sgx,sgy,linrange=(-4,7,201))
@@ -791,7 +791,7 @@
-