Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))1234567891011121314151617181920212223242526272829303132333435363738394041424344import streamlit as stimport pandas as pdimport matplotlib.pyplot as pltfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import r2_scorest.title("📈 Simple Linear Regression App")st.write("Upload a CSV file and perform linear regression.")# Upload CSVuploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])if uploaded_file is not None:df = pd.read_csv(uploaded_file)st.subheader("Data Preview")st.dataframe(df.head())# Select columnscolumns = df.columns.tolist()x_col = st.selectbox("Select feature (X)", columns)y_col = st.selectbox("Select target (y)", columns)if x_col != y_col:X = df[[x_col]]y = df[y_col]# Train modelmodel = LinearRegression()model.fit(X, y)# Predictionsy_pred = model.predict(X)# Resultsst.subheader("Model Results")st.write(f"**Coefficient:** {model.coef_[0]:.4f}")st.write(f"**Intercept:** {model.intercept_:.4f}")st.write(f"**R² Score:** {r2_score(y, y_pred):.4f}")# Plotst.subheader("Regression Plot")
src/streamlit_app.py+42-38