Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Sep 16, 2017
1 parent ecdfbf9 commit 0cb762d
Show file tree
Hide file tree
Showing 21 changed files with 25,995 additions and 4,047 deletions.
15 changes: 11 additions & 4 deletions code/.convert_notebook_to_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import argparse
import os
import subprocess
import textwrap


def convert(input_path, output_path):
Expand All @@ -26,15 +25,23 @@ def cleanup(path):

clean_content = []
imports = []
existing_imports = set()
with open(path, 'r') as f:
next(f)
next(f)
for line in f:
line = line.rstrip(' ')
if line.startswith(skip_lines_startwith):
continue
if line.startswith('import') or (
'from' in line and 'import' in line):
imports.append(line)
if line.startswith('import ') or (
'from ' in line and 'import ' in line):
if 'from __future__ import print_function' in line:
if line != imports[0]:
imports.insert(0, line)
else:
if line.strip() not in existing_imports:
imports.append(line)
existing_imports.add(line.strip())
else:
clean_content.append(line)

Expand Down
2 changes: 1 addition & 1 deletion code/ch02/ch02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand Down
1 change: 0 additions & 1 deletion code/ch02/ch02.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap

# *Python Machine Learning 2nd Edition* by [Sebastian Raschka](https://sebastianraschka.com), Packt Publishing Ltd. 2017
Expand Down
11 changes: 10 additions & 1 deletion code/ch03/ch03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -1758,6 +1758,15 @@
"source": [
"! python ../.convert_notebook_to_script.py --input ch03.ipynb --output ch03.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions code/ch03/ch03.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@
from sklearn.metrics import accuracy_score
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.linear_model import SGDClassifier
import matplotlib.pyplot as plt
import numpy as np
from sklearn.svm import SVC
import matplotlib.pyplot as plt
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from pydotplus import graph_from_dot_data
from sklearn.tree import export_graphviz
Expand Down
Binary file added code/ch03/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion code/ch04/ch04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down
7 changes: 1 addition & 6 deletions code/ch04/ch04.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
from io import StringIO
import sys
from sklearn.preprocessing import Imputer
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt
from sklearn.base import clone
from itertools import combinations
import numpy as np
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
importances = forest.feature_importances_
from sklearn.feature_selection import SelectFromModel

# *Python Machine Learning 2nd Edition* by [Sebastian Raschka](https://sebastianraschka.com), Packt Publishing Ltd. 2017
Expand Down Expand Up @@ -592,6 +586,7 @@ def _calc_score(self, X_train, y_train, X_test, y_test, indices):
random_state=1)

forest.fit(X_train, y_train)
importances = forest.feature_importances_

indices = np.argsort(importances)[::-1]

Expand Down
2 changes: 1 addition & 1 deletion code/ch05/ch05.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook ch05.ipynb to script\n",
"[NbConvertApp] Writing 27719 bytes to ch05.py\n"
"[NbConvertApp] Writing 27705 bytes to ch05.py\n"
]
}
],
Expand Down
13 changes: 0 additions & 13 deletions code/ch05/ch05.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@
from matplotlib.colors import ListedColormap
from sklearn.linear_model import LogisticRegression
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.linear_model import LogisticRegression
from scipy.spatial.distance import pdist, squareform
from scipy import exp
from scipy.linalg import eigh
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_moons
from sklearn.decomposition import PCA
from sklearn.datasets import make_circles
from scipy.spatial.distance import pdist, squareform
from scipy import exp
from scipy.linalg import eigh
import numpy as np
from sklearn.decomposition import KernelPCA

# *Python Machine Learning 2nd Edition* by [Sebastian Raschka](https://sebastianraschka.com), Packt Publishing Ltd. 2017
Expand Down Expand Up @@ -922,8 +914,3 @@ def project_x(x_new, X, gamma, alphas, lambdas):








Loading

0 comments on commit 0cb762d

Please sign in to comment.