Skip to content

Commit 2905bdf

Browse files
committed
ENH More verbose output. Better code
1 parent 4899138 commit 2905bdf

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

ch10/simple_classification.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ def features_for(im):
3535
sobels = []
3636
labels = []
3737

38+
print('Computing features...')
3839
# Use glob to get all the images
3940
images = glob('{}/*.jpg'.format(basedir))
4041
for fname in images:
4142
haralicks.append(features_for(fname))
4243
sobels.append(edginess_sobel(mh.imread(fname, as_grey=True)))
43-
labels.append(fname[:-len('00.jpg')])
44+
45+
# Files are named like building00.jpg, scene23.jpg...
46+
labels.append(fname[:-len('xx.jpg')])
47+
48+
print('Finished computing features.')
4449

4550
haralicks = np.array(haralicks)
4651
sobels = np.array(sobels)
@@ -58,3 +63,12 @@ def features_for(im):
5863
LogisticRegression(), haralick_plus_sobel, labels, cv=5).mean()
5964
print('Accuracy (5 fold x-val) with Logistic Regrssion [std features + sobel]: {}%'.format(
6065
0.1 * round(1000 * scores.mean())))
66+
67+
68+
# We can try to just use the sobel feature. The result is almost completely
69+
# random.
70+
scores = cross_validation.cross_val_score(
71+
LogisticRegression(), np.atleast_2d(sobels).T, labels, cv=5).mean()
72+
print('Accuracy (5 fold x-val) with Logistic Regrssion [only using sobel feature]: {}%'.format(
73+
0.1 * round(1000 * scores.mean())))
74+

0 commit comments

Comments
 (0)