8000 Modifications in examples/ to avoid unwanted notebook style · scikit-learn/scikit-learn@d9287ff · GitHub
[go: up one dir, main page]

Skip to content

Commit d9287ff

Browse files
committed
Modifications in examples/ to avoid unwanted notebook style
1 parent 58f7bc0 commit d9287ff

File tree

55 files changed

+21
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+21
-162
lines changed

examples/applications/plot_face_recognition.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
4949

5050

51-
###############################################################################
5251
# Download the data, if not already on disk and load it as numpy arrays
5352

5453
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
@@ -72,15 +71,13 @@
7271
print("n_classes: %d" % n_classes)
7372

7473

75-
###############################################################################
7674
# Split into a training set and a test set using a stratified k fold
7775

7876
# split into a training and testing set
7977
X_train, X_test, y_train, y_test = train_test_split(
8078
X, y, test_size=0.25, random_state=42)
8179

8280

83-
###############################################################################
8481
# Compute a PCA (eigenfaces) on the face dataset (treated as unlabeled
8582
# dataset): unsupervised feature extraction / dimensionality reduction
8683
n_components = 150
@@ -101,7 +98,6 @@
10198
print("done in %0.3fs" % (time() - t0))
10299

103100

104-
###############################################################################
105101
# Train a SVM classification model
106102

107103
print("Fitting the classifier to the training set")
@@ -115,7 +111,6 @@
115111
print(clf.best_estimator_)
116112

117113

118-
###############################################################################
119114
# Quantitative evaluation of the model quality on the test set
120115

121116
print("Predicting people's names on the test set")
@@ -127,7 +122,6 @@
127122
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))
128123

129124

130-
###############################################################################
131125
# Qualitative evaluation of the predictions using matplotlib
132126

133127
def plot_gallery(images, titles, h, w, n_row=3, n_col=4):

examples/applications/plot_model_complexity_influence.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
from sklearn.linear_model.stochastic_gradient import SGDClassifier
3535
from sklearn.metrics import hamming_loss
3636

37-
###############################################################################
3837
# Routines
3938

4039

41-
# initialize random generator
40+
# Initialize random generator
4241
np.random.seed(0)
4342

4443

@@ -122,8 +121,7 @@ def _count_nonzero_coefficients(estimator):
122121
a = estimator.coef_.toarray()
123122
return np.count_nonzero(a)
124123

125-
###############################################################################
126-
# main code
124+
# Main code
127125
regression_data = generate_data('regression')
128126
classification_data = generate_data('classification', sparse=True)
129127
configurations = [

examples/applications/plot_prediction_latency.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,11 @@ def plot_benchmark_throughput(throughputs, configuration):
266266
plt.show()
267267

268268

269-
###############################################################################
270-
# main code
269+
# Main code
271270

272271
start_time = time.time()
273272

274-
# benchmark bulk/atomic prediction speed for various regressors
273+
# Benchmark bulk/atomic prediction speed for various regressors
275274
configuration = {
276275
'n_train': int(1e3),
277276
'n_test': int(1e2),

examples/applications/plot_stock_market.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
from sklearn import cluster, covariance, manifold
7575

7676

77-
###############################################################################
7877
# Retrieve the data from Internet
7978

8079
def quotes_historical_google(symbol, date1, date2):
@@ -189,7 +188,6 @@ def quotes_historical_google(symbol, date1, date2):
189188
variation = close_prices - open_prices
190189

191190

192-
###############################################################################
193191
# Learn a graphical structure from the correlations
194192
edge_model = covariance.GraphLassoCV()
195193

@@ -199,7 +197,6 @@ def quotes_historical_google(symbol, date1, date2):
199197
X /= X.std(axis=0)
200198
edge_model.fit(X)
201199

202-
###############################################################################
203200
# Cluster using affinity propagation
204201

205202
_, labels = cluster.affinity_propagation(edge_model.covariance_)
@@ -208,7 +205,6 @@ def quotes_historical_google(symbol, date1, date2):
208205
for i in range(n_labels + 1):
209206
print('Cluster %i: %s' % ((i + 1), ', '.join(names[labels == i])))
210207

211-
###############################################################################
212208
# Find a low-dimension embedding for visualization: find the best position of
213209
# the nodes (the stocks) on a 2D plane
214210

@@ -220,7 +216,6 @@ def quotes_historical_google(symbol, date1, date2):
220216

221217
embedding = node_position_model.fit_transform(X.T).T
222218

223-
###############################################################################
224219
# Visualization
225220
plt.figure(1, facecolor='w', figsize=(10, 8))
226221
plt.clf()

examples/applications/wikipedia_principal_eigenvector.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
print(__doc__)
5454

55-
###############################################################################
5655
# Where to download the data, if not already on disk
5756
redirects_url = "http://downloads.dbpedia.org/3.5.1/en/redirects_en.nt.bz2"
5857
redirects_filename = redirects_url.rsplit("/", 1)[1]
@@ -73,7 +72,6 @@
7372
print()
7473

7574

76-
###############################################################################
7775
# Loading the redirect files
7876

7977
memory = Memory(cachedir=".")

examples/calibration/plot_calibration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
clf_sigmoid_score = brier_score_loss(y_test, prob_pos_sigmoid, sw_test)
8484
print("With sigmoid calibration: %1.3f" % clf_sigmoid_score)
8585

86-
###############################################################################
8786
# Plot the data and the predicted probabilities
8887
plt.figure()
8988
y_unique = np.unique(y)

examples/calibration/plot_compare_calibration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
rfc = RandomForestClassifier(n_estimators=100)
8282

8383

84-
###############################################################################
8584
# Plot calibration plots
8685

8786
plt.figure(figsize=(10, 10))

examples/classification/plot_lda_qda.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class has its own standard deviation with QDA.
2020
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
2121
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
2222

23-
###############################################################################
24-
# colormap
23+
# Colormap
2524
cmap = colors.LinearSegmentedColormap(
2625
'red_blue_classes',
2726
{'red': [(0, 1, 1), (1, 0.7, 0.7)],
@@ -30,8 +29,7 @@ class has its own standard deviation with QDA.
3029
plt.cm.register_cmap(cmap=cmap)
3130

3231

33-
###############################################################################
34-
# generate datasets
32+
# Generate datasets
3533
def dataset_fixed_cov():
3634
'''Generate 2 Gaussians samples with the same covariance matrix'''
3735
n, dim = 300, 2
@@ -54,8 +52,7 @@ def dataset_cov():
5452
return X, y
5553

5654

57-
###############################################################################
58-
# plot functions
55+
# Plot functions
5956
def plot_data(lda, X, y, y_pred, fig_index):
6057
splot = plt.subplot(2, 2, fig_index)
6158
if fig_index == 1:
@@ -132,7 +129,6 @@ def plot_qda_cov(qda, splot):
132129
plot_ellipse(splot, qda.means_[0], qda.covariances_[0], 'red')
133130
plot_ellipse(splot, qda.means_[1], qda.covariances_[1], 'blue')
134131

135-
###############################################################################
136132
for i, (X, y) in enumerate([dataset_fixed_cov(), dataset_cov()]):
137133
# Linear Discriminant Analysis
138134
lda = LinearDiscriminantAnalysis(solver="svd", store_covariance=True)

examples/cluster/plot_affinity_propagation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
from sklearn import metrics
1515
from sklearn.datasets.samples_generator import make_blobs
1616

17-
##############################################################################
1817
# Generate sample data
1918
centers = [[1, 1], [-1, -1], [1, -1]]
2019
X, labels_true = make_blobs(n_samples=300, centers=centers, cluster_std=0.5,
2120
random_state=0)
2221

23-
##############################################################################
2422
# Compute Affinity Propagation
2523
af = AffinityPropagation(preference=-50).fit(X)
2624
cluster_centers_indices = af.cluster_centers_indices_
@@ -39,7 +37,6 @@
3937
print("Silhouette Coefficient: %0.3f"
4038
% metrics.silhouette_score(X, labels, metric='sqeuclidean'))
4139

42-
##############################################################################
4340
# Plot result
4441
import matplotlib.pyplot as plt
4542
from itertools import cycle

examples/cluster/plot_dbscan.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
from sklearn.preprocessing import StandardScaler
1818

1919

20-
##############################################################################
2120
# Generate sample data
2221
centers = [[1, 1], [-1, -1], [1, -1]]
2322
X, labels_true = make_blobs(n_samples=750, centers=centers, cluster_std=0.4,
2423
random_state=0)
2524

2625
X = StandardScaler().fit_transform(X)
2726

28-
##############################################################################
2927
# Compute DBSCAN
3028
db = DBSCAN(eps=0.3, min_samples=10).fit(X)
3129
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
@@ -46,7 +44,6 @@
4644
print("Silhouette Coefficient: %0.3f"
4745
% metrics.silhouette_score(X, labels))
4846

49-
##############################################################################
5047
# Plot result
5148
import matplotlib.pyplot as plt
5249

0 commit comments

Comments
 (0)
0