Exemplo n.º 1
0
 def select_widget(Select_numeric_variable):
     """
     This program must take in a variable passed from the widget and turn it into a chart.
     The input is known as num_var and it is the variable you must use to get the data and build a chart.
     The output must return a HoloViews Chart.
     """
     color = next(colors)
     overlay = hv.NdOverlay({group: hv.Distribution(np.histogram(dft[dft[dep]==group][Select_numeric_variable].values)) for i,group in enumerate(target_vars)})
     hv_look = overlay.opts(opts.Distribution(alpha=0.5, height=height_size, width=width_size)).opts(
         title='KDE (Distribution) Plots of all Numeric Variables by Classes').opts(
         xlabel='%s' %dep).opts(ylabel='%s' %Select_numeric_variable)
     return hv_look
Exemplo n.º 2
0
# %%
import cProfile
import line_profiler

import holoviews as hv
import numpy as np
from holoviews import opts

from guess import RcaHmm

hv.extension("bokeh", "matplotlib")
opts.defaults(opts.Distribution(width=650))

series = np.genfromtxt("data/1995/RCAmatrix1995.txt")

model = RcaHmm(series, 4)
hv.Distribution(np.log(series[series.nonzero()]))

# %%
model.baum_welch(series, 6)
hv.Curve(model.lk, "iterations", "likelihood")

# %%
gen_states = np.genfromtxt("gen_param/states.txt")

right_states = 100 * np.count_nonzero(
    gen_states == model.viterbi(series)) / series.size
right_viterbi = 100 * np.count_nonzero(
    gen_states == model.states(series)) / series.size
print(f"Right states with Viterbi:      {right_states:.2f}%\n"
      f"Right states with gamma argmax: {right_viterbi:.2f}%")
Exemplo n.º 3
0
# %%
import holoviews as hv
import numpy as np
from holoviews import opts
from scipy.stats import norm

from guess import RcaHmm, import_rca_data, save_country_model

hv.extension("bokeh", "matplotlib")
opts.defaults(opts.Distribution(width=650), opts.Curve(width=650))

a, countries = import_rca_data("./mcps export fixed size/")

# %%
country = "Canada"
country_series = a[countries[country], ...]
n_nonzero = 1 - np.count_nonzero(country_series) / np.prod(
    country_series.shape)
print(f"Null values: {100 * n_nonzero:.2f}%")

country_model = RcaHmm(country_series, 4)
country_model.baum_welch(country_series, eps=8)

print(
    "Matrix:",
    country_model.matrix,
    "Means and std devs:",
    country_model.distr_params,
    "Zero distribution:",
    country_model.zero_distr,
    "Starting distribution:",
Exemplo n.º 4
0
def plot_perforacion():

    elementos_perforacion=serie_resumen[['dias_perforacion','Qi_hist','estado_actual']]

    tabla_perforacion = hv.Table(elementos_perforacion,'pozo')
    tabla_perforacion.opts(height=500,width=400,fontscale=20)

    dist = hv.Distribution(serie_resumen.dias_perforacion,
                           label='Dias de perforacion - Función de Probabilidad')




    hist=serie_resumen.dias_perforacion.dropna()
    hist=np.histogram(hist)

    plot_hist = hv.Histogram(hist)


    #kde = univariate_kde(dist,
     #                    bin_range=(0, serie_resumen.dias_perforacion.max()),
      #                   bw_method='scott',
       #                  n_samples=1000)
    #kde

    scatter = hv.Scatter(serie_resumen,
                         kdims=['dias_perforacion','profundidad_total'],
                         label='Dias de perforacion vs Profundidad total')

    #dist = dists.redim.label(dias_perforacion='Dias de perforacion')
    scatter  = scatter.redim.label(dias_perforacion='Dias de perforacion', profundidad_total='Profundidad total')

    tiempos = tabla_perforacion + dist + scatter

    tiempos.opts(
        opts.Distribution(height=500, width=700, xaxis=True,
                          xlabel='Dias de Perforacion',
                          xlim=(0,serie_resumen.dias_perforacion.max()),
                          line_width=1.00,
                          color='grey',
                          alpha=0.5,
                          fontscale=1.5,
                          tools=['hover']),
        opts.Scatter(height=500,
                     width=700,
                     xaxis=True,
                     yaxis=True,
                     size=dim('Qi_hist')*50,
                     line_width=0.25,
                     color='estado_actual',
                     cmap='Set1',
                     fontscale=1.5,
                     legend_position='bottom_right'))
                     #fill_color=factor_cmap('estado_actual', palette=Spectral6, factors=elementos_tipos['tipo']))

    tiempos

    hv.output(tiempos, backend='bokeh', fig='html')

    hv.save(tiempos, 'curvas_tipo.html')

    #hv.save(tiempos, 'tiempos.html')

    return
Exemplo n.º 5
0
                     label='Dias de perforacion vs Profundidad total')

#dist = dists.redim.label(dias_perforacion='Dias de perforacion')
scatter = scatter.redim.label(dias_perforacion='Dias de perforacion',
                              profundidad_total='Profundidad total')

tiempos = dist + scatter

tiempos

tiempos.opts(
    opts.Distribution(height=400,
                      width=800,
                      xaxis=True,
                      xlabel='Dias de Perforacion',
                      xlim=(0, serie_resumen.dias_perforacion.max()),
                      line_width=1.00,
                      color='grey',
                      alpha=0.5,
                      tools=['hover']),
    opts.Scatter(height=400,
                 width=800,
                 xaxis=True,
                 yaxis=True,
                 size=10,
                 line_width=0.25,
                 color='orange')).cols(1)

hv.save(tiempos, 'output_tiempos.html', backend='bokeh')

###### HV Plot