예제 #1
0
    def test_default_step_when_a_value_is_float(self):
        st.number_input("the label", value=10.5)

        c = self.get_delta_from_queue().new_element.number_input
        self.assertEqual("%0.2f" % c.step, "0.01")
예제 #2
0
def write(state):
    st.subheader("Create Model from Best Result or Select Single Model or Ensemble?")
    
    if state.is_set_up:
    
        all_models = retrieve_models_name(type="Regression")

        select_model = None 
        select_model_names = list(all_models.keys())
        select_model_names.remove('ExtremeGradientBoosting')

        best_name = ""
        ensemble_method =""
        select_ensemble_method = ""
        select_model_blend = []
        select_model_stack_first = []
        select_model_stack_seconnd = ""
        
        if state.best is not None:
            train_options = ["From Best", "Single Model", "Ensemble Model"]
            if state.transform_target:
                best_name = state.best.__dict__['regressor'].__class__.__name__
                st.write(best_name)
            else:
                best_name = state.best.__class__.__name__
            # the class name of "Lasso" must be modified manually
            if best_name == "Lasso":
                best_name = "LassoRegression"        
        else:
            train_options = ["Single Model", "Ensemble Model"]
               
        train_option = st.radio("Select a Mode to Train Model", options=train_options)
        
        if train_option == "From Best":        
            select_model = best_name
            state.is_ensemble = False

        if train_option == "Single Model":
            select_model = st.selectbox('Select Another Model to Create', options=select_model_names)
            state.is_ensemble = False

        if train_option == "Ensemble Model":
            state.is_ensemble = True
            ensemble_method = st.selectbox("Select a Method for Ensemble", options=["Ensemble","Blend","Stack"])
            if ensemble_method == "Ensemble":
                select_model = st.selectbox('Select a Base Model for Ensemble', options=select_model_names)
                select_ensemble_method = st.selectbox('Select a Method for Ensemble', options=["Bagging","Boosting"])
            elif ensemble_method == "Blend":
                select_model_blend = st.multiselect('Select One or More Models(s) for Blending', options=select_model_names)
            else:
                select_model_stack_first = st.multiselect('Select One or More Models(s) for First Layer Stacking', options=select_model_names)
                select_model_stack_seconnd = st.selectbox('Select a Base Model for Ensemble', options=select_model_names)
        
        
        st.subheader("Create Model")
        with st.beta_expander("Select Parameters for Creating Model"):
            if not state.is_ensemble:
                fold_text = st.text_input('Control Cross Validation Folds (int or None)', value='None',key=1)
                fold = None if fold_text == 'None' else int(fold_text)
                cross_validation = st.checkbox('Allow Cross Validation or not', value=True)

                button_create = st.button('Training a Single Model')
                try:
                    if button_create:
                        with st.spinner("Training Model..."):
                            state.trained_model = create_model(estimator=all_models[select_model], fold=fold, cross_validation=cross_validation)
                        state.log_history["create_model"] = pull(True).to_dict()
                except:
                    st.error("Please Set Up Dataset first!")     

                st.markdown('<p style="color:#1386fc">Show All the Metrics Results After Tuning.</p>',unsafe_allow_html=True)       
                button_after_create = st.button("Show Model Result")
                try:
                    if button_after_create:
                        with st.spinner("Show All the Results..."):
                            st.table(convert_dict_to_df(state.log_history["create_model"]))
                except:
                    st.error("Please Train a Model first!")

                is_tuning = st.checkbox("Do You want to Tune the Hyperparemters?", value=False)
                if is_tuning:
                    fold_text_tune = st.text_input('Control CV Folds (int or None)', value='None',key=2)
                    fold_tune = None if fold_text_tune == 'None' else int(fold_text_tune)
                    n_iter = st.number_input("Number of iterations in the Grid Search", min_value = 1, value=10)
                    optimize = st.selectbox('Metric Name to be Evaluated for Hyperparameter Tuning', options=['R2','MAE','MSE','RMSE','RMSLE','MAPE'], )
                    search_library = st.selectbox('The Search Library Used for Tuning Hyperparameters.',options=['scikit-learn',
                                                                                                   'optuna'])
                    search_algorithms = []
                    if search_library == 'scikit-learn':
                        search_algorithms = ['random','grid']
                    elif search_library == 'scikit-optimize':
                        search_algorithms = ['bayesian']
                    elif search_library  == 'tune-sklearn':
                        search_algorithms = ['random','grid','bayesian','hyperopt','optuna','bohb']
                    else:
                        search_algorithms = ['random','tpe']
                    search_algorithm = st.selectbox('The Search Algorithm Dependes on Search Library',options=search_algorithms)
                    early_stopping = st.checkbox('Stop Fitting to a Hyperparameter Configuration if it Performs Pooly', value=False)
                    early_stopping_iter = 10
                    if early_stopping:
                        early_stopping_iter = st.number_input("Maximum Number of Epochs to Run", min_value=1, value=10)
                    choose_better = st.checkbox('When Set to True, the Returned Object is Always Betting Performing', value=False)
                    button_tuning = st.button('Tune Hyperparameter')
                    if button_tuning:
                        with st.spinner("Search Hyperparamters..."):
                            created_model = create_model(estimator=all_models[select_model])
                            state.trained_model = tune_model(created_model, fold=fold_tune, n_iter=n_iter,
                                                optimize=optimize, search_library=search_library, search_algorithm=search_algorithm,
                                                early_stopping=early_stopping, early_stopping_max_iters=early_stopping_iter,
                                                choose_better = choose_better)
                            state.log_history["tuned_models"] = pull(True).to_dict()

                    st.markdown('<p style="color:#1386fc">Show All the Metrics Results After Tuning.</p>',unsafe_allow_html=True)       
                    button_tuning = st.button("Show Tuning Model Result")
                    if button_tuning:
                        with st.spinner("Show All the Results..."):
                            st.table(convert_dict_to_df(state.log_history["tuned_models"]))
            
            else:
                fold_ensemble_text = st.text_input('Control Cross Validation Folds (int or None)', value='None',key=3)
                fold_ensemble = None if fold_ensemble_text == 'None' else int(fold_ensemble_text)
                choose_better_ensemble = st.checkbox('When Set to True, the Returned Object is Always Betting Performing', value=False)
                optimize_ensemble = st.selectbox('Metric Name to be Evaluated for Hyperparameter Tuning', options=['R2','MAE','MSE','RMSE','RMSLE','MAPE'], )

                if ensemble_method == "Ensemble":
                    n_estimators = st.number_input("The number of Base Estimators in the Ensemble", min_value=1, value=10)
                    button_ensemble = st.button("Training an Ensemble Model")
                    if button_ensemble:
                        with st.spinner("Training Ensemble Model"):
                            base = create_model(estimator=all_models[select_model])
                            state.trained_model = ensemble_model(base, method=select_ensemble_method, fold=fold_ensemble,
                                                                 n_estimators=n_estimators, choose_better=choose_better_ensemble,
                                                                 optimize=optimize_ensemble)
                        state.log_history["create_model"] = pull(True).to_dict()

                elif ensemble_method == "Blend":
                    bases = []
                    button_ensemble = st.button("Training an Ensemble Model")
                    if button_ensemble:
                        with st.spinner("Training Blending Model"):
                            for model in select_model_blend:
                                base = create_model(estimator=all_models[model])
                                bases.append(base)
                            state.trained_model = blend_models(estimator_list=bases, fold=fold_ensemble,
                                                                 choose_better=choose_better_ensemble,
                                                                 optimize=optimize_ensemble)
                        state.log_history["create_model"] = pull(True).to_dict()

                else:
                    restack = st.checkbox("Restack the Predictions for the Meta Model", value=True)
                    button_ensemble = st.button("Training an Ensemble Model")
                    bases = []
                    if button_ensemble:
                        with st.spinner("Training Stacking Model"):
                            for model in select_model_stack_first:
                                base = create_model(estimator=all_models[model])
                                bases.append(base)
                            if select_model_stack_seconnd in select_model_stack_first:
                                index = select_model_stack_first.index(select_model_stack_seconnd)
                                meta_model = bases[index]
                            else:
                                meta_model = create_model(all_models[select_model_stack_seconnd])
                            state.trained_model = stack_models(estimator_list=bases, meta_model=meta_model,
                                                               fold=fold_ensemble, restack=restack,
                                                                 choose_better=choose_better_ensemble,
                                                                 optimize=optimize_ensemble)
                        state.log_history["create_model"] = pull(True).to_dict()
                
                st.markdown('<p style="color:#1386fc">Show All the Metrics Results After Tuning.</p>',unsafe_allow_html=True)       
                button_after_create = st.button("Show Model Result")
                if button_after_create:
                    with st.spinner("Show All the Results..."):
                        st.table(convert_dict_to_df(state.log_history["create_model"]))
   
            state.X_before_preprocess = get_config('data_before_preprocess')
            state.y_before_preprocess = get_config('target_param')

        return state
            
    else:
        st.error("Please Set Up Dataset first!")           
예제 #3
0
from keras_retinanet.utils.colors import label_color

###########################################################
### uploading the image ###
###########################################################

upload = st.file_uploader(
    'Upload an picture of the item you are trying to match')
if upload is not None:
    image1 = Image.open(upload)
    st.image(image1, caption='Uploaded Image.', width=400)

##### User input of number of similar outfits to find

number = st.number_input('How many similar outfits would you like to see?',
                         value=0,
                         step=1)

###########################################################
### TF model
###########################################################

import keras
from keras import backend as K
import tensorflow as tf


def get_session():
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    return tf.Session(config=config)
예제 #4
0
import streamlit as st
import pandas as pd

from moonlight.valuations import ValuationModel


@st.cache
def load_valuations():
    vm = ValuationModel(date="01-27-2022")
    return pd.read_csv(vm.output_path)


if __name__ == "__main__":
    st.title("Ottoneu Draft Helper")
    value_scalar = st.number_input("Value Scale:",
                                   min_value=0.,
                                   max_value=100.,
                                   value=1.)

    data = load_valuations()
    league_id = st.selectbox(label="Select League:",
                             options=data["league_id"].unique())

    data_league = data.loc[data["league_id"] == league_id]
    teams = data_league["teamname"].unique()
    n_teams = len(teams) - 1
    data_league["Value_Scaled"] = data_league["Value"] * value_scalar
    data_league[
        "Surplus"] = data_league["Value_Scaled"] - data_league["Salary"]
    data_league_nfa = data_league.loc[data_league['teamname'] != "free_agent"]
    data_league_fa = data_league.loc[data_league['teamname'] == "free_agent"]
    st.write(f"Total dollars commited: ${int(data_league['Salary'].sum())}")
예제 #5
0
                                 DropDown1['policy_deductable'].unique())
police_report_available = st.selectbox(
    'Is Police Report available ?',
    DropDown1['police_report_available'].unique())
collision_type = st.selectbox('Type of collision',
                              DropDown2['collision_type'].unique())
incident_severity = st.selectbox('Severity of incident',
                                 DropDown2['incident_severity'].unique())
incident_type = st.selectbox('Type of incident',
                             DropDown2['incident_type'].unique())
authorities_contacted = st.selectbox(
    'Type of authorities contacted',
    DropDown3['authorities_contacted'].unique())
umbrella_limit = st.selectbox('Select umbrella limit',
                              DropDown4['umbrella_limit'].unique())
months_as_customer = st.number_input(
    'Duration stayed with the insurer: Select any number between 0 - 500')
vehicle_claim = st.number_input(
    'Amount requested: Select any value between 0 - 80000')
number_of_vehicles_involved = st.slider("Number of vehicles involved", 1, 4)
bodily_injuries = st.slider("Number of injuries", 0, 2)
witnesses = st.slider("Number of witnesses", 0, 3)

# dealing with input passed by user in the app and converting them back to type understandable by the machine learning algorithm

# insured_hobbies
if insured_hobbies == 'chess':
    hobby = 0
else:
    if insured_hobbies == 'cross-fit':
        hobby = 1
    else:
예제 #6
0
        winner = "Pancake"
        amount = pancake[2] - bunny[2]
    else:
        winner = "Bunny"
        amount = bunny[2] - pancake[2]

    return winner, amount


st.title('🐰Pancakebunny CAKE🍰 Compounder')
st.write("Working out how often you should compound your CAKE. \
Assumes you swap BUNNY back to CAKE to stake.")
st.write(
    "Should you stake on [pancakeswap](https://pancakeswap.finance/pools) or [bunnyswap](https://pancakebunny.finance/pool/CAKE)?"
)
cake_staked = st.number_input(label='Enter CAKE staked in £:', value=1000)
st.write("")

pancakeswap = optimal_interval(cake_staked, cake_pool_apr, fees_to_compound)
bunnyswap = optimal_interval_bunny(cake_staked, cake_pool_apr,
                                   fees_to_compound)

st.write(
    f"🍰 £{cake_price:,.2f}, 🐰 £{bunny_price:,.2f}, 💰BNB £{bnb_price:,.2f}")

st.write("## On Pancakeswap:")
st.write(print_results(pancakeswap)[0])
st.write(print_results(pancakeswap)[1])
st.write("## On Pancakebunny:")
st.write(print_results_bunny(bunnyswap)[0])
st.write(print_results_bunny(bunnyswap)[1])
예제 #7
0
def show():
    """Shows the sidebar components for the template and returns user inputs as dict."""

    inputs = {}

    with st.sidebar:
        st.write("## Policy :joystick:")
        policy = st.selectbox("Which policy do you want to train?",
                              list(POLICIES.keys()))
        inputs["policy"] = policy

        st.write("## Environment :video_game:")
        inputs["env"] = st.selectbox("Which environment do you want to use?",
                                     list(ENVIRONMENTS.keys()))
        env = inputs["env"]

        env_list = ENVIRONMENTS[env].keys()
        if inputs["policy"] in DISCRETE_POLICIES:
            if env == "Classic control":
                env_list = [
                    "CartPole", "Acrobot"
                ]  # only CartPole can be solved by discrete policies
            if env == "Box2D":
                env_list = [
                    "LunarLander"
                ]  # only LunarLander can be solved by discrete policies

        if isinstance(ENVIRONMENTS[env], dict):  # different env tasks
            task = st.selectbox("Which task?", list(env_list))
            inputs["task"] = ENVIRONMENTS[env][task]
        else:  # only one variant
            inputs["task"] = ENVIRONMENTS[env]
        if env == "Atari":
            inputs["frames_stack"] = st.number_input("Frames stacking", 1,
                                                     None, 4)
            st.markdown(
                '<sup> Stacked frames composing an observation, used to represent object directions </sup>',
                unsafe_allow_html=True)
        if env in ["Classic control", "Box2d"]:
            inputs["layer_num"] = st.number_input("Number of layers", 1, None,
                                                  3)
            st.markdown('<sup> Number of layers of dense network </sup>',
                        unsafe_allow_html=True)
        inputs["early_stop"] = st.checkbox("Early stop", False)
        if inputs["early_stop"]:
            inputs["target_reward"] = st.number_input("Target reward", None,
                                                      None, 1000)
            st.markdown("<sup> Stop earlier if agent's reward is at least " +
                        str(inputs["target_reward"]) + "</sup>",
                        unsafe_allow_html=True)

        inputs["prioritized"] = None

        section = [
            "Training duration :hourglass:", "Exploration level :world_map:",
            "Training parameters :bookmark_tabs:",
            "Parallelization :fast_forward:"
        ]
        for i, DICT in enumerate([
                TRAINING_DURATION_DICT, EPS_DICT, TRAINING_PARAMS_DICT,
                PARALLELIZATION_DICT
        ]):
            st.write("## " + section[i])
            for k, v in POLICIES[policy][inputs["env"]].items():
                if k in DICT.keys():
                    if type(v) == float:
                        inputs[k] = st.number_input(DICT[k]["text"],
                                                    0.000,
                                                    None,
                                                    v,
                                                    format="%f")
                    if type(v) == int:
                        inputs[k] = st.number_input(DICT[k]["text"], 1, None,
                                                    v)
                    if type(v) == bool:
                        inputs[k] = st.checkbox(DICT[k]["text"], v)
                    if DICT[k]["desc"] is not None:
                        st.markdown('<sup>' + DICT[k]["desc"] + '</sup>',
                                    unsafe_allow_html=True)

                    if k == "prioritized" and inputs["prioritized"]:
                        inputs["alpha"] = st.number_input(
                            "Alpha", 0.000, 1., 0.5)
                        st.markdown(
                            '<sup> Determines how much prioritization is used, with α = 0 corresponding to the uniform case </sup>',
                            unsafe_allow_html=True)
                        inputs["beta"] = st.number_input(
                            "Beta", 0.000, 1., 0.5)
                        st.markdown(
                            "<sup> Importance sampling weights, reduce gradients according to samples' importance, higher values correspord to greater downscaling </sup>",
                            unsafe_allow_html=True)
            """if "Exploration level" in section[i]:
                import numpy as np, pandas as pd
                st.markdown('<sup> Epsilon curve </sup>', unsafe_allow_html=True)
                linear_decay.eps_train = inputs["eps_train"]
                linear_decay.eps_train_final = inputs["eps_train_final"]
                x = np.linspace(0, inputs["epoch"] * inputs["step_per_epoch"] * inputs["collect_per_step"], 100)
                y = np.vectorize(linear_decay)(x[:, np.newaxis])
                chart_data = pd.DataFrame(y, x, columns=['lr'])
                st.line_chart(chart_data)"""

            if "Training duration" in section[i]:
                st.markdown(
                    'Training frames: ' +
                    str(inputs["epoch"] * inputs["step_per_epoch"] *
                        inputs["collect_per_step"]),
                    unsafe_allow_html=True,
                )

        st.write("## Configuration :robot_face:")

        inputs["optimizer"] = st.selectbox("Optimizer", OPTIMIZERS)
        inputs["gpu"] = st.checkbox("Use GPU if available", True)
        inputs["tensorboard"] = st.checkbox("Tensorboard visualization", True)
        inputs["save"] = st.checkbox("Save best model", True)
        inputs["watch"] = st.checkbox("Test final performance", True)
        #inputs["args"] = st.checkbox("Use 'args' as input", True)
        inputs["seed"] = st.number_input("Random seed", 0, None, 0)

    return inputs
예제 #8
0
# Create color palette
rgbs = [[84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76],
        [84, 71, 140], [44, 105, 154], [4, 139, 168], [13, 179, 158], [22, 219, 147], [131, 227, 119], [185, 231, 105], [239, 234, 90], [241, 196, 83], [242, 158, 76]]

layers = []
if dfs:
    
    # Create multi selector for filenames
    opts = [options.index(o) for o in st.multiselect('Select datafile(s) to visualize', options, default=options)]
    sub = st.number_input('Resample every', 1, 20, 10, format='%i')

    # Calculate viewport of entire dataset
    for ii, num in enumerate(opts):
        df_ = dfs[num]
        if ii == 0:
            df_['survey'] = ii
            df = df_.copy()
        else:
            df_['survey'] = ii
            df = df.append(df_)
    
        # Construct layers
        layers.append(pdk.Layer('ScatterplotLayer',
                                df_[['survey', 'WGS84_LON', 'WGS84_LAT']], 
                                get_position=['WGS84_LON', 'WGS84_LAT'],
예제 #9
0
    st.image(open(image_filepath, 'rb').read(), caption='', use_column_width=True)
    
    st.write("Supported Documents : \n - Aadhaar Card (UIDAI)"
             )
elif Run_Mode == 'Aadhaar Card':
    st.write(" Document Type **Aadhaar Card** ")
    feature = st.sidebar.radio("What's dow you want to try?",('Mask 1st 8 digits of Aadhaar',
                                                              'Validate Aadhaar Number',
                                                              'Extract Aadhaar Number', 
                                                              'Mask Aadhaar Number',
                                                              'Brut Mask Numbers'))
    
    if feature == "Validate Aadhaar Number":
        st.write('Please enter 12 digit Aadhaar Number')
        number = st.number_input('Insert aadhaar number', min_value=10000000000, 
                                  max_value=999999999999, value=397788000234, 
                                  step=1,format = '%d')
        #st.write('The current number is ', number)
        if st.button('Validate'):
            if hit_api_validate(number)['validity']:
                st.write(" :white_check_mark: Valid Aadhaar Card Sequence Number")
            else:
                st.write(" :no_entry: Invalid Aadhaar Card Sequence Number")
    elif feature == "Extract Aadhaar Number":

        uploaded_file = st.file_uploader("Upload an image file", type=['png', 'jpg'])
        
        if uploaded_file is not None:
#            image = Image.open(uploaded_file)
            st.image(uploaded_file, caption='Uploaded Image.', use_column_width=True) #width = 450)#
            st.write("Click on extract to **extract** Aadhar Number from the image!")
예제 #10
0
파일: Covid19.py 프로젝트: NAMD/covidash
def main():
    st.sidebar.image(logo, use_column_width=True)
    page = st.sidebar.selectbox("Escolha uma Análise", [
        HOME, MODELS, DATA, PAGE_CASE_DEATH_NUMBER_BR, CUM_DEATH_CART,
        PAGE_GLOBAL_CASES, MAPA, CREDITOS
    ])
    if page == HOME:
        st.header("Analisando a Pandemia de COVID-19 no Brasil")
        st.markdown(
            """Neste site buscamos trazer até você os números da epidemia, a medida que se revelam, 
        mas também um olhar analítico, capaz de desvelar a dinâmica do processo de transmissão do vírus SARS-Cov-2
        por meio de modelos matemáticos, análises estatísticas e visualização de informação.
        
Pelo *painel à esquerda* você pode ***navegar entre nossas análises***, as quais estaremos atualizando constantemente 
daqui para frente. 
## Outros Recursos de Interesse
Vamos compilar aqui também outras fontes de informação de confiança para que você possa se manter atualizado 
com os últimos resultados científicos sobre a Pandemia.

* Canal [A Matemática das Epidemias](https://www.youtube.com/channel/UCZFllLoI5kB4o_6w59YVzAA?view_as=subscriber).
* Grupo MAVE: [Métodos Analíticos em Vigilância Epidemiológica](https://covid-19.procc.fiocruz.br).

## Fontes de Dados
As sguintes fontes de dados foram usadas neste projeto:

* [Brasil.io](https://brasil.io): Dados de incidência e mortalidade no Brasil
* [Johns Hopkins CSSE](https://github.com/CSSEGISandData/COVID-19): Dados de incidência e mortalidade globais.

## Softwares opensource
Várias bibliotecas opensource foram utilizadas na construção deste dashboard:

* [Streamlit](https://streamlit.io): Web framework voltada para ciência de dados.
* [Epimodels](https://github.com/fccoelho/epimodels): Biblioteca de modelos matemáticos para simulação de epidemias.

        """)
        data = dashboard_data.get_data()
    elif page == MODELS:
        st.title("Explore a dinâmica da COVID-19")
        st.sidebar.markdown("### Parâmetros do modelo")
        chi = st.sidebar.slider('χ, Fração de quarentenados', 0.0, 1.0, 0.76)
        phi = st.sidebar.slider('φ, Taxa de Hospitalização', 0.0, 0.5, 0.005)
        beta = st.sidebar.slider('β, Taxa de transmissão', 0.0, 1.0, 0.6)
        rho = st.sidebar.slider('ρ, Taxa de alta dos hospitalizados:', 0.0,
                                1.0, 0.12)
        delta = st.sidebar.slider('δ, Taxa de recuperação de Sintomáticos:',
                                  0.0, 1.0, 0.1)
        gamma = st.sidebar.slider('γ, Taxa de recuperação de Assintomáticos:',
                                  0.0, 1.0, 0.05)
        alpha = st.sidebar.slider('α, Taxa de incubação', 0.0, 10.0, .37)
        mu = st.sidebar.slider('μ, Taxa de mortalidade pela COVID-19', 0.0,
                               1.0, .01)

        p = st.slider('Fração de assintomáticos:', 0.0, 1.0, 0.63)
        q = st.slider('Dia de início da Quarentena:', 1, 165, 35)
        r = st.slider('duração em dias da Quarentena:', 0, 200, 80)
        N = st.number_input('População em Risco:',
                            value=102.3e6,
                            max_value=200e6,
                            step=1e6)
        st.markdown(
            f"""$R_0={(beta * (1-chi)*(p*(phi+delta)+(1-p)*gamma)) / (gamma*(delta+phi)):.2f}$, durante a quarentena. &nbsp 
                    $R_0={(beta * (1-0)*(p*(phi+delta)+(1-p)*gamma)) / (gamma*(delta+phi)):.2f}$, fora da quarentena."""
        )

        params = {
            'chi': chi,
            'phi': phi,
            'beta': beta,
            'rho': rho,
            'delta': delta,
            'gamma': gamma,
            'alpha': alpha,
            'mu': mu,
            'p': p,
            'q': q,
            'r': r
        }
        traces = pd.DataFrame(data=seqiahr_model(params=params)).rename(
            columns=COLUMNS)
        final_traces = dashboard_models.prepare_model_data(
            traces, VARIABLES, COLUMNS, N)

        # Dataframes
        Hospitalizacoes = traces['Hospitalizações Acumuladas']
        Hosp_t = traces['Hospitalizados']
        Mortes = traces['Mortes Acumuladas']
        Infectados = traces['Infectados']
        Recuperados = traces['Recuperados']

        # Valores
        pico_infectados = Infectados.iloc[Infectados.idxmax()]
        pico_hosp = Hosp_t.iloc[Hosp_t.idxmax()]
        pico_mortes = Mortes.iloc[Mortes.diff().idxmax()]
        Hospitalizacoes_totais = Hospitalizacoes.iloc[-1]
        mortes_totais = Mortes.iloc[-1]
        inf_tot = N - Recuperados.iloc[-1] - mortes_totais

        stats = pd.DataFrame(data={
            'Pico': [
                hp.intword(pico_infectados * N),
                hp.intword(pico_hosp * N),
                hp.intword(pico_mortes * N)
            ],
            'Total': [
                hp.intword(inf_tot),
                hp.intword(Hospitalizacoes_totais * N),
                hp.intword(mortes_totais * N)
            ]
        },
                             index=['Infecções', 'Hospitalizações', 'Mortes'])

        st.markdown(f"""### Números importantes da simulação""")
        st.dataframe(stats)
        st.markdown(
            f"""O pico das hospitalizações ocorrerá após {Hosp_t.idxmax()} dias"""
        )
        st.markdown(
            f"""O pico das Mortes ocorrerá após {Mortes.diff().idxmax()} dias"""
        )

        dashboard_models.plot_model(final_traces, q, r)
        st.markdown('''### Comparando Projeções e Dados
Podemos agora comparar nossa série simulada de Hospitalizações acumuladas com o número de casos acumulados 
de notificações oficiais.
        ''')
        ofs = st.number_input("Atraso no início da notificação (dias)",
                              value=0,
                              min_value=0,
                              max_value=90,
                              step=1)
        st.markdown(
            'Na caixa acima, você pode mover lateralmente a curva, Assumindo que os primeiro caso '
            'notificado não corresponde ao início da transmissão')
        dashboard_models.plot_predictions(ofs, final_traces, dias=365)
        st.markdown('### Formulação do modelo')
        st.write(r"""
                $\frac{dS}{dt}=-\lambda[(1-\chi) S]$

                $\frac{dE}{dt}= \lambda [(1-\chi) S] -\alpha E$

                $\frac{dI}{dt}= (1-p)\alpha E - \delta I -\phi I$

                $\frac{dA}{dt}= p\alpha E - \gamma A$

                $\frac{dH}{dt}= \phi I -(\rho+\mu) H$

                $\frac{dR}{dt}= \delta I + \rho H+\gamma A$

                $\lambda=\beta(I+A)$

                $\mathcal{R}_0 = \frac{\beta(1-\chi)( p (\phi + \delta) +(1-p)\gamma)}{\gamma(\delta + \phi)}$
                """)

    elif page == DATA:
        st.title('Probabilidade de Epidemia por Município ao Longo do tempo')

        @st.cache
        def read_video():
            with open('dashboard/video_prob.mp4', 'rb') as v:
                video = v.read()
            return video

        st.video(read_video())
        st.markdown(r'''## Descrição da modelagem:
Os municípios brasileiros são conectados por uma malha de transporte muito bem desenvolvida e através desta,
cidadãs e cidadãos viajam diariamente entre as cidades para trabalhar, estudar e realizar outras atividades.
Considerando o fluxo de indivíduos (infectados) que chega em um município em um determinado dia, caso este município
ainda não estejam em transmissão comunitária, podemos calcular a probabilidade de uma epidemia se estabelecer.
Esta probabilidade é dada por esta fórmula:

$$P_{epi}=1-\left(\frac{1}{R_0}\right)^{I_0}$$,

onde $I_0$ é o número de infectados chegando diáriamente no município. Neste cenário usamos um $R_0=2.5$.
        ''')

    elif page == PAGE_CASE_DEATH_NUMBER_BR:
        st.title(PAGE_CASE_DEATH_NUMBER_BR)
        x_variable = "date"
        y_variable = "Casos Confirmados"
        y_variable2 = "Mortes Acumuladas"

        data = dashboard_data.get_data()
        ufs = sorted(list(data.state.drop_duplicates().values))
        uf_option = st.multiselect("Selecione o Estado", ufs)

        city_options = None

        if uf_option:
            cities = dashboard_data.get_city_list(data, uf_option)
            city_options = st.multiselect("Selecione os Municípios", cities)

        is_log = st.checkbox('Escala Logarítmica', value=False)
        region_name, data_uf_confirmed = dashboard_data.get_data_uf(
            data, uf_option, city_options, y_variable)
        region_name, data_uf_deaths = dashboard_data.get_data_uf(
            data, uf_option, city_options, y_variable2)

        figure = dashboard_data.plot_series(data_uf_confirmed, x_variable,
                                            y_variable, region_name, is_log)
        figure = dashboard_data.add_series(figure, data_uf_deaths, x_variable,
                                           y_variable2, region_name, is_log)

        st.plotly_chart(figure)

        st.markdown(
            "**Fonte**: [brasil.io](https://brasil.io/dataset/covid19/caso)")
        st.markdown(r"""## Evolução da Letalidade por Estado Brasileiro
No gráfico abaixo, podemos ver como a letalidade(Fração dos casos confirmados que foi a óbito) está evoluindo 
com o tempo em cada estado.

É importante lembrar que estes números não representam todas as mortes por COVID-19 no país, pois apenas as mortes de 
casos testados e confirmados são efetivamente contadas como mortes oficiais pela COVID-19. Devido à escassez de testes e 
recomendações sobre quem deve ser testado, existe um viés nestas estimativas.

Na figura abaixo o eixo vertical representa a letalidade: $\frac{mortes}{casos}$, o eixo Horizontal representa o número 
total de casos. O tamanho dos círculos representa o número total de mortes em cada estado. Este gráfico é mais fácil de 
ser estudado em tela cheia. clicando na legenda é possível "ligar" e "desligar" a visualização dos estados individualmente,
para facilitar a visualização dos demais. Passando o mouse por sobre os circulos, podemos ler os valores da letalidade e 
da data a que corresponde.
        """)
        dashboard_data.plot_scatter_CFR(data)

        st.markdown('''## Excesso de Mortes por Estado
Abaixo, exploramos o excesso de mortalidade nos estados que a COVID-19 representa, quando comparada à média dos 
últimos 10 anos de mortes por doenças respiratórias.
        ''')
        uf_option2 = st.selectbox("Selecione o Estado", ufs)
        viral = st.checkbox(
            "Apenas Mortalidade por pneumonia viral? Desmarque para comparar com o total de mortes respiratórias",
            value=True)
        dashboard_data.plot_excess_deaths(data, uf_option2, viral)

    elif page == CUM_DEATH_CART:
        st.title(CUM_DEATH_CART)
        x_variable = "date"
        y_variable = "deaths_covid19"
        y_variable2 = "Mortes Acumuladas"
        data = dashboard_data.get_data_from_source(
            dashboard_data.BRASIL_IO_CART, usecols=None, rename_cols=None)
        data2 = dashboard_data.get_data()
        ufs = sorted(list(data.state.drop_duplicates().values))
        uf_option = st.multiselect("Selecione o Estado", ufs)
        is_log = st.checkbox('Escala Logarítmica', value=False)
        city_options = None
        # get data
        region_name, data_uf = dashboard_data.get_data_cart(
            data, uf_option, y_variable)
        region_name, data_uf_deaths = dashboard_data.get_data_uf(
            data2, uf_option, city_options, y_variable2)
        # Plota mortes dos cartorios
        fig = dashboard_data.plot_series(
            data_uf,
            x_variable,
            y_variable,
            region_name,
            is_log,
            label='Mortes registradas em Cartório')
        fig = dashboard_data.add_series(fig, data_uf_deaths, x_variable,
                                        y_variable2, region_name, is_log,
                                        "Mortes Oficiais")

        st.plotly_chart(fig)

        st.markdown(
            "**Fonte**: [brasil.io](https://brasil.io/dataset/covid19/obito_cartorio)"
        )

    elif page == MAPA:

        # Precisa refatorar
        st.title("Distribuição Geográfica de Casos")
        cases = dashboard_data.get_data()
        estados = dashboard_data.load_lat_long()
        estados['casos'] = 0
        cases = cases[cases.place_type != 'state'].groupby(['date',
                                                            'state']).sum()
        cases.reset_index(inplace=True)

        for i, row in estados.iterrows():
            if row.Estados in list(cases.state):
                estados.loc[estados.Estados == row.Estados, 'casos'] += \
                    cases[(cases.state == row.Estados) & (cases.is_last)]['Casos Confirmados'].iloc[0]

        midpoint = (np.average(estados["Latitude"]),
                    np.average(estados["Longitude"]))

        layer = pdk.Layer("ColumnLayer",
                          data=estados,
                          get_position=["Longitude", "Latitude"],
                          get_elevation=['casos'],
                          auto_highlight=True,
                          radius=50000,
                          elevation_scale=300,
                          get_color=[100, 255, 100, 255],
                          pickable=True,
                          extruded=True,
                          coverage=1)

        view_state = pdk.ViewState(
            longitude=midpoint[1],
            latitude=midpoint[0],
            zoom=3,
            pitch=20.,
        )

        mapbox_style = 'mapbox://styles/mapbox/light-v9'
        mapbox_key = 'pk.eyJ1IjoiZmNjb2VsaG8iLCJhIjoiY2s4c293dzc3MGJodzNmcGEweTgxdGpudyJ9.UmSRs3e4EqTOte6jYWoaxg'

        st.write(
            pdk.Deck(
                map_style=mapbox_style,
                mapbox_key=mapbox_key,
                initial_view_state=view_state,
                layers=[layer],
                tooltip={
                    "html":
                    "<b>Estado:</b> {Estados}<br><b>Número de casos:</b> {casos}",
                    "style": {
                        "color": "white"
                    }
                },
            ))

        st.markdown(
            "**Fonte**: [brasil.io](https://brasil.io/dataset/covid19/caso)")

    elif page == PAGE_GLOBAL_CASES:
        st.title(PAGE_GLOBAL_CASES)
        x_variable = "Data"
        y_variable = "Casos"
        global_cases = dashboard_data.get_global_cases() \
            .drop(["Province/State", "Lat", "Long"], axis="columns")

        melted_global_cases = pd.melt(global_cases,
                                      id_vars=["País/Região"],
                                      var_name=x_variable,
                                      value_name=y_variable)
        melted_global_cases["Data"] = pd.to_datetime(
            melted_global_cases["Data"])
        countries = dashboard_data.get_countries_list(melted_global_cases)
        countries_options = st.multiselect("Selecione os Países", countries)

        region_name, countries_data = dashboard_data.get_countries_data(
            melted_global_cases, countries_options)
        is_log = st.checkbox('Escala Logarítmica', value=False)

        fig = dashboard_data.plot_series(countries_data, x_variable,
                                         y_variable, region_name, is_log)
        st.plotly_chart(fig)
        st.markdown(
            "**Fonte**: [Johns Hopkins CSSE](https://github.com/CSSEGISandData/COVID-19)"
        )

    elif page == CREDITOS:
        st.markdown(open('dashboard/creditos.md', 'r').read())
예제 #11
0
    y = np.arange(3)

    ax.set_yticks(y)
    ax.set_yticklabels(['Iris-setosa','Iris-versicolor','Iris-virginica'])

    ax.set_xlabel('Probability')
    ax.set_title('Predictions')

    return fig


if __name__ == "__main__":

     model = keras.models.load_model("saved_model")


     sepal_length = st.number_input("Sepal Length")
     sepal_width = st.number_input("Sepal Width")
     petal_length = st.number_input("Petal Length")
     petal_width = st.number_input("Petal Width")


     x = np.array([sepal_length,sepal_width,petal_length,petal_width]).reshape(1,-1)
  
     predictions = model.predict(x).reshape(3,1) * 100
  
     fig = graph(predictions)

     st.write(fig)
예제 #12
0
def main():
    analysis = st.sidebar.selectbox("Choose prediction type",
                                    ["2020/2021", "2019/2020"])
    if analysis == '2020/2021':
        pipeline = joblib.load(PATH_TO_MODEL)
        st.header("Beat the Bookies")
        # input from user with arbitary default team name suggestions and game week
        match = st.selectbox('Select a Match', MATCHES)
        if match[0] == 'M':
            home_team = 'Manchester City'
            away_team = 'Manchester United'
        elif match[0] == 'W':
            home_team = 'West Ham United'
            away_team = 'Leicester City'
        elif match[0] == 'C':
            home_team = 'Crystal Palace'
            away_team = 'Arsenal'
        elif match[0] == 'T':
            home_team = 'Tottenham Hotspur'
            away_team = 'Chelsea'
        elif match[0] == 'L':
            home_team = 'Liverpool'
            away_team = 'Wolverhampton Wanderers'
        elif match[0] == 'E':
            home_team = 'Everton'
            away_team = 'Watford'
        elif match[0] == 'N':
            home_team = 'Newcastle United'
            away_team = 'Sheffield United'
        elif match[0] == 'B':
            home_team = 'Brighton & Hove Albion'
            away_team = 'AFC Bournemouth'
        elif match[0] == 'A':
            home_team = 'Aston Villa'
            away_team = 'Burnley'
        elif match[0] == 'S':
            home_team = 'Southampton'
            away_team = 'Norwich City'
        bet = st.number_input('Max Bet Per Game')

        st.write('You selected:')

        st.write('**Fifa Rankings**')
        home_ranks = FIFA_DF[FIFA_DF['Team'] == home_team]
        away_ranks = FIFA_DF[FIFA_DF['Team'] == away_team]
        df = pd.concat([home_ranks, away_ranks], axis=0)
        st.table(
            df.drop(columns='League').set_index('Team').style.highlight_max(
                axis=0))
        game = generate_game()
        home_stats = game[[
            'home_t_total_wins', 'home_t_total_losses', 'home_t_total_draws',
            'home_t_total_goals', 'home_t_home_goals',
            'home_t_home_goals_against', 'home_t_prev_home_matches',
            'home_t_total_shots', 'home_t_total_shots_ot',
            'home_t_total_goals_against'
        ]]
        away_stats = game[[
            'away_t_total_wins', 'away_t_total_losses', 'away_t_total_draws',
            'away_t_total_goals', 'away_t_away_goals',
            'away_t_away_goals_against', 'away_t_prev_away_matches',
            'away_t_total_shots', 'away_t_total_shots_ot',
            'away_t_total_goals_against'
        ]]
        away_stats['Team'] = away_team
        home_stats['Team'] = home_team

        home_show = home_stats[[
            'Team', 'home_t_total_wins', 'home_t_total_losses',
            'home_t_total_draws', 'home_t_total_goals',
            'home_t_total_goals_against', 'home_t_total_shots',
            'home_t_total_shots_ot'
        ]]
        away_show = away_stats[[
            'Team', 'away_t_total_wins', 'away_t_total_losses',
            'away_t_total_draws', 'away_t_total_goals',
            'away_t_total_goals_against', 'away_t_total_shots',
            'away_t_total_shots_ot'
        ]]
        cols = [
            'Team', 'Wins', 'Losses', 'Draws', 'Goals', 'Goals Against',
            'Shots', 'Shots On Target'
        ]
        home_show.columns = cols
        away_show.columns = cols

        st.write('**Team Stats**')
        stat_df = pd.concat([home_show, away_show], axis=0)
        st.table(stat_df.set_index('Team'))

        st.write('**Game Odds**')
        odds = pd.DataFrame(
            {
                'Home Win': round(uniform(1.3, 3.5), 2),
                'Away Win': round(uniform(1.5, 8), 2),
                'Draw': round(uniform(2.5, 4), 2)
            },
            index=[0])
        st.table(odds.assign(hack='William Hill Odds').set_index('hack'))
        odds['stage'] = game['stage']
        game_stats = odds[['Home Win', 'Away Win', 'Draw', 'stage']]
        game_stats.columns = ['WHH', 'WHA', 'WHD', 'stage']
        to_predict = {
            'home_rank': home_ranks,
            'away_rank': away_ranks,
            'home_stats': home_stats,
            'away_stats': away_stats,
            'game_stats': game_stats
        }
        to_predict = [to_predict]
        to_predict = [format_input(team) for team in to_predict]
        X = pd.DataFrame(to_predict)
        X = X[COLS]
        prediction = pipeline.predict(X[COLS])[0]
        prediction_proba = pipeline.predict_proba(X[COLS])[0][1]
        kelly = kelly_prediction(prediction_proba, odds['Home Win'].values[0],
                                 bet)
        if prediction == 1:
            st.subheader(
                f"Your best bet is on the hometeam with {round(prediction_proba * 100,2)}% certainty"
            )
            st.subheader(f"The kelly principle suggests a bet of £{kelly}")
        else:
            st.subheader(
                f"Not looking great for the hometeam, only a {round(prediction_proba * 100,2)}% chance of a win"
            )
            st.subheader(f"The kelly principle suggests a bet of £{kelly}")
        st.markdown("**Place your bets with your favourite Bookmaker**")

        st.markdown(
            "Please gamble responsibly, for more information visit https://www.begambleaware.org"
        )

    if analysis == "2019/2020":

        pipeline = joblib.load('model.joblib')
        # input from user with arbitary default team name suggestions and game week
        st.markdown("""<a id="top"></a>""", unsafe_allow_html=True)
        stage = st.number_input('Game Week', min_value=1, max_value=39)
        bet = st.number_input('Max Bet Per Game')
        toc = Toc()
        href = f"""<a href="#top"> Back to top </a>"""
        st.title("This Weeks Games")
        toc.placeholder()

        matchups = SEASON_DF[SEASON_DF['stage'] == stage]
        profits = []
        for num in range(len(matchups)):
            game = matchups[num:num + 1]
            ht = game.home_team.values[0]
            toc.header(f'{num + 1}. {ht} Match')
            home_ranks = game[[
                'home_team', 'H_ATT', 'H_MID', 'H_DEF', 'H_OVR'
            ]]
            home_ranks.columns = ['Team', 'ATT', 'MID', 'DEF', 'OVR']
            away_ranks = game[[
                'away_team', 'A_ATT', 'A_MID', 'A_DEF', 'A_OVR'
            ]]
            away_ranks.columns = ['Team', 'ATT', 'MID', 'DEF', 'OVR']
            df = pd.concat([home_ranks, away_ranks], axis=0)
            st.write('**Fifa Rankings**')
            st.table(df.set_index('Team').style.highlight_max(axis=0))
            home_stats = game[[
                'home_t_total_wins', 'home_t_total_losses',
                'home_t_total_draws', 'home_t_total_goals',
                'home_t_home_goals', 'home_t_home_goals_against',
                'home_t_prev_home_matches', 'home_t_total_shots',
                'home_t_total_shots_ot', 'home_t_total_goals_against'
            ]]
            away_stats = game[[
                'away_t_total_wins', 'away_t_total_losses',
                'away_t_total_draws', 'away_t_total_goals',
                'away_t_away_goals', 'away_t_away_goals_against',
                'away_t_prev_away_matches', 'away_t_total_shots',
                'away_t_total_shots_ot', 'away_t_total_goals_against'
            ]]
            away_stats['Team'] = game['away_team'].copy()
            home_stats['Team'] = game['home_team'].copy()
            home_show = home_stats[[
                'Team', 'home_t_total_wins', 'home_t_total_losses',
                'home_t_total_draws', 'home_t_total_goals',
                'home_t_total_goals_against', 'home_t_total_shots',
                'home_t_total_shots_ot'
            ]]
            away_show = away_stats[[
                'Team', 'away_t_total_wins', 'away_t_total_losses',
                'away_t_total_draws', 'away_t_total_goals',
                'away_t_total_goals_against', 'away_t_total_shots',
                'away_t_total_shots_ot'
            ]]
            cols = [
                'Team', 'Wins', 'Losses', 'Draws', 'Goals', 'Goals Against',
                'Shots', 'Shots On Target'
            ]
            home_show.columns = cols
            away_show.columns = cols
            st.write('**Team Stats**')
            stat_df = pd.concat([home_show, away_show], axis=0)
            st.table(stat_df.set_index('Team'))
            odds = game[['WHH', 'WHA', 'WHD']]
            odds.columns = ['Home Win', 'Away Win', 'Draw']
            st.write('**Game Odds**')
            st.table(odds.assign(hack='William Hill Odds').set_index('hack'))
            game_stats = game[['WHH', 'WHA', 'WHD', 'stage']]
            to_predict = {
                'home_rank': home_ranks,
                'away_rank': away_ranks,
                'home_stats': home_stats,
                'away_stats': away_stats,
                'game_stats': game_stats
            }
            to_predict = [to_predict]
            to_predict = [format_input(team) for team in to_predict]
            X = pd.DataFrame(to_predict)
            X = X[COLS]
            prediction = pipeline.predict(X[COLS])[0]
            prediction_proba = pipeline.predict_proba(X[COLS])[0][1]
            kelly = kelly_prediction(prediction_proba, game.WHH.values[0], bet)
            outcome = game['FTR'].values[0]
            if prediction == 1:
                st.subheader(
                    f"Your best bet is on the hometeam with {round(prediction_proba * 100,2)}% certainty"
                )
                st.subheader(f"The kelly principle suggests a bet of £{kelly}")
                if outcome == 'H':
                    profit = round((kelly * game.WHH.values[0]) - kelly, 2)
                    collection = round(kelly * game.WHH.values[0], 2)
                    profits.append(collection)
                    st.write("**Results**")
                    st.write(f'Home Team Victory, collect your £{collection}')
                elif outcome == 'D':
                    profit = -kelly
                    profits.append(profit)
                    st.write("**Results**")
                    st.write("Draw, sorry about that - close but no cigar")
                elif outcome == 'A':
                    profit = -kelly
                    profits.append(profit)
                    st.write("**Results**")
                    st.write(
                        "Away Team Victory, yikes....well, nobody bats 1000")

            else:
                st.subheader(
                    f"Not looking great for the hometeam, only a {round(prediction_proba * 100,2)}% chance of a win"
                )
                st.subheader(f"The kelly principle suggests a bet of £{kelly}")
                if outcome == 'H':
                    st.write("**Results**")
                    st.write('Home Team Vicoty, better safe than sorry!')
                elif outcome == 'D':
                    st.write("**Results**")
                    st.write("Draw, that was close, but we told ya so")
                elif outcome == 'A':
                    st.write("**Results**")
                    st.write("Away Team Victory, nailed it")
            st.markdown(href, unsafe_allow_html=True)
            st.write('___')

        weekly_profit = round(sum(profits), 2)
        toc.header(f'Weekly Results')
        st.write(f'**Total collections for the week were £{weekly_profit}**')
        if weekly_profit > 0:
            st.balloons()

        st.markdown(
            "Please gamble responsibly, for more information visit https://www.begambleaware.org"
        )
        st.markdown(href, unsafe_allow_html=True)
        toc.generate()
예제 #13
0
    def test_format_int_and_default_step(self):
        st.number_input("the label", value=10, format="%d")

        c = self.get_delta_from_queue().new_element.number_input
        self.assertEqual(c.format, "%d")
        self.assertEqual(c.step, 1)
예제 #14
0
    def test_default_format_float(self):
        st.number_input("the label", value=10.5)

        c = self.get_delta_from_queue().new_element.number_input
        self.assertEqual(c.format, "%0.2f")
예제 #15
0
    st.write(f"{row[0]} has a :{row[1]}:")

col1, col2 = st.beta_columns(2)
col1.success("First Column")
col1.button("Hello")
col2.success("Second COlumn")
col2.button("Hello From Col2")

for row in rows:
    col2.write(f"{row[0]} has a :{row[1]}:")

with col1:
    st.success("From Col1")
    mytext = st.text_area("Enter Text Here")

with col2:
    st.info("From Col2")
    my_year = st.number_input("Year", 1995, 2040)
    st.write(my_year)

uploaded_file = st.file_uploader("Choose an image...", type="jpg")
if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image.', use_column_width=True)
    st.write("")
    st.write("Classifying...")

# df = pd.read_sql("select * from gold_price;", conn)

# st.write(df)
예제 #16
0
st.write('You selected:', options)

st.header('Slider')
age = st.slider('How old are you?', 0, 130, 25)
st.write("I'm ", age, 'years old')

st.header('Slider Range')
values = st.slider('Select a range of values', 0.0, 100.0, (25.0, 75.0))
st.write('Values:', values)

st.header('Text Input')
title = st.text_input('Movie title', 'Life of Brian')
st.write('The current movie title is', title)

st.header('Number Input')
number = st.number_input('Insert a number')
st.write('The current number is ', number)

st.header('Text Area')
txt = st.text_area(
    'Text to analyze', '''
     It was the best of times, it was the worst of times, it was
     the age of wisdom, it was the age of foolishness, it was
     the epoch of belief, it was the epoch of incredulity, it
     was the season of Light, it was the season of Darkness, it
     was the spring of hope, it was the winter of despair, (...)
     ''')
st.write('Sentiment:', txt)

st.header('Date Input')
d = st.date_input('Whens your birthday', datetime.date(2019, 7, 6))
예제 #17
0
def lru():
    num_faltas = 0
    f = []
    stt = []

    num_quadros = st.number_input(label='Número de Quadros',
                                  step=1,
                                  value=3,
                                  min_value=0,
                                  max_value=20)
    string = st.text_input(label='Sequência de Acesso',
                           value="7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1")

    s = list(map(int, string.strip().split()))

    refs = []
    hits = []
    quadros = []

    st.write('Resultado:')

    g = globals()
    for i in range(num_quadros):
        g['q{0}'.format(i + 1)] = []

    # Para cada página da sequência de processos
    for i in s:
        refs.append(i)
        # Se a página não está no array
        if i not in f:
            # Se há disponibilidade no array, adiciona uma página
            # Mantém o índice da página menos recentemente utilizada (LRU)
            if (len(f) < num_quadros):
                f.append(i)
                stt.append(len(f) - 1)
            # Mantém o índice de cada página
            else:
                ind = stt.pop(0)
                f[ind] = i
                stt.append(ind)
            # Incrementa a falta de página
            num_faltas += 1
            hits.append('Sim')
        # "Hit"
        # Substitui a página atual pela página menos recentemente utilizada (LRU)
        else:
            stt.append(stt.pop(stt.index(f.index(i))))
            hits.append('Não')

        # Preenche os quadros
        for x in f:
            quadros.append(x)
        for x in range(num_quadros - len(f)):
            quadros.append(None)

    # Cria os arrays de quadro
    q_cont = 0
    for i in range(len(quadros)):
        if q_cont == num_quadros:
            q_cont = 0

        if quadros[i] == None:
            g['q{0}'.format(q_cont + 1)].append('')
        else:
            g['q{0}'.format(q_cont + 1)].append(quadros[i])
        q_cont += 1

    # Cria o índice da tabela
    index = []
    index.append('Página')
    for i in range(num_quadros):
        index.append('Q' + str(i + 1))

    index.append('Falta?')

    # Cria as linhas
    linhas = []
    linhas.append(refs)
    for i in range(num_quadros):
        linhas.append(g['q{0}'.format(i + 1)])
    linhas.append(hits)

    # Cria a tabela
    df = pd.DataFrame(linhas, index=index)
    st.dataframe(
        df.style.applymap(cor_falta_pagina).apply(lambda x: [
            'color: white; background-color: deeppink'
            if x.name == 'Página' else '' for i in x
        ],
                                                  axis=1))

    botao_download(df)

    st.write('**Faltas de Página:** ' + str(num_faltas))
    st.write('**Total de Páginas:** ' + str(len(s)))
예제 #18
0
                str(a[(a.Process_name==process_name) & (a.Dim_name==dim_name)]['Ppk'].values[0])

                dim_infor_string_list.append(dim_infor_string)
            except:  # if no process indicator (sigma=0, no Cp, Cpk...) so need continue (he qua cua try except tren)
                continue

        name_list_dict[process_name] = dim_infor_string_list
        #name_list.append(dim_name)
    return process_indicator_df, name_list_dict


process_indicator_df, name_list_dict = create_process_indicator(final_data)

#------------------------Show process indicator-----------------------------#
st.subheader("Process indicator: Cp, Pb, Cpk, Ppk")
limit = st.number_input("Please input lower limit of Cpk and Ppk", value=1.33)
limit = float(limit)


#limit = 1.33  # sigma: 4, Yield: 99.99%
#@st.cache(allow_output_mutation=True) # Moi them vao
def hightlight_price(row):
    ret = ["" for _ in row.index]
    if row.Cpk < limit or row.Ppk < limit:
        ret[row.index.get_loc("Process_name")] = "background-color: yellow"
        ret[row.index.get_loc("Dim_name")] = "background-color: yellow"
    if row.Cpk < limit:
        ret[row.index.get_loc("Cpk")] = "background-color: yellow"
    if row.Ppk < limit:
        ret[row.index.get_loc("Ppk")] = "background-color: yellow"
    return ret
def main():
    st.title('Perform EDA with ease...')

    def file_select(folder='./datasets'):
        filelist=os.listdir(folder)
        selectedfile=st.selectbox('select a default file',filelist)
        return os.path.join(folder,selectedfile)


    if st.checkbox('Select dataset from local machine'):
        data=st.file_uploader('Upload Dataset in .CSV',type=['CSV'])
        if data is not None:
            df=pd.read_csv(data)
    else:
        filename=file_select()
        st.info('You selected {}'.format(filename))
        if filename is not None:
            df=pd.read_csv(filename)
    #show data
    if st.checkbox('Show Dataset'):
        num=st.number_input('No. of Rows',5,10)
        head=st.radio('Select Head/Tail',('Head','Tail'))
        if head=='Head':
            st.dataframe(df.head(num))
        else:
            st.dataframe(df.tail(num))
        
    #show columns
    if st.checkbox('Columns'):
        st.write(df.columns)
    #show shape
    if st.checkbox('Shape'):
        st.text('(Rows,Columns)')
        st.write(df.shape)
    
    #select columns
    if st.checkbox('Select Columns to show'):
        collist=df.columns.tolist()
        selcols=st.multiselect("Select",collist)
        newdf=df[selcols]
        st.dataframe(newdf)
    #unique values
    if st.checkbox('Unique Values'):
        st.dataframe(df.nunique())
        selectedcol=st.selectbox('Select column to see unique values',df.columns.tolist())
        st.write(df[selectedcol].unique())
    #data type
    if st.checkbox('Data Types'):
        st.dataframe(df.dtypes)
    #chech for nul values
    if st.checkbox('Null values'):
        st.dataframe(df.isnull().sum()) 
        st.write(sns.heatmap(df.isnull(),yticklabels=False,cbar=False,cmap='viridis'))
        st.pyplot()
    #show summary
    if st.checkbox('Summary/Describe'):
        st.write(df.describe())

    #plot and viz.
    st.header('Data Visualization with Seaborn')
    #seaborn correlation plot
    if st.checkbox('Correlation plot'):
        st.write(sns.heatmap(df.corr(),annot=True))
        st.pyplot()
    #univariate distribution
    if st.checkbox('Univariate Distribution'):
        cols=df.columns.tolist()
        plottype=st.selectbox('Select plot type',['dist','hist'])
        selectedcol=st.selectbox('Select columns to plot',cols)
        binnum=st.number_input('No. of bins',10,50)
        st.write(sns.distplot(df[selectedcol],bins=binnum))
        st.pyplot()
    #bivariate distribution
    if st.checkbox('Bivariate Distribution'):
        cols=df.columns.tolist()
        plottype=st.selectbox('Select plot type',['scatterplot','jointplot'])
        st.text('Select two columns')
        x=st.selectbox('Select X-axis column to plot',cols)
        y=st.selectbox('Select Y-axis column to plot',cols)
        kindtype=st.selectbox('Select plot kind',['none','reg','resid','hex','kde'])
        if kindtype!='none':
            st.write(sns.jointplot(df[x],df[y],kind=kindtype))
            st.pyplot()
        else:
            st.write(sns.jointplot(df[x],df[y]))
            st.pyplot()
    #pair wise plot
    if st.checkbox('Pair Plot'):
        cols=df.columns.tolist()
        cols.insert(0,'none')
        selectedcollist=st.multiselect('Select columns to plot',cols)
        hueval=st.selectbox('Select a hue column',cols)
        if hueval!='none':
            st.write(sns.pairplot(df[selectedcollist],hue=df[hueval]))
            st.pyplot()
        else:
            st.write(sns.pairplot(df[selectedcollist]))
            st.pyplot()
    
    #categorical plots
    if st.checkbox('Categorical Scatterplots'):
        cols=df.columns.tolist()
        cols.insert(0,'none')
        plottype=st.selectbox('Select plot type',['stripplot','swarmplot'])
        x=st.selectbox('Select X-axis(categorical) column to plot',cols)
        y=st.selectbox('Select Y-axis(numericall) column to plot',cols)
        hueval=st.selectbox('Select a hue column(categorical)',cols)
        if plottype=='stripplot':
            if x!='none' and hueval!='none':
                st.write(sns.stripplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            elif x!='none' and hueval=='none':
                st.write(sns.stripplot(df[x],df[y]))
                st.pyplot()
        else:
            if x!='none' and hueval!='none':
                st.write(sns.swarmplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            elif x!='none' and hueval=='none':
                st.write(sns.swarmplot(df[x],df[y]))
                st.pyplot()
    #categorical distributions
    if st.checkbox('Categorical Distributions'):
        cols=df.columns.tolist()
        cols.insert(0,'none')
        plottype=st.selectbox('Select plot type',['box','bar','violin','count','point','factor'])
        x=st.selectbox('Select X-axis(catrogrical) column to plot',cols)
        y=st.selectbox('Select Y-axis(numerical) column to plot',cols)
        hueval=st.selectbox('Select a hue column',cols)
        #box plot
        if plottype=='box':
            if hueval!='none':
                st.write(sns.boxplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            else:
                st.write(sns.boxplot(df[x],df[y]))
                st.pyplot()
        #bar plot
        if plottype=='bar':
            if hueval!='none':
                st.write(sns.barplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            else:
                st.write(sns.barplot(df[x],df[y]))
                st.pyplot()
        
        #violin plot
        if plottype=='violin':
            if hueval!='none':
                st.write(sns.violinplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            else:
                st.write(sns.violinplot(df[x],df[y]))
                st.pyplot()
        #count plot
        if plottype=='count':
            st.text('Plotting countplot for selected X column')
            if hueval!='none':
                st.write(sns.countplot(df[x],hue=df[hueval]))
                st.pyplot()
            else:
                st.write(sns.countplot(df[x]))
                st.pyplot()
        
        #point plot
        if plottype=='point':
            if hueval!='none':
                st.write(sns.pointplot(df[x],df[y],hue=df[hueval]))
                st.pyplot()
            else:
                st.write(sns.pointplot(df[x],df[y]))
                st.pyplot()

        #factor plot
        if plottype=='factor':
            typekind=st.selectbox('Select plottype for factor for plot',['point','bar','box','violin','strip','swarm'])
            colm=st.selectbox('Select column(col) parameter',cols)
            rows=st.selectbox('Select(only if col is selected) column(row) parameter',cols)
            if hueval!='none':
                if colm!='none' and rows!='none':
                    st.write(sns.factorplot(x=x,y=y,hue=hueval,col=colm,row=rows,data=df,kind=typekind))
                    st.pyplot()
                elif colm!='none' and rows=='none':
                    st.write(sns.factorplot(x=x,y=y,hue=hueval,col=colm,data=df,kind=typekind))
                    st.pyplot()
            else:
                if colm!='none' and rows!='none':
                    st.write(sns.factorplot(x=x,y=y,col=colm,row=rows,data=df,kind=typekind))
                    st.pyplot()
                elif colm!='none' and rows=='none':
                    st.write(sns.factorplot(x=x,y=y,col=colm,data=df,kind=typekind))
                    st.pyplot()


    #linear relationship
    if st.checkbox('Linear Relationship'):
        cols=df.columns.tolist()
        cols.insert(0,'none')
        xval=st.selectbox('Select X-axis',cols)
        yval=st.selectbox('Select Y-axis',cols)
        hueval=st.selectbox('Select hue column',cols)
        if hueval!='none':
            st.write(sns.lmplot(x=xval,y=yval,hue=hueval,data=df))
            st.pyplot()
        else:
            st.write(sns.lmplot(x=xval,y=yval,data=df))
            st.pyplot()

###########

    st.subheader('Customizable plots')
    cols=df.columns.tolist()
    plottype=st.selectbox('Select plot type',['bar','hist','box','area','line','kde'])
    selectedcollist=st.multiselect('Select columns to plot',cols)

    if st.button('Generate plot'):
        st.success('Generating customizable {} plot for {}'.format(plottype,selectedcollist))
        #plot using streamlit
        if plottype=='area' :
            cusdata=df[selectedcollist]
            st.area_chart(cusdata)
        elif plottype=='bar' :
            cusdata=df[selectedcollist]
            st.bar_chart(cusdata)
        elif plottype=='line' :
            cusdata=df[selectedcollist]
            st.line_chart(cusdata)
        elif plottype :
            cusplot=df[selectedcollist].plot(kind=plottype)
            st.write(cusplot)
            st.pyplot()

    if st.button('See who created this!'):
        st.subheader('Project developed by:')
        st.info('Name: K Vikas Reddy')
        st.info('College: SASTRA Deemed to be University')
        st.info('Gmail:  [email protected]')

    if st.button('Thanks'):
        st.balloons()
    st.text('')
    st.text('')
    st.warning('Please report bugs if any and suggest any new features')
    if st.checkbox('About this project'):
        st.write('Exploratory Data Analysis is the first step every Data Scientist does in every project.') 
        st.write('I saw many people groan to perform EDA. It is because of the same scripts written over and over for every project.')
        st.write('If you also felt the same, then this project is for you. This project helps you perform EDA with ease.')
        st.write('You dont need to write any scripts. EDA can be performed with just few clicks. It is also very time efficient.')
        st.write('As Data Science is becoming very popular, Data Science aspirants should also become smart and productive.')
        st.write('Hope this project helps you to some extent.')
예제 #20
0
def main():
    ### common dataset explorer ###
    st.title("ML dataset explorer")
    st.subheader("Simple Data Science Explorer with dataset")

    html_temp = """ 
    <div style="background-color:tomato"><p>StreamLit App</p></div>
    """
    st.markdown(html_temp, unsafe_allow_html=True)

    def file_selector(folder_path='./datasets'):
        filenames = os.listdir(folder_path)
        select_filenames = st.selectbox("Select a file", filenames)
        return os.path.join(folder_path, select_filenames)

    filename = file_selector()
    st.info("You have selected {}".format(filename))

    ## Read Data ##
    df = pd.read_csv(filename)
    ## Show Data ##
    if st.checkbox("Show Dataset"):
        number = st.number_input("Number of Rows", 1, 100)
        st.dataframe(df.head(number))
    ## Show columns ##
    if st.button("Columns Names"):
        st.write(df.columns)

    ## Show shape ##
    if st.checkbox("Shape of the dataset"):
        st.write(df.shape)
        datadim = st.radio("Show dimension by", ("Rows", "Columns"))
        if datadim == "Rows":
            st.write(df.shape[0])
        elif datadim == "Columns":
            st.write(df.shape[1])
        else:
            st.write(df.shape)

    ## Select columns ##
    if st.checkbox("Select columns to show"):
        all_columns = df.columns.tolist()
        selected_columns = st.multiselect("Select", all_columns)
        new_df = df[selected_columns]
        st.dataframe(new_df)
    ## Show values ##
    if st.button("Value counts"):
        st.text("Value Counts By Target")
        st.write(df.iloc[:, -1].value_counts())

    ## Show Datatypes ##
    if st.button("Data Types"):
        st.write(df.dtypes)
    ## Show summary ##
    if st.checkbox("Show the summary"):
        st.write(df.describe().T)

    ## Plot and Visulaization ##
    st.subheader("Data Visualization")
    ## Correlation
    ## seaborn plot
    if st.checkbox("Correlation plot"):
        st.write(sns.heatmap(df.corr(), annot=True))
        st.pyplot()
    ## count plot
    if st.checkbox("Plot the value count"):
        st.text("Value counts by target")
        all_columns_names = df.columns.tolist()
        primary_col = st.selectbox("Primary columns to group by",
                                   all_columns_names)
        selected_columns_names = st.multiselect("Select column",
                                                all_columns_names)
        if st.button("Plot"):
            st.text("Generate Plot")
            if selected_columns_names:
                vc_plot = df.groupby(
                    primary_col)[selected_columns_names].count()
            else:
                vc_plot = df.iloc[:, -1].value_counts()
            st.write(vc_plot.plot(kind="bar"))
            st.pyplot()

    ## pie charts
    if st.checkbox("Pie plot"):
        all_columns = df.columns.tolist()
        if st.button("Generate plot"):
            st.success("Generating a pie plot")
            st.write(df.iloc[:, -1].value_counts().plot.pie())
            st.pyplot()

    ## customizable plot
    st.subheader("Customizable plots")
    all_columns = df.columns.tolist()
    type_of_plot = st.selectbox("Select type of plot",
                                ["area", "bar", "line", "hist", "box", "kde"])
    selected_columns_names = st.multiselect("Select columns to plot",
                                            all_columns)

    if st.button("Generate plot"):
        st.success("Generating customizable plot of {} for {}".format(
            type_of_plot, selected_columns_names))

        if type_of_plot == 'area chart':
            cust_data = df[selected_columns_names]
            st.area_chart(cust_data)
        elif type_of_plot == 'bar chart':
            cust_data = df[selected_columns_names]
            st.bar_chart(cust_data)
        elif type_of_plot == 'line chart':
            cust_data = df[selected_columns_names]
            st.line_chart(cust_data)
        elif type_of_plot:
            cust_plot = df[selected_columns_names].plot(kind=type_of_plot)
            st.write(cust_plot)
            st.pyplot()
예제 #21
0
    # Get features
    data_feature = GetFeatures(data_csv, X_features)
    # Features normalization
    if st.checkbox("Normalize features"):
        scaler = StandardScaler()
        scaler.fit(data_feature)
        df_scaled = scaler.transform(data_feature)
        data_feature = pd.DataFrame(df_scaled, columns=data_feature.columns)
    # Get target
    data_target = GetTarget(data_csv, y_target)
    st.write("Features", data_feature.head(), "Target", data_target.head())
except:
    st.write("Não foi possível carregar feature e target.")

# Train Test Split
lr_ts = st.number_input("Test size: ")
lr_rs = st.number_input("Random state: ", min_value=1, step=1)
try:
    X_train, X_test, y_train, y_test = train_test_split(
        data_feature, data_target, test_size=lr_ts, random_state=int(lr_rs))
except:
    st.write("Não possivel separar os dados")
########################################

########################################
# LINEAR REGRESSION
########################################
if ML_option == "Linear Regression":
    # Fit the model and predict X_test. Show some analysis.
    try:
        linReg = LinearRegression()
예제 #22
0
# -*- coding: utf-8 -*-
# Copyright 2018-2020 Streamlit Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st

i1 = st.number_input("number input 1")
st.write('value 1: "', i1, '"')

i2 = st.number_input("number input 2", value=1)
st.write('value 2: "', i2, '"')

i3 = st.number_input("number input 3", 1, 10)
st.write('value 3: "', i3, '"')
예제 #23
0
def main():
    # =============================================================================
    #     st.title("Default Predictor")
    # =============================================================================
    st.markdown(
        "<h1 style='text-align: center; color: red;'>Default Predictor</h1>",
        unsafe_allow_html=True)
    html_temp = """
    <div style="background-color:tomato;padding:10px">
    <h2 style="color:white;text-align:center;">Credit Card Default Payment Prediction </h2>
    </div>
    """
    st.markdown(html_temp, unsafe_allow_html=True)

    # =============================================================================
    #     PAY_1 = st.text_input("PAY_1","Repayment Status in September")
    #     PAY_2 = st.text_input("PAY_2","Repayment Status in August")
    #     PAY_3 = st.text_input("PAY_3","Repayment Status in July")
    #     PAY_4 = st.text_input("PAY_4","Repayment Status in June")
    #     PAY_5 = st.text_input("PAY_5","Repayment Status in May")
    #     PAY_6 = st.text_input("PAY_6","Repayment Status in April")
    # =============================================================================

    NAME = st.text_input("Name of the Client")

    AGE = st.number_input("AGE")
    AGE = int(AGE)

    PAY_1 = st.selectbox(
        'PAY_1(REPAYMENT STATUS IN SEPTEMBER)',
        ("0 Months Delay", "1 Month Delay", "2 Months Delay", "3 Months Delay",
         "4 Months Delay", "5 Months Delay", "6 Months Delay",
         "7 Months Delay", "8 Months Delay"))
    x = PAY_1.split(" ")
    PAY_1 = int(x[0])

    PAY_2 = st.selectbox(
        'PAY_2(REPAYMENT STATUS IN AUGUST)',
        ("0 Months Delay", "1 Month Delay", "2 Months Delay", "3 Months Delay",
         "4 Months Delay", "5 Months Delay", "6 Months Delay",
         "7 Months Delay", "8 Months Delay"))

    y = PAY_2.split(" ")
    PAY_2 = int(y[0])

    # =============================================================================
    #     BILL_AMT1 = st.number_input("BILL_AMT1")
    #     BILL_AMT1=int(BILL_AMT1)
    # =============================================================================

    BILL_AMT2 = st.number_input("BILL_AMT2(BILL AMOUNT IN AUGUST)")
    BILL_AMT2 = int(BILL_AMT2)

    PAY_AMT1 = st.number_input(
        "PAY_AMT1(AMOUNT OF PREVIOUS PAYMENT IN SEPTEMBER)")
    PAY_AMT1 = int(PAY_AMT1)

    BILL_AMT3 = st.number_input("BILL_AMT3(BILL AMOUNT IN JULY)")
    BILL_AMT3 = int(BILL_AMT3)

    PAY_AMT2 = st.number_input("PAY_AMT2(PREVIOUS PAYMENT IN AUGUST)")
    PAY_AMT2 = int(PAY_AMT2)

    # =============================================================================
    #     Closeness_1 = st.number_input("Closeness_1")
    #     Closeness_2 = st.number_input("Closeness_2")
    #     #Closeness_3 = st.text_input("Closeness_3","Repayment Status in April")
    #
    #     Closeness_4 = st.number_input("Closeness_4")
    # =============================================================================
    #Closeness_6 = st.text_input("Closeness_6","Repayment Status in April")
    LIMIT_BAL = st.number_input("LIMIT_BAL(CREDIT LIMIT GIVEN TO THE PERSON)")
    LIMIT_BAL = int(LIMIT_BAL)

    #Closeness_1=(LIMIT_BAL) - (BILL_AMT1)
    Closeness_2 = (LIMIT_BAL) - (BILL_AMT2)
    Closeness_3 = (LIMIT_BAL) - (BILL_AMT3)

    #Closeness_4=(LIMIT_BAL) - (BILL_AMT4)

    # top_12_rf=['PAY_1', 'PAY_2', 'BILL_AMT1', 'PAY_AMT1', 'AGE',
    #'Closeness_1', 'PAY_AMT2', 'Closeness_4', 'BILL_AMT2', 'Closeness_2', 'Closeness_3', 'Closeness_6']

    option = st.selectbox(
        'Select A Classifier',
        ('CatBoost', 'Voting Classifier(DT,KNN,LR)',
         'Voting Classifier(DT,KNN,GNB)', 'StackingClassifier(KNN,RF,LR)'))

    st.write('You selected:', option)

    values = instance_values(PAY_1, PAY_2, BILL_AMT2, BILL_AMT3, PAY_AMT1,
                             PAY_AMT2, AGE, Closeness_2, Closeness_3)

    #print(type(values))

    result, probability, text = "", "", ""
    if st.button("Predict"):
        with st.spinner('Predicting The Results...'):

            result, probability, fig1, fig2 = predict_default(
                PAY_1, PAY_2, BILL_AMT2, BILL_AMT3, PAY_AMT1, PAY_AMT2, AGE,
                Closeness_2, Closeness_3, option)
            if result == 1:
                name = NAME if len(NAME) >= 1 else "Person"
                text = "{} is more likely to default next month payment.".format(
                    name)
                st.success('{}.  \nProbability of default is {}  '.format(
                    text, probability))
                st.plotly_chart(fig1)
                st.plotly_chart(fig2)

                #Using Google Text To Speech API
                ta_tts = gTTS(
                    '{}. Probability of default is {} percent, which is {} percent more than the threshold value of 50% '
                    .format(text, probability * 100, (probability * 100) - 50))
                ta_tts.save("trans.mp3")
                audio_file = open("trans.mp3", "rb")
                audio_bytes = audio_file.read()
                st.audio(audio_bytes, format="audio/ogg")


# =============================================================================
#                 audio_file = open('default.wav', 'rb')
#                 audio_bytes = audio_file.read()
#                 st.audio(audio_bytes, format='audio/wav')
# =============================================================================
            else:
                name = NAME if len(NAME) >= 1 else "Person"
                text = " {} is likely to Make the Payment on Time".format(name)
                st.success('{}.  \n Probability of default is {}  '.format(
                    text, probability))
                st.plotly_chart(fig1)
                st.plotly_chart(fig2)
                ta_tts = gTTS(
                    '{}. probability of default is {} percent which is {} percent less than the threshold value of 50%'
                    .format(text, probability * 100, 50 - (probability * 100)))
                ta_tts.save("trans.mp3")
                audio_file = open("trans.mp3", "rb")
                audio_bytes = audio_file.read()
                st.audio(audio_bytes, format="audio/ogg")
    if st.button("Explain LIME Results"):
        st.text(
            "Note:'CLOSENESS' represents how far was the particular bill amount from the Limit Balance of the person"
        )

        #Lime Explainer
        classifier = model_selection(option)
        limeexplainer = interpret_model(sampled_df, feature_set, classifier)
        values = instance_values(PAY_1, PAY_2, BILL_AMT2, BILL_AMT3, PAY_AMT1,
                                 PAY_AMT2, AGE, Closeness_2, Closeness_3)
        explainable_exp = limeexplainer.explain_instance(
            np.array(values),
            classifier.predict_proba,
            num_features=len(feature_set))
        explain = explainable_exp.as_pyplot_figure()

        st.pyplot(explain)
        # Display explainer HTML object
        components.html(explainable_exp.as_html(), height=800)

    if st.button("Explain SHAP Results"):
        with st.spinner('Generating Explanations...'):
            classifier = model_selection(option)
            feat_plot, summary = shap_explainer(sampled_df, feature_set,
                                                classifier)

            st.set_option('deprecation.showPyplotGlobalUse', False)
            st.pyplot(feat_plot)
            print("\n")
            st.pyplot(summary)
            #for plots in dependance_plots:
            #st.pyplot(plots)

    if st.button("Precision Recall Curve For the Classifier You selected"):

        classifier = model_selection(option)
        fig = plot_prec_recall_vs_tresh(sampled_df, feature_set, classifier,
                                        option)
        st.pyplot(fig)

        st.text("")
예제 #24
0
파일: doggo.py 프로젝트: ethanleeman/DogGo
select = st.selectbox(
	'Going out for a walk or to a park or somewhere else?',
	('Going out for a walk', 'Take me to a park', 'Traveling somewhere else'))

if select=='Traveling somewhere else':
	input2 = st.text_input('Where will the walk end?')

dog_df = pd.read_csv('data/dogbreeds.csv')
dogs = dict(zip(dog_df['Name'], zip(dog_df['Exercise-Needs'], dog_df['Height']) ))

temp = st.selectbox(
		'What type of dog do you have?', 
		list(dogs.keys()))

#Initial estimate for duration depends on dog breed
duration = st.number_input('How much time (minutes) do you have for this walk?', step = 5, value = 10 * int(1.2 * dogs[temp][0]))

if duration > 60:
	st.write('This is a long walk! It might take a while to route...')

#Estimate for walking speed depends on dog breed
#Vary by ~20% depending on dog height
walking_rate = set_walking_rate(80 - (15/14)*(14-dogs[temp][1])) #m/min

#If we want to avoid busy streets, we adjust the edge weights later
avoid_busy_streets = st.checkbox('Keep me away from busy streets', value=False, key=1)

submit = st.button('Calculate route - Go!', key=1)
if not submit:
	st.pydeck_chart(pdk.Deck(
		map_style="mapbox://styles/mapbox/light-v9", 
예제 #25
0
def main()  : 
    

    #1. 파일 업로드 하기
    image_file = st.file_uploader('Upload Image', type = ['png', 'jpg', 'jpeg']) 

    if image_file is not None :  # 유저가 입력한 파일이 있으면

        img = load_image(image_file)  # 다운로드한게 이미지파일에 있으면 이미지로 오픈하라
      

        option_list =  [ 'Show Image', 'Rotate Image', 'Creat Thumbnail',
                     'Crop Image', 'Merge Images', 'Flip Image', 'Change color',
                      'Filters - Sharpen', 'Filters - Edge Enhance',
                      'Contrast Image'  ]
                     # 이러한 기능을 하도록 만든다

        option =  st.selectbox('옵션을 선택하세요', option_list)

        if option == 'Show Image' :
            st.image(img)

        elif option == 'Rotate Image' :
            degree =  st.number_input('각도입력', 0,360 )   # 0부터 360까지 정수로 입력받을수 있음
            rotated_img = img.rotate(degree) # 90 도 회전
            img.save('data/rotate.png')
            st.image(rotated_img)                        
    
        elif option == 'Create Thumbnail' :   # 오류
            # 이미지의 사이즈를 알아야겠다.
            print(img.size)  
            #st.write(img.size) # 둘다 똑같음

            width = st.number_input('width 입력', 1, img.size[0] )  # 가로 세로 사이즈가 다르니 이렇게 해야함 
            height =  st.number_input( 'height 입력', 1, img.size[1] )
            size = ( width, height )

    
            img.thumbnail( size )
            img.save('data/thumb.png') 
            st.image(img)                # 원본 사이즈 바꾸고 data에 thumb.png 로 저장했다   (다른것도 가능 )

        elif option == 'Crop Image' :      # 이미지 자를 때
        # 왼쪽 윗부분 부터, 오른쪽 아래 부분 까지 잘라라
        # 왼쪽 윗부분 좌표 ( 50,10 )
        # 너비 x축으로, 깊이 y축으로 계산한 종료좌표(200,200)
        # 시작 좌표 + ( 너비 , 높이 ) =>  크랍 종료 좌표
            start_x = st.number_input('시작 x 좌표', 0, img.size[0]-1 )  # 가로 세로 사이즈가 다르니 이렇게 해야함 
            start_y =  st.number_input( '시작 y 좌표', 0, img.size[1]-1 ) 
            # start_x가 0~0까지 이고 start_y가 0~1 까지 면 이미지를 자를 때 전체다 자를 수도 있으니 예외처리를 한것
            max_width = img.size[0] - start_x
            max_height = img.size[0] - start_y   # 예외처리 한것 
            
            width = st.number_input('width 입력', 1, max_width ) # 너비가 0부터 시작일수는 없으니 1 임
            height =  st.number_input( 'height 입력', 1, max_height )    



            box = ( start_x, start_y, start_x + width, start_y + height )
            st.write(box)  # crop 이미지가 왜 안보여지는 지 확인한다
            cropped_img = img.crop(box)
            # img.save('data/crop.png')
            st.image(cropped_img)


        elif option == 'Merge Image' :  # 두개합치는 것    # 오류 

            merge_file = st.file_uploader('Upload Image', type = ['png', 'jpg', 'jpeg'], key='merge')    
                                                                                 # 위에 업로더 쓴것과 충돌이 일어나지 않게 키를 머지로 한것
           

            if merge_img is not None :
                  # 유저가 입력한 머지 이미지가 있으면      # 오류

                merge_img =  Image.open(merge_file)  # 이미지로 바꿔라 

                start_x = st.number_input('시작 x 좌표', 0, img.size[0]-1 )  # 가로 세로 사이즈가 다르니 이렇게 해야함 
                start_y =  st.number_input( '시작 y 좌표', 0, img.size[1]-1 )

                position =  (start_x, start_y)  # 원래 이미지 안쪽에 추가되는게 들어가게 y축 이 원본이미지 y축보다 작아야함 
                img.paste(merge_img, position)
                st.image(img)

        elif option == 'Flip Image' :   #  이미지 뒤집기    

            status = st.radio('플립 선택', ['FLIP_TOP_BOTTOM', 'FLIP_LEFT_RIGHT'])
            
            if status == 'FLIP_TOP_BOTTOM' :
                flipped_img = img.transpose( Image.FLIP_TOP_BOTTOM )  
            
            elif status == 'FLIP_LEFT_RIGHT' :
                flipped_img = img.transpose( Image.FLIP_LEFT_RIGHT )  
            
            st.image(flipped_img)  # 탑 바텀 이나 왼쪽오른쪽 나오게   # 셀렉트박스 써도됨

        elif option == 'Change Color' :  # 이미지 색상 바꾸기  # 오류

             status = st.radio('색 변경',
            ['Color', 'Gray Scale', 'Black & White'] )
            
            if status == 'Color' :
                color = 'RGB'
            elif status == 'Gray Scale' :
                color = 'L'
            elif status == 'Black & White' :
                color = '1'
            
            bw = img.convert('1')  # "L" 로쓰면 그레이스케일됨
            st.image( bw )

        elif option == 'Filters - Sharpen' :   # 이미지 선명하게
            sharp_img = img.filter(ImageFilter.SHARPEN)
            st.image( sharp_img )

        elif  option == 'Filters - Edge Enhance'  :  # 윤곽선이 진해진다 
            edge_img = img.filter(ImageFilter.EDGE_ENHANCE)
            st.image(edge_img)

        elif option == 'Contrast Image' :        # 대비가 세진다 
            contrast_img = ImageEnhance.Contrast(img).enhance( 2 )
            st.image(contrast_img)    
예제 #26
0
st.header("Have a look at the Top gainers today!")
if st.button("Check Gainers"):
    top_gainers = nse.get_top_gainers(10)
    st.write(top_gainers)

st.header("Have a look at the Top losers today!")
if st.button("Check Losers"):
    top_losers = nse.get_top_losers(5)
    st.write(top_losers)

st.header("Analyze Market")
st.markdown(
    "Enter year, month and date to analyze Forex rates , Market valuation and Market Volatility"
)
sy = int(st.number_input("Enter starting year"))
sm = int(st.number_input("Enter starting  month"))
sd = int(st.number_input("Enter starting  day"))
ey = int(st.number_input("Enter ending year"))
em = int(st.number_input("Enter ending month"))
ed = int(st.number_input("Enter ending date"))
st.header("RBI Currency rates")
st.markdown("USD, GBP, EURO, YEN to INR rbi reference rates")
if st.button("Check Rates"):
    rbi_ref = get_rbi_ref_history(date(sy, sm, sd), date(ey, em, ed))
    st.write(rbi_ref)

st.header("Market Volatility")
st.markdown(
    "India VIX is a volatility index which gives a measurement of market volatility based on NIFTY options contract. This servers as important parameter in option pricing"
)
예제 #27
0
    final_train_time = st.slider(
        "Select the final date for the train",
        min_value=datetime.strptime(df.index[0], '%Y-%m-%d'),
        max_value=datetime.strptime(df.index[-1], '%Y-%m-%d'),
        value=datetime.strptime(df.index[int(df.shape[0] * 0.7)], '%Y-%m-%d'),
        format='YYYY-MM-DD')

    # selected_model = st.selectbox('Select a model to use for forecast', ('SVR', 'Linear Regression', 'MLP', 'XGBoost', 'LSTM',
    #                     'HoltWinters', 'Moving Average'))
    selected_model = st.selectbox(
        'Select a model to use for forecast',
        ('Linear Regression', 'MLP', 'Moving Average'))

    if selected_model == 'Linear Regression':
        lagged_features = st.number_input(
            'How many lagged features do you want to use?', value=1, step=1)
        run = st.button('Run')
        if run:
            lagged_features += 1
            df, features = create_lagged_features(df, lagged_features)
            df_train = df[df.index <= final_train_time.strftime("%Y-%m-%d")]
            df_test = df[df.index > final_train_time.strftime("%Y-%m-%d")]
            X_train = df_train.iloc[lagged_features:][features]
            y_train = df_train.iloc[lagged_features:]['close']
            X_test = df_test[features]
            y_test = df_test['close']

            reg = LinearRegression().fit(X_train, y_train)
            y_pred = reg.predict(X_test)
            st.subheader('RMSE = ' + str(
                round(np.sqrt(mean_squared_error(df_test.close, y_pred)), 6)))
예제 #28
0
def start():
    st.title('Insurance Product Recommender')

    data = pd.read_csv('initial_preprocess.csv')

    AGE_MAX = 44
    AGE_MIN = 18
    DEPENDANT_MAX = 3
    DEPENDANT_MIN = 2
    ANNUAL_MAX = 199918
    ANNUAL_MIN = 48127
    MAX_EXP = 10462
    MIN_EXP = 2514

    html_temp = """
        <div style="background-color:tomato;padding:10px">
        <h2 style="color:white;text-align:center;">Fill in your details and we'll find the best product for you! </h2>
        </div>
        """
    st.markdown(html_temp, unsafe_allow_html=True)
    age = st.number_input("Age")
    if age > AGE_MAX: AGE_MAX = age
    age = (age - AGE_MIN) / (AGE_MAX - AGE_MIN)

    if (age >= 18 and age <= 26):
        ageg = '18-26'
    elif (age > 26 and age <= 36):
        ageg = '27-35'
    else:
        ageg = '36-44'

    gender = st.text_input("Gender", "Type Here")
    if not gender in ['male', 'Male', 'female', 'Female']:
        st.write('either male or female')

    ms = st.text_input("MaritalStatus", "Type Here")
    if not ms in ['single', 'married']:
        st.write('either single or married ')

    ss = st.text_input("SmokerStatus", "Type Here")
    if not ss in ['frequent', 'once_in_a_while', 'sometimes']:
        st.write('either frequent , once_in_a_awhile or sometimes')

    ls = st.text_input("LifeStyle", "Type Here")
    if not ls in ['home', 'outdoor', 'pub_goer']:
        st.write('home , outdoor or pub_goer')

    langS = st.text_input("LanguageSpoken", "Type Here")
    if not langS in ['english', 'malay', 'mandarin']:
        st.write('either english,malay or mandarin ')

    he = st.text_input("HighestEducation", "Type Here")
    if not he in ['Bachelor', 'Diploma', 'Master', 'PhD']:
        st.write('either Bachelors, Diploma, Master or PhD')

    race = st.text_input("Race", "Type Here")
    if not race in ['malay', 'chinese', 'indian', 'others']:
        st.write('either malay , chinese , indian or others ')

    nationality = st.text_input("Nationality", "Type Here")
    if not nationality in ['Malaysian', 'others']:
        st.write('Malaysian or Others ')

    mpr = st.text_input("MalaysiaPR", "Type Here")
    if mpr == 'yes' or mpr == 'Yes':
        mpr = 1
    elif mpr == 'no' or mpr == 'No':
        mpr = 0

    mtnc = st.text_input("MovingToNewCompany", "Type Here")
    if mtnc == 'yes' or mtnc == 'Yes':
        mtnc = 1
    elif mtnc == 'no' or mtnc == 'No':
        mtnc = 0

    occ = st.text_input("Occupation", "Type Here")
    if not occ in [
            'employer', 'selfEmployed', 'privateEemployee', 'govServant'
    ]:
        st.write('either employer,selfEmployed,privateEemployee,govServant ')

    telco = st.text_input("Telco", "Type Here")
    if not telco in ['maxis', 'umobile', 'celcom', 'digi']:
        st.write(
            'A plan that you are using like maxis, celcom, digi or umobile')

    ha = st.text_input("HomeAddress", "Type Here")
    if not ha in ['north_mal', 'east_mal', 'central_mal', 'south_mal']:
        st.write(
            'Which part of malaysia, in short write for example "south_mal"')

    rt = st.text_input("ResidentialType", "Type Here")
    if not rt in ['terrace', 'condominium', 'flat', 'bungalow']:
        st.write('either terrace , condominium , flat or bungalow')

    depend = st.number_input("NoOfDependent")
    if depend > DEPENDANT_MAX: DEPENDANT_MAX = depend
    depend = (depend - DEPENDANT_MIN) / (DEPENDANT_MAX - DEPENDANT_MIN)

    fe = st.number_input("FamilyExpenses(month)")
    if fe > MAX_EXP: fe = MAX_EXP
    fe = (fe - MIN_EXP) / (MAX_EXP - MIN_EXP)

    ass = st.number_input("AnnualSalary")
    save = savings(ass, fe)
    if ass > ANNUAL_MAX: ANNUAL_MAX = ass
    ass = (ass - ANNUAL_MIN) / (ANNUAL_MAX - ANNUAL_MIN)

    cn1 = st.text_input("Customer_Needs_1", "Type Here")
    if not cn1 in ['PersonalSaving', 'PersonalRetirement', 'PersonalMedical']:
        st.write(
            'We have a variety of plans such as PersonalSaving, PersonalRetirement,PersonalMedical just for you'
        )

    cn2 = st.text_input("Customer_Needs_2", "Type Here")
    if not cn2 in ['KidMedical', 'KidSaving', 'KidEducation']:
        st.write(
            'get a plan for your kid, choose from KidMedical,KidSaving or KidEducation '
        )

    t = st.text_input("Transport", "Type Here")
    if not t in ['driving', 'publicTransport']:
        st.write('are you driving or taking publicTransport ')

    mc = st.text_input("MedicalComplication", "Type Here")
    if mc == 'yes' or mc == 'Yes':
        mc = 1
    elif mc == 'no' or mc == 'No':
        mc = 0

    columns = [
        "Age", "AgeGroup", "Gender", "MaritalStatus", "SmokerStatus",
        "LifeStyle", "LanguageSpoken", "HighestEducation", "Race",
        "Nationality", "MalaysiaPR", "MovingToNewCompany", "Occupation",
        "Telco", "HomeAddress", "ResidentialType", "NoOfDependent",
        "FamilyExpenses(month)", "AnnualSalary", "Saving(month)",
        "Customer_Needs_1", "Customer_Needs_2", "Transport",
        "MedicalComplication"
    ]

    df = pd.DataFrame(data=np.array([[
        age, ageg, gender, ms, ss, ls, langS, he, race, nationality, mpr, mtnc,
        occ, telco, ha, rt, depend, fe, ass, save, cn1, cn2, t, mc
    ]]),
                      columns=columns)

    #for continous data
    #performing normalization on Age, AnnualSalary,FamilyExpenses(Month),NoOfDependent

    data['MalaysiaPR'].replace(('yes', 'no'), (1, 0), inplace=True)
    data['MovingToNewCompany'].replace(('yes', 'no'), (1, 0), inplace=True)
    data['MedicalComplication'].replace(('yes', 'no'), (1, 0), inplace=True)

    data_1 = data.copy()
    data_2 = data.copy()
    df_pp1 = adjust_df_pp1(df, data_1)
    #st.write(df_pp1)
    df_pp2 = adjust_df_pp2(df, data_2)
    #st.write(df_pp2)

    if st.button("Predict"):
        try:
            result1 = predict_pp1(df_pp1)
            result2 = predict_pp2(df_pp2)
            st.success('We recommend for your first choice {}'.format(result1))
            st.success(
                'Highly recommended by our customers {}'.format(result2))
        except ValueError:
            st.write('Make sure all the boxes are filled in!')
        except:
            st.write('Something went wrong contact us to find out more.')

    if st.button("About"):
        st.text("Created by the team")
        st.text("Built with Streamlit")
def main():
    """Prediccion Salario con ML"""
    st.title("Prediccion de Salarios")
    activity = [
        "Analisis Exploratorio Datos", "Prediccion", "Metrica", "Paises"
    ]
    choice = st.sidebar.selectbox("Escojer una actividad: ", activity)
    st.sidebar.info("Desarrollado por: Juan Minango y Pablo Minango")
    st.sidebar.markdown(
        "[Juan Minango](https://www.linkedin.com/in/juan-carlos-minango-negrete-4b6106197/)"
    )
    st.sidebar.markdown(
        "[Pablo Minango](https://www.linkedin.com/in/pablo-david-minango-negrete-3b275b141/)"
    )
    st.sidebar.markdown("[JD-Techn](https://jdtechn.com/)")
    #Load File
    df = pd.read_csv("data/adult_salary.csv")

    #ExploringDataAnalize
    if choice == "Analisis Exploratorio Datos":
        st.subheader("Planteamiento del Problema")
        st.write(
            "Ha sido proporcionado un conjunto de datos de salarios que tiene 15 columnas y 48842 filas. Nuestra tarea es analizar el conjunto de datos y predecir si el ingreso de un adulto excederá de 50k ($USD 50.000) por año o no mediante el desarrollo de un modelo supervisado de aprendizaje automático (Machine Learning). Para lo cuál se ha considerado 3 modelos de Machine Learning los cuáles son: Logistic Regression, Naive Bayes y Random Forest."
        )
        st.markdown(
            "[UCI: Base de Datos](https://archive.ics.uci.edu/ml/datasets/Adult)"
        )
        st.markdown(
            "[Teoria: Logistic Regression, Naive Bayes y Random Forest](https://www.amazon.com.br/Hands-Machine-Learning-Scikit-Learn-TensorFlow/dp/1491962291)"
        )
        st.subheader("Seccion Analisis Exploratorio de Datos")
        #Previews
        if st.checkbox("Vista Previa Dataset"):
            number = st.number_input("Numero de Filas a Mostrar: ", value=0)
            st.dataframe(df.head(number))
        #Show Columns/Rows
        if st.button("Nombre de las Columnas"):
            st.write(df.columns)
        #Description
        if st.checkbox("Mostrar Descripcion del DataSet"):
            st.write(df.describe())
        #Shape
        if st.checkbox("Mostrar Dimensiones del DataSet"):
            st.write(df.shape)
            data_dim = st.radio("Mostrar Dimensiones por: ",
                                ("Filas", "Columnas"))
            if data_dim == "Filas":
                st.write("Numero de Filas: ")
                st.write(df.shape[0])
            elif data_dim == "Columnas":
                st.write("Numero de Columnas: ")
                st.write(df.shape[1])
        #Selection Columns
        if st.checkbox("Seleccionar las Columnas a Mostrar"):
            all_columns = df.columns.tolist()
            selected_columns = st.multiselect("Seleccionar las Columnas: ",
                                              all_columns)
            new_df = df[selected_columns]
            st.dataframe(new_df)
        #Selection Filas
        if st.checkbox("Seleccionar las Filas a Mostrar"):
            selected_indices = st.multiselect("Seleccionar las Filas: ",
                                              df.head(11).index)
            selected_rows = df.loc[selected_indices]
            st.dataframe(selected_rows)
        #Value Counts
        if st.button("Conteo Valores"):
            st.text("Conteo de Valores del Target")
            st.write(df.iloc[:, -1].value_counts())
        #Plot
        if st.checkbox("Mostrar Grafico de Correlacion [MatplotLib]"):
            plt.matshow(df.corr())
            st.pyplot()
        if st.checkbox("Mostrar Grafico de Correlacion [SeaBorn]"):
            st.write(sns.heatmap(df.corr(), annot=True))
            st.pyplot()

    #Prediction
    elif choice == "Prediccion":
        st.subheader("Seccion Prediccion")
        #Diccionario
        d_workclass = {
            "Never-worked": 0,
            "Private": 1,
            "Federal-gov": 2,
            "?": 3,
            "Self-emp-inc": 4,
            "State-gov": 5,
            "Local-gov": 6,
            "Without-pay": 7,
            "Self-emp-not-inc": 8
        }
        d_education = {
            "Some-college": 0,
            "10th": 1,
            "Doctorate": 2,
            "1st-4th": 3,
            "12th": 4,
            "Masters": 5,
            "5th-6th": 6,
            "9th": 7,
            "Preschool": 8,
            "HS-grad": 9,
            "Assoc-acdm": 10,
            "Bachelors": 11,
            "Prof-school": 12,
            "Assoc-voc": 13,
            "11th": 14,
            "7th-8th": 15
        }
        d_marital_status = {
            "Separated": 0,
            "Married-spouse-absent": 1,
            "Married-AF-spouse": 2,
            "Married-civ-spouse": 3,
            "Never-married": 4,
            "Widowed": 5,
            "Divorced": 6
        }
        d_occupation = {
            "Tech-support": 0,
            "Farming-fishing": 1,
            "Prof-specialty": 2,
            "Sales": 3,
            "?": 4,
            "Transport-moving": 5,
            "Armed-Forces": 6,
            "Other-service": 7,
            "Handlers-cleaners": 8,
            "Exec-managerial": 9,
            "Adm-clerical": 10,
            "Craft-repair": 11,
            "Machine-op-inspct": 12,
            "Protective-serv": 13,
            "Priv-house-serv": 14
        }
        d_relationship = {
            "Other-relative": 0,
            "Not-in-family": 1,
            "Own-child": 2,
            "Wife": 3,
            "Husband": 4,
            "Unmarried": 5
        }
        d_race = {
            "Amer-Indian-Eskimo": 0,
            "Black": 1,
            "White": 2,
            "Asian-Pac-Islander": 3,
            "Other": 4
        }
        d_sex = {"Female": 0, "Male": 1}
        d_native_country = {
            "Canada": 0,
            "Philippines": 1,
            "Thailand": 2,
            "Scotland": 3,
            "Germany": 4,
            "Portugal": 5,
            "India": 6,
            "China": 7,
            "Japan": 8,
            "Peru": 9,
            "France": 10,
            "Greece": 11,
            "Taiwan": 12,
            "Laos": 13,
            "Hong": 14,
            "El-Salvador": 15,
            "Outlying-US(Guam-USVI-etc)": 16,
            "Yugoslavia": 17,
            "Cambodia": 18,
            "Italy": 19,
            "Honduras": 20,
            "Puerto-Rico": 21,
            "Dominican-Republic": 22,
            "Vietnam": 23,
            "Poland": 24,
            "Hungary": 25,
            "Holand-Netherlands": 26,
            "Ecuador": 27,
            "South": 28,
            "Guatemala": 29,
            "United-States": 30,
            "Nicaragua": 31,
            "Trinadad&Tobago": 32,
            "Cuba": 33,
            "Jamaica": 34,
            "Iran": 35,
            "?": 36,
            "Haiti": 37,
            "Columbia": 38,
            "Mexico": 39,
            "England": 40,
            "Ireland": 41
        }
        d_class = {">50K": 0, "<=50K": 1}
        #ML Aspect User Input
        age = st.slider("Seleccionar Edad", 17, 90)
        workclass = st.selectbox("Seleccionar el tipo de Trabajo",
                                 tuple(d_workclass.keys()))
        fnlwgt = st.number_input("Enter FNLWGT", 1.228500e+04, 1.484705e+06)
        education = st.selectbox("Seleccionar tu Educacion",
                                 tuple(d_education.keys()))
        education_num = st.slider("Selecciona tu Nivel de Educacion", 1, 16)
        marital_status = st.selectbox("Selecciona Estado Civil",
                                      tuple(d_marital_status.keys()))
        occupation = st.selectbox("Selecciona Ocupacion",
                                  tuple(d_occupation.keys()))
        relationship = st.selectbox("Selecciona Relacionamiento",
                                    tuple(d_relationship.keys()))
        race = st.selectbox("Selecciona Raza", tuple(d_race.keys()))
        sex = st.radio("Selecciona Sexo", tuple(d_sex.keys()))
        capital_gain = st.number_input("Ganancia Capital", 0, 9999, value=0)
        capital_loss = st.number_input("Perdida Capital", 0, 4356, value=0)
        hours_per_week = st.number_input("Horas por Semana", 1, 99, value=1)
        native_country = st.selectbox("Selecciona Pais de Origen",
                                      tuple(d_native_country.keys()))
        #User Input
        k_workclass = get_value(workclass, d_workclass)
        k_education = get_value(education, d_education)
        k_marital_status = get_value(marital_status, d_marital_status)
        k_occupation = get_value(occupation, d_occupation)
        k_relationship = get_value(relationship, d_relationship)
        k_race = get_value(race, d_race)
        k_sex = get_value(sex, d_sex)
        k_native_country = get_value(native_country, d_native_country)
        #Result of User Input
        selected_options = [
            age, workclass, fnlwgt, education, education_num, marital_status,
            occupation, relationship, race, sex, capital_gain, capital_loss,
            hours_per_week, native_country
        ]
        vectorized_result = [
            age, k_workclass, fnlwgt, k_education, education_num,
            k_marital_status, k_occupation, k_relationship, k_race, k_sex,
            capital_gain, capital_loss, hours_per_week, k_native_country
        ]
        st.success(vectorized_result)
        st.subheader("Informacion Ingresada en Formato Lista")
        #Formato Lista
        st.info(selected_options)
        sample_data = np.array(vectorized_result).reshape(1, -1)
        #Formato JSON
        st.subheader("Informacion Ingresada en Formato JSON")
        prettified_result = {
            "age": age,
            "workclass": workclass,
            "fnlwgt": fnlwgt,
            "education": education,
            "education_num": education_num,
            "marital_status": marital_status,
            "occupation": occupation,
            "relationship": relationship,
            "race": race,
            "sex": sex,
            "capital_gain": capital_gain,
            "capital_loss": capital_loss,
            "hours_per_week": hours_per_week,
            "native_country": native_country
        }
        st.json(prettified_result)
        #Formato Numerico
        st.subheader("Informacion Ingresada en Formato Numerico")
        st.write(vectorized_result)
        #MAke Prediction
        st.header("Seccion ML para Prediccion")
        if st.checkbox("Realizar Prediccion"):
            all_ml_lists = ["LOGISTIC REGRESSION", "RFOREST", "NAIVE BAYES"]
            #Seleccion Modelo ML
            model_choice = st.selectbox("Escoje el Modelo ML: ", all_ml_lists)
            st.text("Usando la siguiente codificacion para prediccion: ")
            prediction_label = {">50k": 0, "<=50k": 1}
            st.write(prediction_label)
            if st.button("Predecir"):
                if model_choice == "LOGISTIC REGRESSION":
                    model_predictor = load_prediction_models(
                        "models/salary_logit_model_juan.pkl")
                    prediction = model_predictor.predict(sample_data)
                    st.text("Prediccion con ML Logistic Regression")
                    st.write(prediction)
                    if prediction == 1:
                        st.success("Salario es: <=50k ")
                    elif prediction == 0:
                        st.success("Salario es: >50k ")
                elif model_choice == "RFOREST":
                    model_predictor = load_prediction_models(
                        "models/salary_rf_model_juan.pkl")
                    prediction = model_predictor.predict(sample_data)
                    st.text("Prediccion con ML Random Forest")
                    st.write(prediction)
                    if prediction == 1:
                        st.success("Salario es: <=50k ")
                    elif prediction == 0:
                        st.success("Salario es: >50k ")
                elif model_choice == "NAIVE BAYES":
                    model_predictor = load_prediction_models(
                        "models/salary_nv_model_juan.pkl")
                    prediction = model_predictor.predict(sample_data)
                    st.text("Prediccion con ML Naive Bayes")
                    st.write(prediction)
                    if prediction == 1:
                        st.success("Salario es: <=50k ")
                    elif prediction == 0:
                        st.success("Salario es: >50k ")
                final_result = get_keys(prediction, prediction_label)
                model_class = model_choice
                time_prediction = datetime.datetime.now()
                monitor = Monitor(age, workclass, fnlwgt, education,
                                  education_num, marital_status, occupation,
                                  relationship, race, sex, capital_gain,
                                  capital_loss, hours_per_week, native_country,
                                  final_result, model_class)
                monitor.create_table()
                monitor.add_data()
                #st.success("Salario Predecido como :: {}".format(final_result))

    # Countries
    elif choice == "Paises":
        st.subheader("Seccion Paises")
        #List of Countries
        d_native_country = {
            "Canada": 0,
            "Philippines": 1,
            "Thailand": 2,
            "Scotland": 3,
            "Germany": 4,
            "Portugal": 5,
            "India": 6,
            "China": 7,
            "Japan": 8,
            "Peru": 9,
            "France": 10,
            "Greece": 11,
            "Taiwan": 12,
            "Laos": 13,
            "Hong": 14,
            "El-Salvador": 15,
            "Outlying-US(Guam-USVI-etc)": 16,
            "Yugoslavia": 17,
            "Cambodia": 18,
            "Italy": 19,
            "Honduras": 20,
            "Puerto-Rico": 21,
            "Dominican-Republic": 22,
            "Vietnam": 23,
            "Poland": 24,
            "Hungary": 25,
            "Holand-Netherlands": 26,
            "Ecuador": 27,
            "South": 28,
            "Guatemala": 29,
            "United-States": 30,
            "Nicaragua": 31,
            "Trinadad&Tobago": 32,
            "Cuba": 33,
            "Jamaica": 34,
            "Iran": 35,
            "?": 36,
            "Haiti": 37,
            "Columbia": 38,
            "Mexico": 39,
            "England": 40,
            "Ireland": 41
        }
        selected_countries = st.selectbox("Escojer un Pais",
                                          tuple(d_native_country.keys()))
        #Selection Countries
        st.text(selected_countries)
        df2 = pd.read_csv("data/adult_salary_data.csv")
        result_df = df2[df2['native-country'].str.contains(selected_countries)]
        st.dataframe(result_df.head(10))
        countries_images = {
            'af': 'Afghanistan',
            'al': 'Albania',
            'dz': 'Algeria',
            'as': 'American Samoa',
            'ad': 'Andorra',
            'ao': 'Angola',
            'ai': 'Anguilla',
            'aq': 'Antarctica',
            'ag': 'Antigua And Barbuda',
            'ar': 'Argentina',
            'am': 'Armenia',
            'aw': 'Aruba',
            'au': 'Australia',
            'at': 'Austria',
            'az': 'Azerbaijan',
            'bs': 'Bahamas',
            'bh': 'Bahrain',
            'bd': 'Bangladesh',
            'bb': 'Barbados',
            'by': 'Belarus',
            'be': 'Belgium',
            'bz': 'Belize',
            'bj': 'Benin',
            'bm': 'Bermuda',
            'bt': 'Bhutan',
            'bo': 'Olivia',
            'ba': 'Bosnia And Herzegovina',
            'bw': 'Botswana',
            'bv': 'Bouvet Island',
            'br': 'Brazil',
            'io': 'British Indian Ocean Territory',
            'bn': 'Brunei Darussalam',
            'bg': 'Bulgaria',
            'bf': 'Burkina Faso',
            'bi': 'Burundi',
            'kh': 'Cambodia',
            'cm': 'Cameroon',
            'ca': 'Canada',
            'cv': 'Cape Verde',
            'ky': 'Cayman Islands',
            'cf': 'Central African Republic',
            'td': 'Chad',
            'cl': 'Chile',
            'cn': "People'S Republic Of China",
            'cx': 'Hristmas Island',
            'cc': 'Cocos (Keeling) Islands',
            'co': 'Colombia',
            'km': 'Comoros',
            'cg': 'Congo',
            'cd': 'Congo, The Democratic Republic Of',
            'ck': 'Cook Islands',
            'cr': 'Costa Rica',
            'ci': "Côte D'Ivoire",
            'hr': 'Croatia',
            'cu': 'Cuba',
            'cy': 'Cyprus',
            'cz': 'Czech Republic',
            'dk': 'Denmark',
            'dj': 'Djibouti',
            'dm': 'Dominica',
            'do': 'Dominican Republic',
            'ec': 'Ecuador',
            'eg': 'Egypt',
            'eh': 'Western Sahara',
            'sv': 'El Salvador',
            'gq': 'Equatorial Guinea',
            'er': 'Eritrea',
            'ee': 'Estonia',
            'et': 'Ethiopia',
            'fk': 'Falkland Islands (Malvinas)',
            'fo': 'Aroe Islands',
            'fj': 'Fiji',
            'fi': 'Finland',
            'fr': 'France',
            'gf': 'French Guiana',
            'pf': 'French Polynesia',
            'tf': 'French Southern Territories',
            'ga': 'Gabon',
            'gm': 'Gambia',
            'ge': 'Georgia',
            'de': 'Germany',
            'gh': 'Ghana',
            'gi': 'Gibraltar',
            'gr': 'Greece',
            'gl': 'Greenland',
            'gd': 'Grenada',
            'gp': 'Guadeloupe',
            'gu': 'Guam',
            'gt': 'Guatemala',
            'gn': 'Guinea',
            'gw': 'Guinea-Bissau',
            'gy': 'Guyana',
            'ht': 'Haiti',
            'hm': 'Heard Island And Mcdonald Islands',
            'hn': 'Honduras',
            'hk': 'Hong Kong',
            'hu': 'Hungary',
            'is': 'Iceland',
            'in': 'India',
            'id': 'Indonesia',
            'ir': 'Iran, Islamic Republic Of',
            'iq': 'Iraq',
            'ie': 'Ireland',
            'il': 'Israel',
            'it': 'Italy',
            'jm': 'Jamaica',
            'jp': 'Japan',
            'jo': 'Jordan',
            'kz': 'Kazakhstan',
            'ke': 'Kenya',
            'ki': 'Kiribati',
            'kp': "Korea, Democratic People'S Republic Of",
            'kr': 'Korea, Republic Of',
            'kw': 'Kuwait',
            'kg': 'Kyrgyzstan',
            'la': "Lao People'S Democratic Republic",
            'lv': 'Latvia',
            'lb': 'Lebanon',
            'ls': 'Lesotho',
            'lr': 'Liberia',
            'ly': 'Libyan Arab Jamahiriya',
            'li': 'Liechtenstein',
            'lt': 'Lithuania',
            'lu': 'Luxembourg',
            'mo': 'Macao',
            'mk': 'Macedonia, The Former Yugoslav Republic Of',
            'mg': 'Madagascar',
            'mw': 'Malawi',
            'my': 'Malaysia',
            'mv': 'Maldives',
            'ml': 'Mali',
            'mt': 'Malta',
            'mh': 'Marshall Islands',
            'mq': 'Martinique',
            'mr': 'Mauritania',
            'mu': 'Mauritius',
            'yt': 'Mayotte',
            'mx': 'Mexico',
            'fm': 'Micronesia, Federated States Of',
            'md': 'Moldova, Republic Of',
            'mc': 'Monaco',
            'mn': 'Mongolia',
            'ms': 'Montserrat',
            'ma': 'Morocco',
            'mz': 'Mozambique',
            'mm': 'Myanmar',
            'na': 'Namibia',
            'nr': 'Nauru',
            'np': 'Nepal',
            'nl': 'Netherlands',
            'an': 'Netherlands Antilles',
            'nc': 'New Caledonia',
            'nz': 'New Zealand',
            'ni': 'Nicaragua',
            'ne': 'Niger',
            'ng': 'Nigeria',
            'nu': 'Niue',
            'nf': 'Norfolk Island',
            'mp': 'Northern Mariana Islands',
            'no': 'Norway',
            'om': 'Oman',
            'pk': 'Pakistan',
            'pw': 'Palau',
            'ps': 'Palestinian Territory, Occupied',
            'pa': 'Panama',
            'pg': 'Papua New Guinea',
            'py': 'Paraguay',
            'pe': 'Peru',
            'ph': 'Philippines',
            'pn': 'Pitcairn',
            'pl': 'Poland',
            'pt': 'Portugal',
            'pr': 'Puerto Rico',
            'qa': 'Qatar',
            're': 'Réunion',
            'ro': 'Romania',
            'ru': 'Russian Federation',
            'rw': 'Rwanda',
            'sh': 'Saint Helena',
            'kn': 'Saint Kitts And Nevis',
            'lc': 'Saint Lucia',
            'pm': 'Saint Pierre And Miquelon',
            'vc': 'Saint Vincent And The Grenadines',
            'ws': 'Samoa',
            'sm': 'San Marino',
            'st': 'Sao Tome And Principe',
            'sa': 'Saudi Arabia',
            'sn': 'Senegal',
            'cs': 'Serbia And Montenegro',
            'sc': 'Seychelles',
            'sl': 'Sierra Leone',
            'sg': 'Singapore',
            'sk': 'Slovakia',
            'si': 'Slovenia',
            'sb': 'Solomon Islands',
            'so': 'Somalia',
            'za': 'South Africa',
            'gs': 'South Georgia And South Sandwich Islands',
            'es': 'Spain',
            'lk': 'Sri Lanka',
            'sd': 'Sudan',
            'sr': 'Suriname',
            'sj': 'Svalbard And Jan Mayen',
            'sz': 'Swaziland',
            'se': 'Sweden',
            'ch': 'Switzerland',
            'sy': 'Syrian Arab Republic',
            'tw': 'Taiwan, Republic Of China',
            'tj': 'Tajikistan',
            'tz': 'Tanzania, United Republic Of',
            'th': 'Thailand',
            'tl': 'Timor-Leste',
            'tg': 'Togo',
            'tk': 'Tokelau',
            'to': 'Tonga',
            'tt': 'Trinidad And Tobago',
            'tn': 'Tunisia',
            'tr': 'Turkey',
            'tm': 'Turkmenistan',
            'tc': 'Turks And Caicos Islands',
            'tv': 'Tuvalu',
            'ug': 'Uganda',
            'ua': 'Ukraine',
            'ae': 'United Arab Emirates',
            'gb': 'United Kingdom',
            'us': 'United States',
            'um': 'United States Minor Outlying Islands',
            'uy': 'Uruguay',
            'uz': 'Uzbekistan',
            've': 'Venezuela',
            'vu': 'Vanuatu',
            'vn': 'Viet Nam',
            'vg': 'British Virgin Islands',
            'vi': 'U.S. Virgin Islands',
            'wf': 'Wallis And Futuna',
            'ye': 'Yemen',
            'zw': 'Zimbabwe'
        }

        for k, v in countries_images.items():
            if v == selected_countries:
                temp_images = 'cflags/{}.png'.format(k)
                st.text(temp_images)
                img = Image.open(os.path.join(temp_images)).convert('RGB')
                st.image(img)

        if st.checkbox("Selecciona las Columnas a Mostrar"):
            result_df_columns_list = result_df.columns.tolist()
            selected_columns_countries = st.multiselect(
                "Selecciona las columnas", result_df_columns_list)
            new_df2 = df[selected_columns_countries]
            st.dataframe(new_df2.head(10))

            if st.button("Grafico del Pais"):
                st.area_chart(new_df2)
                st.pyplot()

    #Metrics
    elif choice == "Metrica":
        st.subheader("Seccion Metrica")
        cnx = sqlite3.connect('data.db')
        mdf = pd.read_sql_query("SELECT * FROM predictiontable", cnx)
        st.dataframe(mdf)
예제 #30
0
    def test_default_step_when_a_value_is_int(self):
        st.number_input("the label", value=10)

        c = self.get_delta_from_queue().new_element.number_input
        self.assertEqual(c.step, 1.0)