Skip to content

Instantly share code, notes, and snippets.

@0x00b1
Created August 5, 2016 19:38
Show Gist options
  • Select an option

  • Save 0x00b1/9a104b221e3095434174fc6425434f93 to your computer and use it in GitHub Desktop.

Select an option

Save 0x00b1/9a104b221e3095434174fc6425434f93 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext memory_profiler"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sklearn.datasets\n",
"import sklearn.ensemble\n",
"import sklearn.preprocessing"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n_features = 8"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n_samples = 1500000"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 481.08 MiB, increment: 417.99 MiB\n"
]
}
],
"source": [
"%memit X, y = sklearn.datasets.make_classification(n_features=n_features, n_samples=n_samples)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 481.10 MiB, increment: 0.00 MiB\n"
]
}
],
"source": [
"%memit standard_scaler = sklearn.preprocessing.StandardScaler()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 481.17 MiB, increment: 0.07 MiB\n"
]
}
],
"source": [
"%memit X = standard_scaler.fit_transform(X)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 481.18 MiB, increment: 0.00 MiB\n"
]
}
],
"source": [
"%memit classifier = sklearn.ensemble.RandomForestClassifier()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 585.13 MiB, increment: 103.93 MiB\n"
]
}
],
"source": [
"%memit classifier.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 617.26 MiB, increment: 251.26 MiB\n"
]
}
],
"source": [
"%memit predictions = classifier.predict(X)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 536.41 MiB, increment: 0.00 MiB\n"
]
}
],
"source": [
"%memit probabilities = classifier.predict_proba(X)"
]
}
],
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment