<jupyter_start><jupyter_text><jupyter_code>"""
FT043
Preenchimento de matrizes
<NAME>
"""

import numpy as np
import matplotlib.pyplot as plt
from soft_impute_functions import *
from PIL import Image


n, m, k = 100, 100, 10

A = np.random.normal(size=(n,k))
B = np.random.normal(size=(k,n))

X = np.dot(A,B)


plt.imshow(X)
plt.colorbar()
plt.show()

missing_data = 5000
idx = list(np.random.randint(X.shape[0], size=missing_data))
idy = list(np.random.randint(X.shape[1], size=missing_data))

Xfloat =  X.astype(np.float64)
Xmissing = X.astype(np.float64)

for kk in range(missing_data):
    Xmissing[idx[kk],idy[kk]] = np.nan
    

clf = SoftImpute(J=10)
fit = clf.fit(Xmissing)
Xest = clf.predict(Xmissing)


plt.imshow(Xmissing)
plt.colorbar()
plt.show()


plt.imshow(Xest)
plt.colorbar()
plt.show()



plt.imshow(Xest-X)
plt.colorbar()
plt.show()



qwqwq

#X = np.array(Image.open('foto_fca_gray.png').convert('L'))

plt.imshow(X,cmap='gray', vmin=0, vmax=255)
plt.show()

n = 2  # for 2 random indices
#index = np.random.choice(X.shape[0], n, replace=False)

# row_indices = [4,2,18,16,7,19,4]
# col_indices = [1,2]
# x_rows = x[row_indices,:]
# x_indexed = x_rows[:,column_indices]


# X = np.random.random((10,3)) + (np.arange(10).reshape(10,1) ** 2)

# X.shape[0]

missing_data = 700*700
idx = list(np.random.randint(X.shape[0], size=missing_data))
idy = list(np.random.randint(X.shape[1], size=missing_data))

Xfloat =  X.astype(np.float64)
Xmissing = X.astype(np.float64)

for kk in range(missing_data):
    Xmissing[idx[kk],idy[kk]] = np.nan
    

clf = SoftImpute(J=200)
fit = clf.fit(Xmissing)
X_imp = clf.predict(Xmissing)

plt.imshow(Xmissing,cmap='gray')
plt.show()

plt.imshow(X_imp,cmap='gray')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18223234624145787, 'fraction_numerical': 0.038154897494305236, 'mean_word_length': 5.143356643356643, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '310532', 'license': 'MIT', 'n_tokens_mistral': 838, 'n_tokens_neox': 776, 'n_words': 127, 'path': 'Semana14_PO450.ipynb', 'repo_name': 'julianovale/PO450', 'size': '1768'}