<jupyter_start><jupyter_text>Data Mining and Machine Learning <NAME> 1-D, 2-D,3-D Visualization in Python using four modules: ggplot, plotly, seaborn and bokeh (Python 2)<jupyter_code>import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
from ggplot import mtcars
import bokeh
# Otra forma de llamar a plotnine
#from plotnine import *
#Funcion magica para que la grafica de matplotlib salga en la pantalla
%matplotlib inline
#Leyendo los datos
datos1=pd.read_csv("http://academic.uprm.edu/eacuna/clase97.txt",sep=" ")
datos1.head()<jupyter_output><empty_output><jupyter_text>Histogram using ggplot<jupyter_code># Histograma de gpa usando ggplot
p=ggplot(aes(x='gpa'),data=datos1)
p+geom_histogram(binwidth=.35)<jupyter_output><empty_output><jupyter_text>Notar que en lugar de 5 intervalos ggplot muestra 10 intervalos<jupyter_code># Histograma de gpa cpn 8 intervalos usando ggplot
p=ggplot(aes(x = 'mpg'),data=mtcars) 
p=p+geom_histogram(colour = "black" , fill = "red" , bins = 8)
p<jupyter_output><empty_output><jupyter_text>Nuevamente notar de que a pesar que se le pide 8 intervalos, ggplot muestra 8 intervalos. La funcion parece estar con errores aun  Histogram using seaborn<jupyter_code>#Histogram de gpa usando seaborn
sns.distplot(datos1['gpa'],kde=False, color="blue")
#otra vez el histograma en seaborn usando 5 intervalos
sns.distplot(datos1['gpa'],bins=5, kde=False, color="cyan")<jupyter_output><empty_output><jupyter_text>Histogram using Plotly<jupyter_code>#Histograma usando plotly
import plotly 
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)

x = datos1['gpa']
data = [go.Histogram(x=x)]

plotly.offline.iplot(data, filename='histograma en plotly')<jupyter_output><empty_output><jupyter_text>Comentario: Me da la impresion de que la libreria mas estable es seaborn.Lo unico malo es que no hace pie charts<jupyter_code># haciendo un segundo ejemplo con el cojunto de dato mtcars que viene dentro de pandas
mtcars.head()
#Haciendo el histograma cpn seaborn
sns.distplot(mtcars['mpg'],kde=False)
#Haciendo el histograma con ggplopt
p = ggplot(aes(x='mpg'), data=mtcars)
p+geom_histogram(fill="green")<jupyter_output><empty_output><jupyter_text>Histogram using Bokeh<jupyter_code>#haciendo el histograma con Bokeh
from bokeh.charts import Histogram
from bokeh.charts import defaults, show
from bokeh.io import output_notebook

# input options
output_notebook()
hist = Histogram(datos1['gpa'], title="Histograma de GPA")

show(hist)<jupyter_output><empty_output><jupyter_text>Scatterplot 3D using matplotlib<jupyter_code># Scatterplot 3D usando matplotlib
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
import random


fig = pyplot.figure()
ax = Axes3D(fig)

sequence_containing_x_vals = list(range(0, 100))
sequence_containing_y_vals = list(range(0, 100))
sequence_containing_z_vals = list(range(0, 100))

random.shuffle(sequence_containing_x_vals)
random.shuffle(sequence_containing_y_vals)
random.shuffle(sequence_containing_z_vals)

ax.scatter(sequence_containing_x_vals, sequence_containing_y_vals, sequence_containing_z_vals)
pyplot.show()<jupyter_output><empty_output><jupyter_text>Scatterplot 3D using plotly<jupyter_code>import plotly as py
import plotly.graph_objs as go

py.offline.init_notebook_mode(connected=True)
import numpy as np

x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
trace1 = go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode='markers',
    marker=dict(
        size=12,
        line=dict(
            color='rgba(217, 217, 217, 0.14)',
            width=0.5
        ),
        opacity=0.8
    )
)

x2, y2, z2 = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
trace2 = go.Scatter3d(
    x=x2,
    y=y2,
    z=z2,
    mode='markers',
    marker=dict(
        color='rgb(127, 127, 127)',
        size=12,
        symbol='circle',
        line=dict(
            color='rgb(204, 204, 204)',
            width=1
        ),
        opacity=0.9
    )
)
data = [trace1, trace2]
layout = go.Layout(
    margin=dict(
        l=0,
        r=0,
        b=0,
        t=0
    )
)
fig = go.Figure(data=data, layout=layout)
py.offline.iplot(fig, filename='simple-3d-scatter')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11108528933302347, 'fraction_numerical': 0.026493144317917734, 'mean_word_length': 5.274052478134111, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '456151', 'license': 'MIT', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1631, 'n_words': 361, 'path': 'Notebooks/visual1e.ipynb', 'repo_name': 'eacunafer/Data-Mining-and-Machine-Learning-with-Python', 'size': '4308'}