{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Important: This notebook will only work with fastai-0.7.x. Do not try to run any fastai-1.x code from this path in the repository because it will load fastai-0.7.x**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%reload_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"\n",
"from fastai.nlp import *\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.svm import LinearSVC\n",
"from torchtext import vocab, data, datasets\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sl=1000\n",
"vocab_size=200000"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" link | \n",
" time | \n",
" favorites | \n",
" rts | \n",
" authors | \n",
" category | \n",
" published | \n",
" summary | \n",
" title | \n",
" tweeted | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" arxiv.org/abs/1611.10003 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" [Tom A. F. Anderson, C. -H. Ruan] | \n",
" q-bio.NC | \n",
" 2016-11-30 05:17:11 | \n",
" In summary of the research findings presented ... | \n",
" Vocabulary and the Brain: Evidence from Neuroi... | \n",
" 0 | \n",
"
\n",
" \n",
" 1 | \n",
" arxiv.org/abs/1611.10007 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" [M. Amin Rahimian, Amir G. Aghdam] | \n",
" cs.SY | \n",
" 2016-11-30 05:37:11 | \n",
" In this paper, structural controllability of a... | \n",
" Structural Controllability of Multi-Agent Netw... | \n",
" 0 | \n",
"
\n",
" \n",
" 2 | \n",
" arxiv.org/abs/1611.10010 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" [Debidatta Dwibedi, Tomasz Malisiewicz, Vijay ... | \n",
" cs.CV | \n",
" 2016-11-30 06:00:47 | \n",
" We present a Deep Cuboid Detector which takes ... | \n",
" Deep Cuboid Detection: Beyond 2D Bounding Boxes | \n",
" 0 | \n",
"
\n",
" \n",
" 3 | \n",
" arxiv.org/abs/1611.10012 | \n",
" 2016-12-01 01:46:12 | \n",
" 11.0 | \n",
" 2.0 | \n",
" [Jonathan Huang, Vivek Rathod, Chen Sun, Mengl... | \n",
" cs.CV | \n",
" 2016-11-30 06:06:15 | \n",
" In this paper, we study the trade-off between ... | \n",
" Speed/accuracy trade-offs for modern convoluti... | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" arxiv.org/abs/1611.10014 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" [Yoones Hashemi, Amir H. Banihashemi] | \n",
" cs.IT | \n",
" 2016-11-30 06:12:45 | \n",
" In this paper, we propose a characterization o... | \n",
" Characterization and Efficient Exhaustive Sear... | \n",
" 0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" link time favorites rts \\\n",
"0 arxiv.org/abs/1611.10003 NaN NaN NaN \n",
"1 arxiv.org/abs/1611.10007 NaN NaN NaN \n",
"2 arxiv.org/abs/1611.10010 NaN NaN NaN \n",
"3 arxiv.org/abs/1611.10012 2016-12-01 01:46:12 11.0 2.0 \n",
"4 arxiv.org/abs/1611.10014 NaN NaN NaN \n",
"\n",
" authors category \\\n",
"0 [Tom A. F. Anderson, C. -H. Ruan] q-bio.NC \n",
"1 [M. Amin Rahimian, Amir G. Aghdam] cs.SY \n",
"2 [Debidatta Dwibedi, Tomasz Malisiewicz, Vijay ... cs.CV \n",
"3 [Jonathan Huang, Vivek Rathod, Chen Sun, Mengl... cs.CV \n",
"4 [Yoones Hashemi, Amir H. Banihashemi] cs.IT \n",
"\n",
" published summary \\\n",
"0 2016-11-30 05:17:11 In summary of the research findings presented ... \n",
"1 2016-11-30 05:37:11 In this paper, structural controllability of a... \n",
"2 2016-11-30 06:00:47 We present a Deep Cuboid Detector which takes ... \n",
"3 2016-11-30 06:06:15 In this paper, we study the trade-off between ... \n",
"4 2016-11-30 06:12:45 In this paper, we propose a characterization o... \n",
"\n",
" title tweeted \n",
"0 Vocabulary and the Brain: Evidence from Neuroi... 0 \n",
"1 Structural Controllability of Multi-Agent Netw... 0 \n",
"2 Deep Cuboid Detection: Beyond 2D Bounding Boxes 0 \n",
"3 Speed/accuracy trade-offs for modern convoluti... 1 \n",
"4 Characterization and Efficient Exhaustive Sear... 0 "
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PATH='data/arxiv/arxiv.csv'\n",
"\n",
"# You can download a similar to Jeremy's original arxiv.csv here: https://drive.google.com/file/d/0B34BjUTAgwm6SzdPWDAtVG1vWVU/. It comes from this article https://hackernoon.com/building-brundage-bot-10252facf3d1 and github https://github.com/amauboussin/arxiv-twitterbot, just rename it to arxiv.csv\n",
"\n",
"df = pd.read_csv(PATH)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df['txt'] = df.category + ' ' + df.title + '\\n' + df.summary"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"q-bio.NC Vocabulary and the Brain: Evidence from Neuroimaging Studies\n",
"In summary of the research findings presented in this paper, various brain\n",
"regions are correlated with vocabulary and vocabulary acquisition. Semantic\n",
"associations for vocabulary seem to be located near brain areas that vary\n",
"according to the type of vocabulary, e.g. ventral temporal regions important\n",
"for words for things that can be seen. Semantic processing is believed to be\n",
"strongly associated with the ANG. Phonological ability has been closely related\n",
"to the anterior surfaces of the SMG. Pathways through the posterior SMG are\n",
"thought to link the anterior SMG and the ANG. In vocabulary tasks,\n",
"mediotemporal structures may be related to long-term memory processing, with\n",
"left hippocampal and parahippocampal regions related to long-term and working\n",
"memory, respectively. Precentral structures are associated with phonological\n",
"retrieval. Furthermore, many more regions of the brain are of interest in\n",
"vocabulary tasks, particularly in areas important for visual and auditory\n",
"processing. Furthermore, differences between brain anatomies can be attributed\n",
"to vocabulary demands of different languages.\n"
]
}
],
"source": [
"print(df.iloc[0].txt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"27188"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n=len(df); n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"val_idx = get_cv_idxs(n, val_pct=0.1)\n",
"((val,trn),(val_y,trn_y)) = split_by_idx(val_idx, df.txt.values, df.tweeted.values)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ngram logistic regression"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((24470, 3780668), 14938443)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"veczr = CountVectorizer(ngram_range=(1,3), tokenizer=tokenize)\n",
"trn_term_doc = veczr.fit_transform(trn)\n",
"val_term_doc = veczr.transform(val)\n",
"trn_term_doc.shape, trn_term_doc.sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"y=trn_y\n",
"x=trn_term_doc.sign()\n",
"val_x = val_term_doc.sign()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p = x[np.argwhere(y!=0)[:,0]].sum(0)+1\n",
"q = x[np.argwhere(y==0)[:,0]].sum(0)+1\n",
"r = np.log((p/p.sum())/(q/q.sum()))\n",
"b = np.log(len(p)/len(q))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.80316409124356147"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pre_preds = val_term_doc @ r.T + b\n",
"preds = pre_preds.T>0\n",
"(preds==val_y).mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.85062545989698313"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = LogisticRegression(C=0.1, fit_intercept=False)\n",
"m.fit(x, y);\n",
"\n",
"preds = m.predict(val_x)\n",
"(preds.T==val_y).mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"probs = m.predict_proba(val_x)[:,1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEWCAYAAAB42tAoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucXVV99/HPb26Z3GZyD5DbJBgSwh1CACkQBRGoglUf\nC2LVPlSq1WqrtY992pemqLXVx7Za8VFarNeCaIumCqXKJaByyWAuEEhCLoRMLiSTe2Yy91//+O3j\nOZnMnDmZzJ6Zc/J9v17nNefss8/e6+xJ9nfWWnutbe6OiIhIb8qGugAiIjK8KShERCQvBYWIiOSl\noBARkbwUFCIikpeCQkRE8lJQSEHMbI2ZLe5jnZlmdtjMygepWKkzs5fN7Jrk+RIz++5Ql0lksCko\nilxyIjuSnKBfNbN/NbMxA70fdz/L3R/rY51X3H2Mu3cO9P6Tk3R78j33m9mvzOyygd7PycLMvmlm\nHWZ2Wg/LP9NtWZ2ZuZlV5Cx7p5nVJ7+PHWb2oJn9Vj/K8admttPMDpjZN8xsRJ51R5nZV82sMVn/\n8Zz3cv99ZB5zjrc80jMFRWl4s7uPAS4ELgb+qvsKFor99/395HtOAh4FfjDE5RlwuSfjFPcxGngb\ncAC4tR+f/yjwj8DfAFOBmcBXgZuOcztvBD4BXA3UAXOAv87zkbuACcCZyc8/7fb+95M/VDKPTcdT\nHuldsZ84JIe7bwMeBM4GMLPHzOyzZvZLoBmYY2a1ZnZ38lfgNjP7TG5TkZm9z8xeNLNDZvaCmV2Y\nLM9tglmU/DV5MKnF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\nERHJS0EhIiJ5KShEujGzTjNbaWbPm9l/mtm4Ad7+e83sK8nzJWb2ZwO5fZGBpqAQOdYRdz/f3c8m\nxuh8cKgLJDKUFBQi+T1JzqRpZvZxM1uezOX/1znL350sW2Vm30mWvTm5V8oKM/u5mU0dgvKLnLBh\nOTJbZDgws3Ji2oe7k9fXEnMlLSImV1tqZlcCe4h5ti5390Yzm5Bs4hfApe7uZvYHwJ8TI4RFioqC\nQuRYI81sJVAHPAv8LFl+bfJYkbweQwTHecAP3b0RwN0zk1NOB76fzPdfBWwelNKLDDA1PYkc64i7\nnw/MIk7wmT4KAz6X9F+c7+6vcfe7k+U9zYXzT8BX3P0c4A+JiehEio6CQqQX7n4A+DDwZ2ZWSUw6\n97/NbAyAmU0zsynAw8A7zGxisjzT9FQLbEuevweRIqWmJ5E83H2Fma0Cbnb37yRTVD+ZzNJ7GHhX\nMlPpZ4FlZtZJNE29l7ir2g/MbBsx5fnsofgOIidKs8eKiEheanoSEZG8FBQiIpKXgkJERPJSUIiI\nSF4KChERyUtBISIieSkoREQkr/8Bu74+Bz3qyGIAAAAASUVORK5CYII=\n",
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from sklearn.metrics import precision_recall_curve, average_precision_score\n",
"import matplotlib.pyplot as plt\n",
"\n",
"precision, recall, _ = precision_recall_curve(val_y, probs)\n",
"average_precision = average_precision_score(val_y, probs)\n",
"\n",
"plt.step(recall, precision, color='b', alpha=0.2, where='post')\n",
"plt.fill_between(recall, precision, step='post', alpha=0.2, color='b')\n",
"\n",
"plt.xlabel('Recall')\n",
"plt.ylabel('Precision')\n",
"plt.ylim([0.0, 1.05])\n",
"plt.xlim([0.0, 1.0])\n",
"plt.title('Precision-Recall curve: AUC={0:0.2f}'.format(average_precision));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.7583187390542907"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"recall[precision>=0.6][0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_val = df.iloc[sorted(val_idx)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"incorrect_yes = np.where((preds != val_y) & (val_y == 0))[0]\n",
"most_incorrect_yes = np.argsort(-probs[incorrect_yes])\n",
"txts = df_val.iloc[incorrect_yes[most_incorrect_yes[:10]]]\n",
"txts[[\"link\", \"title\", \"summary\"]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'arxiv.org/abs/1710.00814 arxiv.org/abs/1612.02559 arxiv.org/abs/1708.00489 arxiv.org/abs/1703.11000 arxiv.org/abs/1612.06704 arxiv.org/abs/1708.00973 arxiv.org/abs/1707.07341 arxiv.org/abs/1707.06728 arxiv.org/abs/1710.02318 arxiv.org/abs/1612.01064'"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"' '.join(txts.link.values)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"incorrect_no = np.where((preds != val_y) & (val_y == 1))[0]\n",
"most_incorrect_no = np.argsort(probs[incorrect_no])\n",
"txts = df_val.iloc[incorrect_no[most_incorrect_no[:10]]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" link | \n",
" title | \n",
" summary | \n",
"
\n",
" \n",
" \n",
" \n",
" 18571 | \n",
" arxiv.org/abs/1707.03243 | \n",
" Malware in the Future? Forecasting Analyst Det... | \n",
" Cyber attacks endanger physical, economic, soc... | \n",
"
\n",
" \n",
" 23392 | \n",
" arxiv.org/abs/1709.00765 | \n",
" Number of hidden states needed to physically i... | \n",
" We consider the problem of implementing a give... | \n",
"
\n",
" \n",
" 18419 | \n",
" arxiv.org/abs/1707.02651 | \n",
" Model-Based Speech Enhancement in the Modulati... | \n",
" This paper presents algorithms for modulation-... | \n",
"
\n",
" \n",
" 10414 | \n",
" arxiv.org/abs/1704.02162 | \n",
" Locally-adapted convolution-based super-resolu... | \n",
" Super-resolution is a classical problem in ima... | \n",
"
\n",
" \n",
" 3976 | \n",
" arxiv.org/abs/1701.07381 | \n",
" Design and Implementation of a Semantic Dialog... | \n",
" This chapter describes a semantic dialogue sys... | \n",
"
\n",
" \n",
" 13229 | \n",
" arxiv.org/abs/1705.04824 | \n",
" Extracting urban impervious surface from GF-1 ... | \n",
" Impervious surface area is a direct consequenc... | \n",
"
\n",
" \n",
" 18308 | \n",
" arxiv.org/abs/1707.02279 | \n",
" A Probabilistic Calculus of Cyber-Physical Sys... | \n",
" We propose a hybrid probabilistic process calc... | \n",
"
\n",
" \n",
" 18368 | \n",
" arxiv.org/abs/1707.02477 | \n",
" Hyperspectral Image Restoration via Total Vari... | \n",
" Hyperspectral images (HSIs) are often corrupte... | \n",
"
\n",
" \n",
" 22275 | \n",
" arxiv.org/abs/1708.06248 | \n",
" GraphR: Accelerating Graph Processing Using ReRAM | \n",
" This paper presents GRAPHR, the first ReRAM-ba... | \n",
"
\n",
" \n",
" 17840 | \n",
" arxiv.org/abs/1707.00506 | \n",
" Recommender System for News Articles using Sup... | \n",
" In the last decade we have observed a mass inc... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" link \\\n",
"18571 arxiv.org/abs/1707.03243 \n",
"23392 arxiv.org/abs/1709.00765 \n",
"18419 arxiv.org/abs/1707.02651 \n",
"10414 arxiv.org/abs/1704.02162 \n",
"3976 arxiv.org/abs/1701.07381 \n",
"13229 arxiv.org/abs/1705.04824 \n",
"18308 arxiv.org/abs/1707.02279 \n",
"18368 arxiv.org/abs/1707.02477 \n",
"22275 arxiv.org/abs/1708.06248 \n",
"17840 arxiv.org/abs/1707.00506 \n",
"\n",
" title \\\n",
"18571 Malware in the Future? Forecasting Analyst Det... \n",
"23392 Number of hidden states needed to physically i... \n",
"18419 Model-Based Speech Enhancement in the Modulati... \n",
"10414 Locally-adapted convolution-based super-resolu... \n",
"3976 Design and Implementation of a Semantic Dialog... \n",
"13229 Extracting urban impervious surface from GF-1 ... \n",
"18308 A Probabilistic Calculus of Cyber-Physical Sys... \n",
"18368 Hyperspectral Image Restoration via Total Vari... \n",
"22275 GraphR: Accelerating Graph Processing Using ReRAM \n",
"17840 Recommender System for News Articles using Sup... \n",
"\n",
" summary \n",
"18571 Cyber attacks endanger physical, economic, soc... \n",
"23392 We consider the problem of implementing a give... \n",
"18419 This paper presents algorithms for modulation-... \n",
"10414 Super-resolution is a classical problem in ima... \n",
"3976 This chapter describes a semantic dialogue sys... \n",
"13229 Impervious surface area is a direct consequenc... \n",
"18308 We propose a hybrid probabilistic process calc... \n",
"18368 Hyperspectral images (HSIs) are often corrupte... \n",
"22275 This paper presents GRAPHR, the first ReRAM-ba... \n",
"17840 In the last decade we have observed a mass inc... "
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"txts[[\"link\", \"title\", \"summary\"]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'arxiv.org/abs/1707.03243 arxiv.org/abs/1709.00765 arxiv.org/abs/1707.02651 arxiv.org/abs/1704.02162 arxiv.org/abs/1701.07381 arxiv.org/abs/1705.04824 arxiv.org/abs/1707.02279 arxiv.org/abs/1707.02477 arxiv.org/abs/1708.06248 arxiv.org/abs/1707.00506'"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"' '.join(txts.link.values)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"to_review = np.where((preds > 0.8) & (val_y == 0))[0]\n",
"to_review_idx = np.argsort(-probs[to_review])\n",
"txts = df_val.iloc[to_review[to_review_idx]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"txt_html = ('' + txts.title.str.replace('\\n',' ') + ': ' \n",
" + txts.summary.str.replace('\\n',' ') + '').values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"full_html = (f\"\"\"\n",
"\n",
"Brundage Bot Backfill\n",
"\n",
"\n",
"{os.linesep.join(txt_html)}\n",
"
\n",
"\n",
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learner"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"veczr = CountVectorizer(ngram_range=(1,3), tokenizer=tokenize, max_features=vocab_size)\n",
"\n",
"trn_term_doc = veczr.fit_transform(trn)\n",
"val_term_doc = veczr.transform(val)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((24470, 200000), 10271515)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trn_term_doc.shape, trn_term_doc.sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"md = TextClassifierData.from_bow(trn_term_doc, trn_y, val_term_doc, val_y, sl)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"learner = md.dotprod_nb_learner(r_adj=20)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e79dafe458294f2885fff57373c1cde4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" \r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jhoward/anaconda3/lib/python3.6/site-packages/sklearn/metrics/ranking.py:420: RuntimeWarning: invalid value encountered in true_divide\n",
" recall = tps / tps[-1]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 0.13796 0.17713 0.84782 0.68941]\n",
"[ 1. 0.11556 0.17372 0.85 0.72286] \n",
"[ 2. 0.09147 0.17366 0.84714 0.72249] \n",
"[ 3. 0.08243 0.17359 0.84646 0.73789] \n",
"\n"
]
}
],
"source": [
"learner.fit(0.02, 4, wds=1e-6, cycle_len=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import precision_recall_curve\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def prec_at_6(preds,targs):\n",
" precision, recall, _ = precision_recall_curve(targs[:,1], preds[:,1])\n",
" return recall[precision>=0.6][0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.71103327495621715"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prec_at_6(*learner.predict_with_targs())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}