Skip to content

Commit 8da7ec2

Browse files
authored
Merge pull request #14 from johnnync13/master
Hasta T7-1 TESTEADO en 3.8
2 parents b9d9f95 + fb0f87d commit 8da7ec2

File tree

86 files changed

+72324
-33850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+72324
-33850
lines changed

notebooks/T1 - 1 - Data Cleaning - Carga de datos-Colab.ipynb

Lines changed: 1596 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/T1 - 2 - Data Cleaning - Análisis Preliminar de los Datos-Colab.ipynb

Lines changed: 2623 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/T1 - 3 - Data Cleaning - Plots-Colab.ipynb

Lines changed: 874 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/T10 - 1 - Analisis de Componentes Principales-Colab.ipynb

Lines changed: 745 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/T10 - 1 - Analisis de Componentes Principales.ipynb

Lines changed: 90 additions & 463 deletions
Large diffs are not rendered by default.
Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a href=\"https://colab.research.google.com/github/joanby/python-ml-course/blob/master/notebooks/T10%20-%202%20-%20Analisis%20de%20Componentes%20Principales%20SK%20Learn-Colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# Análisis de Componentes Principales - SkLearn\n"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 6,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"import pandas as pd\n",
24+
"\n",
25+
"import plotly.plotly as py\n",
26+
"from plotly.graph_objs import * \n",
27+
"import plotly.tools as tls\n",
28+
"\n",
29+
"from sklearn.preprocessing import StandardScaler\n",
30+
"\n",
31+
"tls.set_credentials_file(username='JuanGabriel', api_key='6mEfSXf8XNyIzpxwb8z7')"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 7,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"df = pd.read_csv(\"../datasets/iris/iris.csv\")"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 8,
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"X = df.iloc[:,0:4].values\n",
50+
"y = df.iloc[:,4].values\n",
51+
"X_std = StandardScaler().fit_transform(X)"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 9,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"from sklearn.decomposition import PCA as sk_pca"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 11,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"acp = sk_pca(n_components=2)\n",
70+
"Y = acp.fit_transform(X_std)"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 12,
76+
"metadata": {},
77+
"outputs": [
78+
{
79+
"data": {
80+
"text/plain": [
81+
"array([[-2.26470281, 0.4800266 ],\n",
82+
" [-2.08096115, -0.67413356],\n",
83+
" [-2.36422905, -0.34190802],\n",
84+
" [-2.29938422, -0.59739451],\n",
85+
" [-2.38984217, 0.64683538],\n",
86+
" [-2.07563095, 1.48917752],\n",
87+
" [-2.44402884, 0.0476442 ],\n",
88+
" [-2.23284716, 0.22314807],\n",
89+
" [-2.33464048, -1.11532768],\n",
90+
" [-2.18432817, -0.46901356],\n",
91+
" [-2.1663101 , 1.04369065],\n",
92+
" [-2.32613087, 0.13307834],\n",
93+
" [-2.2184509 , -0.72867617],\n",
94+
" [-2.6331007 , -0.96150673],\n",
95+
" [-2.1987406 , 1.86005711],\n",
96+
" [-2.26221453, 2.68628449],\n",
97+
" [-2.2075877 , 1.48360936],\n",
98+
" [-2.19034951, 0.48883832],\n",
99+
" [-1.898572 , 1.40501879],\n",
100+
" [-2.34336905, 1.12784938],\n",
101+
" [-1.914323 , 0.40885571],\n",
102+
" [-2.20701284, 0.92412143],\n",
103+
" [-2.7743447 , 0.45834367],\n",
104+
" [-1.81866953, 0.08555853],\n",
105+
" [-2.22716331, 0.13725446],\n",
106+
" [-1.95184633, -0.62561859],\n",
107+
" [-2.05115137, 0.24216355],\n",
108+
" [-2.16857717, 0.52714953],\n",
109+
" [-2.13956345, 0.31321781],\n",
110+
" [-2.26526149, -0.3377319 ],\n",
111+
" [-2.14012214, -0.50454069],\n",
112+
" [-1.83159477, 0.42369507],\n",
113+
" [-2.61494794, 1.79357586],\n",
114+
" [-2.44617739, 2.15072788],\n",
115+
" [-2.10997488, -0.46020184],\n",
116+
" [-2.2078089 , -0.2061074 ],\n",
117+
" [-2.04514621, 0.66155811],\n",
118+
" [-2.52733191, 0.59229277],\n",
119+
" [-2.42963258, -0.90418004],\n",
120+
" [-2.16971071, 0.26887896],\n",
121+
" [-2.28647514, 0.44171539],\n",
122+
" [-1.85812246, -2.33741516],\n",
123+
" [-2.5536384 , -0.47910069],\n",
124+
" [-1.96444768, 0.47232667],\n",
125+
" [-2.13705901, 1.14222926],\n",
126+
" [-2.0697443 , -0.71105273],\n",
127+
" [-2.38473317, 1.1204297 ],\n",
128+
" [-2.39437631, -0.38624687],\n",
129+
" [-2.22944655, 0.99795976],\n",
130+
" [-2.20383344, 0.00921636],\n",
131+
" [ 1.10178118, 0.86297242],\n",
132+
" [ 0.73133743, 0.59461473],\n",
133+
" [ 1.24097932, 0.61629765],\n",
134+
" [ 0.40748306, -1.75440399],\n",
135+
" [ 1.0754747 , -0.20842105],\n",
136+
" [ 0.38868734, -0.59328364],\n",
137+
" [ 0.74652974, 0.77301931],\n",
138+
" [-0.48732274, -1.85242909],\n",
139+
" [ 0.92790164, 0.03222608],\n",
140+
" [ 0.01142619, -1.03401828],\n",
141+
" [-0.11019628, -2.65407282],\n",
142+
" [ 0.44069345, -0.06329519],\n",
143+
" [ 0.56210831, -1.76472438],\n",
144+
" [ 0.71956189, -0.18622461],\n",
145+
" [-0.0333547 , -0.43900321],\n",
146+
" [ 0.87540719, 0.50906396],\n",
147+
" [ 0.35025167, -0.19631173],\n",
148+
" [ 0.15881005, -0.79209574],\n",
149+
" [ 1.22509363, -1.6222438 ],\n",
150+
" [ 0.1649179 , -1.30260923],\n",
151+
" [ 0.73768265, 0.39657156],\n",
152+
" [ 0.47628719, -0.41732028],\n",
153+
" [ 1.2341781 , -0.93332573],\n",
154+
" [ 0.6328582 , -0.41638772],\n",
155+
" [ 0.70266118, -0.06341182],\n",
156+
" [ 0.87427365, 0.25079339],\n",
157+
" [ 1.25650912, -0.07725602],\n",
158+
" [ 1.35840512, 0.33131168],\n",
159+
" [ 0.66480037, -0.22592785],\n",
160+
" [-0.04025861, -1.05871855],\n",
161+
" [ 0.13079518, -1.56227183],\n",
162+
" [ 0.02345269, -1.57247559],\n",
163+
" [ 0.24153827, -0.77725638],\n",
164+
" [ 1.06109461, -0.63384324],\n",
165+
" [ 0.22397877, -0.28777351],\n",
166+
" [ 0.42913912, 0.84558224],\n",
167+
" [ 1.04872805, 0.5220518 ],\n",
168+
" [ 1.04453138, -1.38298872],\n",
169+
" [ 0.06958832, -0.21950333],\n",
170+
" [ 0.28347724, -1.32932464],\n",
171+
" [ 0.27907778, -1.12002852],\n",
172+
" [ 0.62456979, 0.02492303],\n",
173+
" [ 0.33653037, -0.98840402],\n",
174+
" [-0.36218338, -2.01923787],\n",
175+
" [ 0.28858624, -0.85573032],\n",
176+
" [ 0.09136066, -0.18119213],\n",
177+
" [ 0.22771687, -0.38492008],\n",
178+
" [ 0.57638829, -0.1548736 ],\n",
179+
" [-0.44766702, -1.54379203],\n",
180+
" [ 0.25673059, -0.5988518 ],\n",
181+
" [ 1.84456887, 0.87042131],\n",
182+
" [ 1.15788161, -0.69886986],\n",
183+
" [ 2.20526679, 0.56201048],\n",
184+
" [ 1.44015066, -0.04698759],\n",
185+
" [ 1.86781222, 0.29504482],\n",
186+
" [ 2.75187334, 0.8004092 ],\n",
187+
" [ 0.36701769, -1.56150289],\n",
188+
" [ 2.30243944, 0.42006558],\n",
189+
" [ 2.00668647, -0.71143865],\n",
190+
" [ 2.25977735, 1.92101038],\n",
191+
" [ 1.36417549, 0.69275645],\n",
192+
" [ 1.60267867, -0.42170045],\n",
193+
" [ 1.8839007 , 0.41924965],\n",
194+
" [ 1.2601151 , -1.16226042],\n",
195+
" [ 1.4676452 , -0.44227159],\n",
196+
" [ 1.59007732, 0.67624481],\n",
197+
" [ 1.47143146, 0.25562182],\n",
198+
" [ 2.42632899, 2.55666125],\n",
199+
" [ 3.31069558, 0.01778095],\n",
200+
" [ 1.26376667, -1.70674538],\n",
201+
" [ 2.0377163 , 0.91046741],\n",
202+
" [ 0.97798073, -0.57176432],\n",
203+
" [ 2.89765149, 0.41364106],\n",
204+
" [ 1.33323218, -0.48181122],\n",
205+
" [ 1.7007339 , 1.01392187],\n",
206+
" [ 1.95432671, 1.0077776 ],\n",
207+
" [ 1.17510363, -0.31639447],\n",
208+
" [ 1.02095055, 0.06434603],\n",
209+
" [ 1.78834992, -0.18736121],\n",
210+
" [ 1.86364755, 0.56229073],\n",
211+
" [ 2.43595373, 0.25928443],\n",
212+
" [ 2.30492772, 2.62632347],\n",
213+
" [ 1.86270322, -0.17854949],\n",
214+
" [ 1.11414774, -0.29292262],\n",
215+
" [ 1.2024733 , -0.81131527],\n",
216+
" [ 2.79877045, 0.85680333],\n",
217+
" [ 1.57625591, 1.06858111],\n",
218+
" [ 1.3462921 , 0.42243061],\n",
219+
" [ 0.92482492, 0.0172231 ],\n",
220+
" [ 1.85204505, 0.67612817],\n",
221+
" [ 2.01481043, 0.61388564],\n",
222+
" [ 1.90178409, 0.68957549],\n",
223+
" [ 1.15788161, -0.69886986],\n",
224+
" [ 2.04055823, 0.8675206 ],\n",
225+
" [ 1.9981471 , 1.04916875],\n",
226+
" [ 1.87050329, 0.38696608],\n",
227+
" [ 1.56458048, -0.89668681],\n",
228+
" [ 1.5211705 , 0.26906914],\n",
229+
" [ 1.37278779, 1.01125442],\n",
230+
" [ 0.96065603, -0.02433167]])"
231+
]
232+
},
233+
"execution_count": 12,
234+
"metadata": {},
235+
"output_type": "execute_result"
236+
}
237+
],
238+
"source": [
239+
"Y"
240+
]
241+
},
242+
{
243+
"cell_type": "code",
244+
"execution_count": 15,
245+
"metadata": {},
246+
"outputs": [
247+
{
248+
"data": {
249+
"text/html": [
250+
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~JuanGabriel/48.embed\" height=\"525px\" width=\"100%\"></iframe>"
251+
],
252+
"text/plain": [
253+
"<plotly.tools.PlotlyDisplay object>"
254+
]
255+
},
256+
"execution_count": 15,
257+
"metadata": {},
258+
"output_type": "execute_result"
259+
}
260+
],
261+
"source": [
262+
"results = []\n",
263+
"\n",
264+
"for name in ('setosa', 'versicolor', 'virginica'):\n",
265+
" result = Scatter(x = Y[y==name,0], y = Y[y==name, 1],\n",
266+
" mode = \"markers\", name = name,\n",
267+
" marker = Marker(size=8, line=Line(color=\"rgba(225,225,225,0.2)\", width=0.5),\n",
268+
" opacity = 0.75))\n",
269+
" results.append(result)\n",
270+
" \n",
271+
"data = Data(results)\n",
272+
"layout = Layout(xaxis = XAxis(title=\"CP1\", showline=False),\n",
273+
" yaxis = YAxis(title=\"CP2\", showline=False))\n",
274+
"\n",
275+
"fig = Figure(data = data, layout = layout)\n",
276+
"py.iplot(fig)"
277+
]
278+
},
279+
{
280+
"cell_type": "code",
281+
"execution_count": null,
282+
"metadata": {},
283+
"outputs": [],
284+
"source": []
285+
}
286+
],
287+
"metadata": {
288+
"kernelspec": {
289+
"display_name": "Python 3",
290+
"language": "python",
291+
"name": "python3"
292+
},
293+
"language_info": {
294+
"codemirror_mode": {
295+
"name": "ipython",
296+
"version": 3
297+
},
298+
"file_extension": ".py",
299+
"mimetype": "text/x-python",
300+
"name": "python",
301+
"nbconvert_exporter": "python",
302+
"pygments_lexer": "ipython3",
303+
"version": "3.8.5"
304+
}
305+
},
306+
"nbformat": 4,
307+
"nbformat_minor": 2
308+
}

notebooks/T10 - 2 - Analisis de Componentes Principales SK Learn.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293
"name": "python",
294294
"nbconvert_exporter": "python",
295295
"pygments_lexer": "ipython3",
296-
"version": "3.6.4"
296+
"version": "3.8.5"
297297
}
298298
},
299299
"nbformat": 4,

0 commit comments

Comments
 (0)