Skip to content

Instantly share code, notes, and snippets.

@qpleple
Created June 13, 2015 16:54
Show Gist options
  • Save qpleple/bf14fe7ca9f598df94c3 to your computer and use it in GitHub Desktop.
Save qpleple/bf14fe7ca9f598df94c3 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 65,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from pymongo import MongoClient\n",
"import numpy as np\n",
"from lerni.models.FeaturesMatrixCreator import FeaturesMatrixCreator\n",
"from lerni.service.Config import Config"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1500"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Config.index = 'lerni_dev'\n",
"db = MongoClient().lerni_dev\n",
"\n",
"feature = 'TfIdf_7e1ffa0223223'\n",
"dataset = [doc['_id'] for doc in db.documents.find({}, ['_id'])]\n",
"\n",
"len(dataset)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Old"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1500, 10000)\n",
"CPU times: user 46.9 s, sys: 57.9 s, total: 1min 44s\n",
"Wall time: 1min 49s\n"
]
}
],
"source": [
"%%time\n",
"\n",
"X = FeaturesMatrixCreator()._FeaturesMatrixCreator__vectorize_nested_feature(dataset, feature)\n",
"\n",
"print X.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## New"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1500, 10000)\n",
"CPU times: user 1.64 s, sys: 700 ms, total: 2.34 s\n",
"Wall time: 3.15 s\n"
]
}
],
"source": [
"%%time\n",
"\n",
"docs = db.documents.find({'_id': {'$in': dataset}}, {feature: True}).sort('_id')\n",
"X = np.array([doc[feature] for doc in docs])\n",
"\n",
"print X.shape"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment