In [2]:
!ls
In [3]:
!pip install --user pandas matplotlib sklearn seaborn
In [4]:
!pip install version_information
In [5]:
%load_ext version_information
%version_information pandas, sklearn
Out[5]:
In [1]:
!pip install watermark
In [2]:
%load_ext watermark
%watermark -a "Gerrit Gruben" -d -t -v -p numpy,pandas -g
In [6]:
from somemodule import hello
In [7]:
hello()
In [8]:
hello()
In [25]:
del hello
In [20]:
%load_ext autoreload
%autoreload 2
In [27]:
%aimport somemodule
In [28]:
somemodule.hello()
In [30]:
somemodule.hello()
In [31]:
from IPython.display import FileLink
In [33]:
FileLink("Simple.ipynb")
Out[33]:
Demonstrating auto complete.
TAB for auto-completion of identifier,
Shift+Enter for auto-completion of parameters
Note to self: show merging of cells, split etc. here
In [1]:
import sklearn
In [2]:
from sklearn.datasets import load_boston
In [ ]:
df = load_boston()
In [ ]:
X, y = df.data, df.target
In [ ]:
from sklearn.cross_validation import train_test_split
In [ ]:
X_train, X_test, y_train, y_test = train_test_split(X, y)
In [ ]:
from sklearn.metrics import mean_squared_error
In [ ]:
from sklearn.ensemble import RandomForestRegressor
In [3]:
rf_reg = RandomForestRegressor(2)
In [29]:
rf_reg.fit(X_train, y_train)
print(mean_squared_error(y_test, rf_reg.predict(X_test)))
In [51]:
# 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)
Out[51]:
In [56]:
%matplotlib inline
import matplotlib.pyplot as plt
In [62]:
plt.scatter(df.MedInc, df.index)
Out[62]:
In [63]:
import seaborn as sns
In [64]:
sns.jointplot(df.MedInc, df.index)
Out[64]:
Try export > html, > pdf (requires pandoc or even a LaTeX installation).
Then try again and compare the figures with the setting:
In [65]:
%config InlineBackend.figure_format = "retina"
In [31]:
x, y = 5, 3
x
y
Out[31]:
In [32]:
# Show all output values
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
In [33]:
x, y = 5, 3
x
y
Out[33]:
Out[33]:
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.
In [34]:
%lsmagic
Out[34]:
In [52]:
%whos
In [35]:
%%latex
$$ x^3 + C = \int{\frac{1}{3} x^2 \; dx} \quad (C \in \mathbb{R})$$
In [36]:
%%system
ls -laH
du -sh .
Out[36]:
Useful to know that we can also set environment variables (also useful for Theano)
In [1]:
%env OMP_NUM_THREADS=8
%store to pass variables between notebooks!
Retrieve in other notebook with %store -r var_name
In [10]:
%%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()
No clue what kendalltau is?
In [14]:
kendalltau?
In [12]:
%pycat some_code.py
In [13]:
%run some_code.py
In [6]:
%matplotlib inline
In [7]:
%run some_code.py
In [37]:
InteractiveShell.ast_node_interactivity = "last"