K Means
K Means
K Means
EJECUCION DE CODIGO
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] ::
Anaconda, Inc. on win32
>>> dataframe.head()
>>> dataframe.describe()
op co ex ag ne wordcount categoria
>>> print(dataframe.groupby('categoria').size())
categoria
1 27
2 34
3 9
4 19
5 4
6 8
7 17
8 16
9 6
dtype: int64
>>> plt.style.use('ggplot')
>>> dataframe.head()
>>> dataframe.describe()
op co ex ag ne wordcount categoria
>>> print(dataframe.groupby('categoria').size())
categoria
1 27
2 34
3 9
4 19
5 4
6 8
7 17
8 16
9 6
dtype: int64
>>> dataframe.drop(['categoria'],1).hist()
array([[<matplotlib.axes._subplots.AxesSubplot object at
0x000001D7675F6288>,
<matplotlib.axes._subplots.AxesSubplot object at
0x000001D7695E40C8>],
[<matplotlib.axes._subplots.AxesSubplot object at
0x000001D769619FC8>,
<matplotlib.axes._subplots.AxesSubplot object at
0x000001D769658148>],
[<matplotlib.axes._subplots.AxesSubplot object at
0x000001D769690248>,
<matplotlib.axes._subplots.AxesSubplot object at
0x000001D7696C7348>]],
dtype=object)
>>> plt.show()
>>>
sb.pairplot(dataframe.dropna(),hue='categoria',size=4,vars=["op","ex","ag"],
kind='scatter')
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\axisgrid.py:2079:
UserWarning: The `size` parameter has been renamed to `height`; please
update your code.
warnings.warn(msg, UserWarning)
>>> plt.show()
>>> X = np.array(dataframe[["op","ex","ag"]])
>>> y = np.array(dataframe['categoria'])
>>> X.shape
(140, 3)
>>> ax = Axes3D(fig)
>>>
colores=['blue','red','green','blue','cyan','yellow','orange','black','pink','brown'
,'purple']
>>> asignar=[]
>>> fig.show()
>>> kmeans
[KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,
>>> score
>>> plt.plot(Nc,score)
>>> plt.ylabel('Score')
Text(0.5, 0, 'Score')
>>> plt.show()
>>> print(centroids)
>>> C = kmeans.cluster_centers_
>>> colores=['red','green','blue','cyan','yellow']
>>> asignar=[]
fig = plt.figure()
>>> ax = Axes3D(fig)
<mpl_toolkits.mplot3d.art3d.Path3DCollection object at
0x000001D768228748>
>>> ax.scatter(C[:, 0], C[:, 1], C[:, 2], marker='*', c=colores, s=1000)
<mpl_toolkits.mplot3d.art3d.Path3DCollection object at
0x000001D76835EE08>
>>> fig.show()
>>> f1 = dataframe['op'].values
>>> f2 = dataframe['ex'].values
>>> plt.show()
>>> copy['usuario']=dataframe['usuario'].values
>>> copy['categoria']=dataframe['categoria'].values
>>> cantidadGrupo['color']=colores
>>> cantidadGrupo['cantidad']=copy.groupby('label').size()
>>> cantidadGrupo
color cantidad
0 red 34
1 green 19
2 blue 31
3 cyan 41
4 yellow 15
>>> copy['usuario']=dataframe['usuario'].values
>>> copy['categoria']=dataframe['categoria'].values
>>> cantidadGrupo['color']=colores
>>> cantidadGrupo['cantidad']=copy.groupby('label').size()
>>> cantidadGrupo
color cantidad
0 red 34
1 green 19
2 blue 31
3 cyan 41
4 yellow 15
>>> diversidadGrupo['categoria']=[0,1,2,3,4,5,6,7,8,9]
>>> diversidadGrupo['cantidad']=group_referrals.groupby('categoria').size()
>>> diversidadGrupo
categoria cantidad
0 0 NaN
1 1 3.0
2 2 4.0
3 3 NaN
4 4 12.0
5 5 3.0
6 6 1.0
7 7 5.0
8 8 3.0
9 9 3.0
>>> Closest
>>> users=dataframe['usuario'].values