当前位置: 首页>>代码示例>>Python>>正文


Python streamlit.pyplot方法代码示例

本文整理汇总了Python中streamlit.pyplot方法的典型用法代码示例。如果您正苦于以下问题:Python streamlit.pyplot方法的具体用法?Python streamlit.pyplot怎么用?Python streamlit.pyplot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在streamlit的用法示例。


在下文中一共展示了streamlit.pyplot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_dist

# 需要导入模块: import streamlit [as 别名]
# 或者: from streamlit import pyplot [as 别名]
def plot_dist(alpha_value: float, beta_value: float, data: np.ndarray = None):
    beta_dist = beta(alpha_value, beta_value)

    xs = np.linspace(0, 1, 1000)
    ys = beta_dist.pdf(xs)

    fig, ax = plt.subplots(figsize=(7, 3))
    ax.plot(xs, ys)
    ax.set_xlim(0, 1)
    ax.set_xlabel("x")
    ax.set_ylabel("P(x)")

    if data is not None:
        likelihoods = beta_dist.pdf(data)
        sum_log_likelihoods = np.sum(beta_dist.logpdf(data))
        ax.vlines(data, ymin=0, ymax=likelihoods)
        ax.scatter(data, likelihoods, color="black")
        st.write(
            f"""
_Under your alpha={alpha_slider:.2f} and beta={beta_slider:.2f},
the sum of log likelihoods is {sum_log_likelihoods:.2f}_
"""
        )
    st.pyplot(fig) 
开发者ID:ericmjl,项目名称:minimal-streamlit-example,代码行数:26,代码来源:beta_distribution.py

示例2: decompose_series

# 需要导入模块: import streamlit [as 别名]
# 或者: from streamlit import pyplot [as 别名]
def decompose_series(ts):
    '''
    This function applies a seasonal decomposition to a time series. It will generate a season plot, a trending plot, and, finally, a resid plot

    Args.
        ts (Pandas Series): a time series to be decomposed
    '''
    fig = plt.Figure(figsize=(12,7))
    ax1 = plt.subplot(311)
    ax2 = plt.subplot(312)
    ax3 = plt.subplot(313)

    try:
        decomposition = seasonal_decompose(ts)

    except AttributeError:
        error_message = '''
                        Seems that your DATE column is not in a proper format. 
                        Be sure that it\'s in a valid format for a Pandas to_datetime function.
                        '''
        raise AttributeError(error_message)

    decomposition.seasonal.plot(color='green', ax=ax1, title='Seasonality')
    plt.legend('')
    #plt.title('Seasonality')
    #st.pyplot()

    decomposition.trend.plot(color='green', ax=ax2, title='Trending')
    plt.legend('')
    #plt.title('Trending')
    #st.pyplot()
    
    decomposition.resid.plot(color='green', ax=ax3, title='Resid')
    plt.legend('')
    #plt.title('Resid')
    plt.subplots_adjust(hspace=1)
    st.pyplot() 
开发者ID:paulozip,项目名称:arauto,代码行数:39,代码来源:decompose_series.py

示例3: predict_set

# 需要导入模块: import streamlit [as 别名]
# 或者: from streamlit import pyplot [as 别名]
def predict_set(timeseries, y, seasonality, transformation_function, model, exog_variables=None,forecast=False, show_train_prediction=None, show_test_prediction=None):
    '''
    Predicts the in-sample train observations

    Args.
        timeseries (Pandas Series): a time series that was used to fit a model
        y (str): the target column
        seasonality (int): the seasonality frequency
        transformation_function (func): a function used to transform the target values
        model (Statsmodel object): a fitted model
        exog_variables (Pandas DataFrame): exogenous (independent) variables of your model
        forecast (bool): wether or not forecast the test set
        show_train_prediction (bool): wether or not to plot the train set predictions
        show_test_prediction (bool): wether or not to plot the test set predictions
    '''
    timeseries = timeseries.to_frame()
    timeseries[y] = transformation_function(timeseries[y])

    if forecast:
        timeseries['ŷ'] = transformation_function(model.forecast(len(timeseries), exog=exog_variables))
    else:
        timeseries['ŷ'] = transformation_function(model.predict())
    
    if show_train_prediction and forecast == False:
        timeseries[[y, 'ŷ']].iloc[-(seasonality*3):].plot(color=['green', 'red'])

        plt.ylabel(y)
        plt.xlabel('')
        plt.title('Train set predictions')
        st.pyplot()
    elif show_test_prediction and forecast:
        timeseries[[y, 'ŷ']].iloc[-(seasonality*3):].plot(color=['green', 'red'])

        plt.ylabel(y)
        plt.xlabel('')
        plt.title('Test set predictions')
        st.pyplot()

    try:
        rmse = sqrt(mean_squared_error(timeseries[y].iloc[-(seasonality*3):], timeseries['ŷ'].iloc[-(seasonality*3):]))
        aic = model.aic
        bic = model.bic
        hqic = model.hqic
        mape = np.round(mean_abs_pct_error(timeseries[y].iloc[-(seasonality*3):], timeseries['ŷ'].iloc[-(seasonality*3):]), 2)
        mae = np.round(mean_absolute_error(timeseries[y].iloc[-(seasonality*3):], timeseries['ŷ'].iloc[-(seasonality*3):]), 2)
    except ValueError:
        error_message = '''
                        There was a problem while we calculated the model metrics. 
                        Usually this is due a problem with the format of the DATE column. 
                        Be sure it is in a valid format for Pandas to_datetime function
                        '''
        raise ValueError(error_message)
    
    metrics_df = pd.DataFrame(data=[rmse, aic, bic, hqic, mape, mae], columns = ['{} SET METRICS'.format('TEST' if forecast else 'TRAIN')], index = ['RMSE', 'AIC', 'BIC', 'HQIC', 'MAPE', 'MAE'])
    st.markdown('### **Metrics**')
    st.dataframe(metrics_df) 
开发者ID:paulozip,项目名称:arauto,代码行数:58,代码来源:predict_set.py


注:本文中的streamlit.pyplot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。