Python streamlit.pyplot() Examples
The following are 3
code examples of streamlit.pyplot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
streamlit
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: beta_distribution.py From minimal-streamlit-example with MIT License | 6 votes |
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)
Example #2
Source File: decompose_series.py From arauto with Apache License 2.0 | 5 votes |
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()
Example #3
Source File: predict_set.py From arauto with Apache License 2.0 | 4 votes |
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)