Skip to content

Commit

Permalink
updated examples with proper paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nestordemeure committed Mar 21, 2020
1 parent 81d22a2 commit bb6c792
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 42 deletions.
102 changes: 77 additions & 25 deletions examples/1_basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,29 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true
},
"source": [
"## Regression"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true,
"hidden": true
},
"source": [
"### Problem definition"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race', 'salary']\n",
Expand All @@ -89,7 +96,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"data = (TabularList.from_df(df, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs)\n",
Expand All @@ -100,38 +109,49 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true,
"hidden": true
},
"source": [
"### Model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"Creates a gaussian process model:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"learn = tabularGP_learner(data)"
]
},
{
"cell_type": "raw",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"Trains the model:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -193,14 +213,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true,
"hidden": true
},
"source": [
"### Uncertainty"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"Gaussian processes produce a mean (the usual output) and a standard deviation (modelizing the uncertainty on the result).\n",
"Here they are stored respectively in the index 0 and 1 of the last dimenssion of the tensor outputed by the model:"
Expand All @@ -209,7 +234,9 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [
{
"name": "stdout",
Expand All @@ -235,15 +262,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true
},
"source": [
"### Problem definition"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race']\n",
Expand All @@ -254,7 +285,9 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"data = (TabularList.from_df(df, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs)\n",
Expand All @@ -265,22 +298,28 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true
},
"source": [
"### Model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"Creates a gaussian process model (notice that nothing is doen to indicate that this is a classification problem):"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"learn = tabularGP_learner(data)"
Expand All @@ -289,7 +328,9 @@
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -351,7 +392,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"heading_collapsed": true
},
"source": [
"### Uncertainty"
]
Expand All @@ -360,24 +403,29 @@
"cell_type": "code",
"execution_count": 12,
"metadata": {
"hidden": true,
"scrolled": true
},
"outputs": [],
"source": [
"from loss_functions import gp_softmax"
"from tabularGP.loss_functions import gp_softmax"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"Classification models also have a standard deviation but, following the pytorch convention, the output is a raw logit and not a genuine probability (hence the means might not sum to one):"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [
{
"name": "stdout",
Expand All @@ -397,15 +445,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hidden": true
},
"source": [
"The proper way to get probabilities is to apply `gp_softmax` to your raw output (as you would apply a `softmax` to a traditional classification output):"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"metadata": {
"hidden": true
},
"outputs": [
{
"name": "stdout",
Expand Down
Loading

0 comments on commit bb6c792

Please sign in to comment.