<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Simple start to Jupyter notebooks
A
Step1:  Importing modules
Step2:  Some Editing tricks
Demonstrating auto complete.
<kbd>TAB</kbd> for auto-completion of identifier,
<kbd>Shift+Enter</kbd> for auto-completion of parameters
Note to self
Step3:  Very quick plotting (just for export really)
Step4:  Try export > html, > pdf (requires pandoc or even a LaTeX installation).
Then try again and compare the figures with the setting
Step5:  Some magic and multiple outputs
Step6:  Jupyter has a kind of meta-commands starting with the percent character. Some of these are useful for displaying information, such as writing formulas with latex.
Step7:  Useful to know that we can also set environment variables (also useful for Theano)
Step8:  %store to pass variables between notebooks!
Retrieve in other notebook with %store -r var_name
Step9:  No clue what kendalltau is?
<ASSISTANT_TASK:>
Python Code:
!ls
!pip install --user pandas matplotlib sklearn seaborn
!pip install version_information
%load_ext version_information
%version_information pandas, sklearn
!pip install watermark
%load_ext watermark
%watermark -a "Gerrit Gruben" -d -t -v -p numpy,pandas -g
Explanation: Simple start to Jupyter notebooks
A: Oh snap! The initializing cell is missing!
B: No problem! Jupyter notebooks are able to use magic
End of explanation
from somemodule import hello
hello()
hello()
del hello
%load_ext autoreload
%autoreload 2
%aimport somemodule
somemodule.hello()
somemodule.hello()
from IPython.display import FileLink
FileLink("Simple.ipynb")
Explanation: Importing modules
End of explanation
import sklearn
from sklearn.datasets import load_boston
df = load_boston()
X, y = df.data, df.target
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)
from sklearn.metrics import mean_squared_error
from sklearn.ensemble import RandomForestRegressor
rf_reg = RandomForestRegressor(2)
rf_reg.fit(X_train, y_train)
print(mean_squared_error(y_test, rf_reg.predict(X_test)))
# Just need a df
from sklearn.datasets import california_housing
cal = california_housing.fetch_california_housing()
df = pd.DataFrame(data=cal.data, columns=cal.feature_names, index=cal.target)
df.head(10)
Explanation: Some Editing tricks
Demonstrating auto complete.
<kbd>TAB</kbd> for auto-completion of identifier,
<kbd>Shift+Enter</kbd> for auto-completion of parameters
Note to self: show merging of cells, split etc. here
End of explanation
%matplotlib inline
import matplotlib.pyplot as plt
plt.scatter(df.MedInc, df.index)
import seaborn as sns
sns.jointplot(df.MedInc, df.index)
Explanation: Very quick plotting (just for export really)
End of explanation
%config InlineBackend.figure_format = "retina"
Explanation: Try export > html, > pdf (requires pandoc or even a LaTeX installation).
Then try again and compare the figures with the setting:
End of explanation
x, y = 5, 3
x
y
# Show all output values
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
x, y = 5, 3
x
y
Explanation: Some magic and multiple outputs
End of explanation
%lsmagic
%whos
%%latex
$$ x^3 + C = \int{\frac{1}{3} x^2 \; dx} \quad (C \in \mathbb{R})$$
%%system
ls -laH
du -sh .
Explanation: Jupyter has a kind of meta-commands starting with the percent character. Some of these are useful for displaying information, such as writing formulas with latex.
End of explanation
%env OMP_NUM_THREADS=8
Explanation: Useful to know that we can also set environment variables (also useful for Theano)
End of explanation
%%writefile some_code.py
import numpy as np
from scipy.stats import kendalltau
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="ticks")
rs = np.random.RandomState(11)
x = rs.gamma(2, size=1000)
y = -.5 * x + rs.normal(size=1000)
sns.jointplot(x, y, kind="hex", stat_func=kendalltau, color="#4CB391")
plt.show()
Explanation: %store to pass variables between notebooks!
Retrieve in other notebook with %store -r var_name
End of explanation
kendalltau?
%pycat some_code.py
%run some_code.py
%matplotlib inline
%run some_code.py
InteractiveShell.ast_node_interactivity = "last"
Explanation: No clue what kendalltau is?
End of explanation
<END_TASK>