當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。