"* ctrl+ENTER evaluates the current cell; if it contains Python code, it runs the code, if it contains Markdown, it returns rendered text.\n",
"* alt+ENTER evaluates the current cell and adds a new cell below it.\n",
"* If you click to the left of a cell, you'll notice the frame changes color to blue. You can erase a cell by hitting 'dd' (that's two \"d\"s in a row) when the frame is blue."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Supervised Learning Model Skeleton\n",
"\n",
"We'll use this skeleton for implementing different supervised learning algorithms."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"class Model:\n",
" \n",
" def fit(self):\n",
" \n",
" raise NotImplementedError\n",
" \n",
" def predict(self, test_points):\n",
" raise NotImplementedError"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## General supervised learning performance related functions "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\"conf_matrix\" function that takes as input an array of true labels (*true*) and an array of predicted labels (*pred*)."
" # false positives (fp) and false negatives (fn)\n",
" \n",
" size = len(true)\n",
" for i in range(size):\n",
" if true[i]==1:\n",
" if pred[i] == 1: \n",
" tp += 1\n",
" else: \n",
" fn += 1\n",
" else:\n",
" if pred[i] == 0:\n",
" tn += 1 \n",
" else:\n",
" fp += 1 \n",
" \n",
" # returns the confusion matrix as numpy.ndarray\n",
" return np.array([tp,fn, fp, tn])"
]
}
],
"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.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# JUPYTER NOTEBOOK TIPS
Each rectangular box is called a cell.
* ctrl+ENTER evaluates the current cell; if it contains Python code, it runs the code, if it contains Markdown, it returns rendered text.
* alt+ENTER evaluates the current cell and adds a new cell below it.
* If you click to the left of a cell, you'll notice the frame changes color to blue. You can erase a cell by hitting 'dd' (that's two "d"s in a row) when the frame is blue.
%% Cell type:markdown id: tags:
# Supervised Learning Model Skeleton
We'll use this skeleton for implementing different supervised learning algorithms.
%% Cell type:code id: tags:
``` python
classModel:
deffit(self):
raiseNotImplementedError
defpredict(self,test_points):
raiseNotImplementedError
```
%% Cell type:markdown id: tags:
## General supervised learning performance related functions
%% Cell type:markdown id: tags:
"conf_matrix" function that takes as input an array of true labels (*true*) and an array of predicted labels (*pred*).