```python
import mahotas as mh
import numpy as np
from sklearn.datasets import load_digits
import matplotlib.pyplot as plt
from tpot import TPOT
from sklearn.cross_validation import train_test_split
import dautil as dl
```


```python
context = dl.nb.Context('extracting_texture')
lr = dl.nb.LatexRenderer(chapter=11, start=5, context=context)
lr.render(r' C_{\Delta x, \Delta y}(i,j)=\sum_{p=1}^n\sum_{q=1}^m\begin{cases} 1, &amp; \text{if }I(p,q)=i\text{ and }I(p+\Delta x,q+\Delta y)=j \\ 0, &amp; \text{otherwise}\end{cases}')
lr.render(r'''\begin{align}
 Angular \text{ } 2nd \text{ } Moment &amp;= \sum_{i} \sum_{j} p[i,j]^{2}\\
 Contrast &amp;= \sum_{n=0}^{Ng-1} n^{2} \left \{ \sum_{i=1}^{Ng} \sum_{j=1}^{Ng} p[i,j] \right \} \text{, where } |i-j|=n\\
 Correlation &amp;= \frac{\sum_{i=1}^{Ng} \sum_{j=1}^{Ng}(ij)p[i,j] - \mu_x \mu_y}{\sigma_x \sigma_y} \\
 Entropy &amp;= -\sum_{i}\sum_{j} p[i,j] log(p[i,j])\\
\end{align}''')
```


```python
digits = load_digits()
X = digits.data.copy()

for i, img in enumerate(digits.images):
    np.append(X[i], mh.features.haralick(
        img.astype(np.uint8)).ravel())

X_train, X_test, y_train, y_test = train_test_split(
    X, digits.target, train_size=0.75)
```


```python
tpot = TPOT(generations=6, population_size=101,
            random_state=46, verbosity=2)
tpot.fit(X_train, y_train)
```


```python
%matplotlib inline
context = dl.nb.Context('extracting_texture')
dl.nb.RcWidget(context)
```


```python
print('Score {:.2f}'.format(tpot.score(X_train, y_train, X_test, y_test)))
dl.plotting.img_show(plt.gca(), digits.images[0])
plt.title('Original Image')

plt.figure()
dl.plotting.img_show(plt.gca(), digits.data[0].reshape((8, 8)))
plt.title('Core Features')
plt.figure()
dl.plotting.img_show(plt.gca(), mh.features.haralick(
    digits.images[0].astype(np.uint8)))
plt.title('Haralick Features')
```


```python

```

cbd4648121a23411022c9adebf78d5c3dec92cf0
ipynb
Jupyter Notebook
Module2/Python_Data_Analysis_code/Chapter 11/extracting_texture.ipynb
vijaysharmapc/Python-End-to-end-Data-Analysis
a00f2d5d1547993e000b2551ec6a1360240885ba
MIT
2016-08-24T20:12:01.000Z
2022-03-23T03:59:30.000Z
Module2/Python_Data_Analysis_code/Chapter 11/extracting_texture.ipynb
vijaysharmapc/Python-End-to-end-Data-Analysis
a00f2d5d1547993e000b2551ec6a1360240885ba
MIT
2016-10-18T03:49:11.000Z
2020-11-03T12:41:29.000Z
Module2/Python_Data_Analysis_code/Chapter 11/extracting_texture.ipynb
vijaysharmapc/Python-End-to-end-Data-Analysis
a00f2d5d1547993e000b2551ec6a1360240885ba
MIT
2016-08-19T01:57:35.000Z
2022-02-18T17:02:17.000Z
Qwen/Qwen-72B
1. YES
2. YES