<jupyter_start><jupyter_text>DAT210x - Programming with Python for DS  Module4- Lab5<jupyter_code>import pandas as pd

from scipy import misc
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
# Look pretty...

# matplotlib.style.use('ggplot')
plt.style.use('ggplot')<jupyter_output><empty_output><jupyter_text>Create a regular Python list (not NDArray) and name it `samples`:<jupyter_code>samples = []
color = []<jupyter_output><empty_output><jupyter_text>Code up a for-loop that iterates over the images in the `Datasets/ALOI/32/` folder. Look in the folder first, so you know how the files are organized, and what file number they start from and end at.Load each `.png` file individually in your for-loop using the instructions provided in the Feature Representation reading. Once loaded, flatten the image into a single-dimensional NDArray and append it to your `samples` list.**Optional**: You can resample the image down by a factor of two if you have a slower computer. You can also scale the image from `0-255` to `0.0-1.0` if you'd like--doing so shouldn't have any effect on the algorithm's results.<jupyter_code>for i in range(0,355,5):
    img = misc.imread('32_r%s.png' % i)
    samples.append((img[::2,::2]/255.0).reshape(-1))
    color.append('b')<jupyter_output><empty_output><jupyter_text>Convert `samples` to a DataFrame named `df`:<jupyter_code>df = pd.DataFrame(samples)<jupyter_output><empty_output><jupyter_text>Import any necessary libraries to perform Isomap here, reduce `df` down to three components and using `K=6` for your neighborhood size:<jupyter_code>from sklearn import manifold
iso = manifold.Isomap(n_neighbors=2, n_components=3)
iso.fit(df)
isot = iso.transform(df)
dft = pd.DataFrame(isot)<jupyter_output><empty_output><jupyter_text>Create a 2D Scatter plot to graph your manifold. You can use either `'o'` or `'.'` as your marker. Graph the first two isomap components:<jupyter_code>dft.plot.scatter(0, 1, marker='o')<jupyter_output><empty_output><jupyter_text>Chart a 3D Scatter plot to graph your manifold. You can use either `'o'` or `'.'` as your marker:<jupyter_code>fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('principle')
ax.set_ylabel('second')
ax.set_zlabel('third')
ax. scatter(dft.iloc[:,0],dft.iloc[:,1],dft.iloc[:,2], marker='o')<jupyter_output><empty_output><jupyter_text>Answer the first three lab questions! Create another for loop. This time it should iterate over all the images in the `Datasets/ALOI/32_i` directory. Just like last time, load up each image, process them the way you did previously, and append them into your existing `samples` list:<jupyter_code>for i in range(110,220,10):
    img = misc.imread('32_i%s.png' % i)
    samples.append((img[::2,::2]/255.0).reshape(-1))
    color.append('r')<jupyter_output><empty_output><jupyter_text>Convert `samples` to a DataFrame named `df`:<jupyter_code>df2 = pd.DataFrame(samples)<jupyter_output><empty_output><jupyter_text>Import any necessary libraries to perform Isomap here, reduce `df` down to three components and using `K=6` for your neighborhood size:<jupyter_code>iso = manifold.Isomap(n_neighbors=6, n_components=3)
iso.fit(df2)
isot = iso.transform(df2)
dft = pd.DataFrame(isot)<jupyter_output><empty_output><jupyter_text>Create a 2D Scatter plot to graph your manifold. You can use either `'o'` or `'.'` as your marker. Graph the first two isomap components:<jupyter_code>dft.plot.scatter(0,1,c=color,marker='o')<jupyter_output><empty_output><jupyter_text>Chart a 3D Scatter plot to graph your manifold. You can use either `'o'` or `'.'` as your marker:<jupyter_code>fig = plt.figure()
ax = fig.add_subplot('111',projection='3d')
ax.set_xlabel('primary')
ax.set_ylabel('secondary')
ax.set_zlabel('tirshiary')
ax.scatter(dft.iloc[:,0],dft.iloc[:,1],dft.iloc[:,2], c=color, marker='o')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12684666327050434, 'fraction_numerical': 0.020631686194600103, 'mean_word_length': 6.4375, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '12685', 'license': 'MIT', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1375, 'n_words': 383, 'path': 'Module4/.ipynb_checkpoints/Module4 - Lab5-checkpoint.ipynb', 'repo_name': '3point14thon/DAT210x-master', 'size': '3926'}