<jupyter_start><jupyter_text>Exercise 1 - Alps Water Dataset<jupyter_code>data = np.array([
        [194.5, 194.3, 197.9, 198.4, 199.4, 199.9, 200.9, 201.1, 201.4, 201.3, 203.6, 204.6, 209.5, 208.6, 210.7, 211.9, 212.2],
        [20.79, 20.79, 22.40, 22.67, 23.15, 23.35, 23.89, 23.99, 24.02, 24.01, 25.14, 26.57, 28.49, 27.76, 29.04, 29.88, 30.06]
])
X = [
[194.5],
[194.3],
[197.9],
[198.4],
[199.4],
[199.9],
[200.9],
[201.1],
[201.4],
[201.3],
[203.6],
[204.6],
[209.5],
[208.6],
[210.7],
[211.9],
[212.2]
]

Y = [
[20.79],
[20.79],
[22.40],
[22.67],
[23.15],
[23.35],
[23.89],
[23.99],
[24.02],
[24.01],
[25.14],
[26.57],
[28.49],
[27.76],
[29.04],
[29.88],
[30.06]
]
pca = PCA()
pca.fit(data=data, pcaType=PcaType.Two)
data_pca = pca.transform(data=data, n_components=2)
lms = LMS()

lms.fit(x=X, y=Y, type=LmsType.Linear)
y_predict_linear = lms.predict(x=X)
data_plot_x = data[0] - np.average(data[0])
data_plot_y = data[1] - np.average(data[1])
data_pca_plot_x = data_pca[0] - np.average(data_pca[0])
data_pca_plot_y = data_pca[1] - np.average(data_pca[1])
np_x = np.array([(X[i][0]) for i in range(0, len(X))])
np_x_plot = np_x - np.average(np_x)
np_y = np.array([(y_predict_linear[i][0]) for i in range(0, len(y_predict_linear))])
np_y_plot = np_y - np.average(np_y)
plt.scatter(data_plot_x, data_plot_y, color="black", label="Data")
plt.plot(data_pca_plot_x, data_pca_plot_y, color="brown", label="PCA - Transform Data")
plt.plot(np_x_plot, np_y_plot, color="blue", label="MMQ - Linear Predict")
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Alps Water Dataset')
plt.legend()
plt.grid()<jupyter_output><empty_output><jupyter_text>Exercise 2 - Books x Grades Dataset<jupyter_code>data = np.array([
        [0, 1, 0, 2, 4, 4, 1, 4, 3, 0, 2, 1, 4, 1, 0, 1, 3, 0, 1, 4, 4, 0, 2, 3, 1, 0, 3, 3, 2, 2, 3, 2, 2, 3, 4, 4, 3, 1, 2, 0],
        [9, 15, 10, 16, 10, 20, 11, 20, 15, 15, 8, 13, 18, 10, 8, 10, 16, 11, 19, 12, 11, 19, 15, 15, 20, 6, 15, 19, 14, 13, 17, 20, 11, 20, 20, 20, 9, 8, 16, 10],
        [45, 57, 45, 51, 65, 88, 44, 87, 89, 59, 66, 65, 56, 47, 66, 41, 56, 37, 45, 58, 47, 64, 97, 55, 51, 61, 69, 79, 71, 62, 87, 54, 43, 92, 83, 94, 60, 56, 88, 62]
])
pca = PCA()
pca.fit(data=data, pcaType=PcaType.Three)
data_pca = pca.transform(data=data, n_components=2)
data_plot_x = data[0] - np.average(data[0])
data_plot_y = data[1] - np.average(data[1])
data_pca_plot_x = data_pca[0] - np.average(data_pca[0])
data_pca_plot_y = data_pca[1] - np.average(data_pca[1])
plt.scatter(data_plot_x, data_plot_y, color="black", label="Data")
plt.plot(data_pca_plot_x, data_pca_plot_y, color="brown", label="PCA Transform Data")
plt.xlabel('X')
plt.ylabel('Y')
plt.title('PCA')
plt.legend()
plt.grid()<jupyter_output><empty_output><jupyter_text>Exercise 3 - US Census Dataset<jupyter_code>data = np.array([
    [1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000],
    [75.99500, 91.97200, 105.7110, 123.2030, 131.6690, 150.6970, 179.3230, 203.2120, 226.5050, 249.6330, 281.4220]
])
X = [
    [1900],
    [1910],
    [1920],
    [1930],
    [1940],
    [1950],
    [1960],
    [1970],
    [1980],
    [1990],
    [2000],
]

Y = [
    [75.9950],
    [91.9720],
    [105.7110],
    [123.2030],
    [131.6690],
    [150.6970],
    [179.3230],
    [203.2120],
    [226.5050],
    [249.6330],
    [281.4220],
]
pca = PCA()
pca.fit(data=data, pcaType=PcaType.Three)
data_pca = pca.transform(data=data, n_components=2)
lms = LMS()

lms.fit(x=X, y=Y, type=LmsType.Linear)
y_predict_linear = lms.predict(x=X)
data_plot_x = data[0] - np.average(data[0])
data_plot_y = data[1] - np.average(data[1])
data_pca_plot_x = data_pca[0] - np.average(data_pca[0])
data_pca_plot_y = data_pca[1] - np.average(data_pca[1])
np_x = np.array([(X[i][0]) for i in range(0, len(X))])
np_x_plot = np_x - np.average(np_x)
np_y = np.array([(y_predict_linear[i][0]) for i in range(0, len(y_predict_linear))])
np_y_plot = np_y - np.average(np_y)
plt.scatter(data_plot_x, data_plot_y, color="black", label="Data")
plt.plot(data_pca_plot_x, data_pca_plot_y, color="brown", label="PCA - Transform Data")
plt.plot(np_x_plot, np_y_plot, color="blue", label="MMQ - Linear Predict")
plt.xlim(-50, 50)
plt.ylim(-100, 100)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('US Census Dataset')
plt.legend()
plt.grid()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2222222222222222, 'fraction_numerical': 0.17529330572808835, 'mean_word_length': 4.263922518159807, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '385589', 'license': 'MIT', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2106, 'n_words': 433, 'path': 'PCA.ipynb', 'repo_name': 'FelipeCapati/pca-principal-component-analysis', 'size': '4347'}