YoneSlapWind80085 commited on
Commit
154b2d9
·
verified ·
1 Parent(s): e75eb9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -184,8 +184,7 @@ st.sidebar.header('User Input Features')
184
  selected_feature = st.sidebar.selectbox('Select feature for visualization', df.columns)
185
  selected_target = st.sidebar.selectbox('Select target variable', df.columns)
186
 
187
- # Display the raw data if checkbox is selected
188
- if st.checkbox('Show raw data'):
189
  st.write(df)
190
 
191
  # Visualization of selected feature
@@ -201,17 +200,7 @@ ax.scatter(df[selected_feature], df[selected_target], alpha=0.3)
201
  ax.set_xlabel(selected_feature)
202
  ax.set_ylabel(selected_target)
203
 
204
- # Show regression line if selected
205
- show_regression = st.checkbox('Show Regression Line')
206
- if show_regression and selected_feature in df.columns and selected_target == 'MedHouseVal':
207
- X_feature = df[[selected_feature]]
208
- y = df[selected_target]
209
- model_feature = LinearRegression()
210
- model_feature.fit(X_feature, y)
211
- line = model_feature.predict(X_feature)
212
- ax.plot(df[selected_feature], line, color='red', linewidth=2)
213
 
214
- st.pyplot(fig)
215
 
216
  # Simple Linear Regression
217
  X_single = df[['MedInc']]
@@ -249,6 +238,18 @@ y_pred_multi = model_multi.predict(X_test_multi)
249
 
250
  r2_multi = r2_score(y_test_multi, y_pred_multi)
251
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  # Add checkbox for multilinear regression plot
253
  show_multilinear_plot = st.checkbox('Show Multilinear Regression Plot')
254
 
 
184
  selected_feature = st.sidebar.selectbox('Select feature for visualization', df.columns)
185
  selected_target = st.sidebar.selectbox('Select target variable', df.columns)
186
 
187
+
 
188
  st.write(df)
189
 
190
  # Visualization of selected feature
 
200
  ax.set_xlabel(selected_feature)
201
  ax.set_ylabel(selected_target)
202
 
 
 
 
 
 
 
 
 
 
203
 
 
204
 
205
  # Simple Linear Regression
206
  X_single = df[['MedInc']]
 
238
 
239
  r2_multi = r2_score(y_test_multi, y_pred_multi)
240
 
241
+ # Show regression line if selected
242
+ show_regression = st.checkbox('Show Regression Line')
243
+ if show_regression and selected_feature in df.columns and selected_target == 'MedHouseVal':
244
+ X_feature = df[[selected_feature]]
245
+ y = df[selected_target]
246
+ model_feature = LinearRegression()
247
+ model_feature.fit(X_feature, y)
248
+ line = model_feature.predict(X_feature)
249
+ ax.plot(df[selected_feature], line, color='red', linewidth=2)
250
+
251
+ st.pyplot(fig)
252
+
253
  # Add checkbox for multilinear regression plot
254
  show_multilinear_plot = st.checkbox('Show Multilinear Regression Plot')
255