Hem345 commited on
Commit
e163a30
·
verified ·
1 Parent(s): 01cbebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
  from sklearn.linear_model import LinearRegression
 
4
 
5
  # Define a function for linear regression
6
  def perform_linear_regression(X, Y):
@@ -34,8 +35,26 @@ if len(x_values) == 3 and len(y_values) == 3:
34
  slope = round(slope, 2)
35
  intercept = round(intercept, 2)
36
 
37
- # Display the results with custom styling
38
- st.markdown(f"<span style='font-family: Times New Roman; font-size: 16px; color: blue;'>Slope: {slope}</span>", unsafe_allow_html=True)
39
- st.markdown(f"<span style='font-family: Times New Roman; font-size: 16px; color: blue;'>Intercept: {intercept}</span>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  else:
41
  st.write("Please provide 3 values for both vectors X and Y.")
 
1
  import streamlit as st
2
  import numpy as np
3
  from sklearn.linear_model import LinearRegression
4
+ import matplotlib.pyplot as plt
5
 
6
  # Define a function for linear regression
7
  def perform_linear_regression(X, Y):
 
35
  slope = round(slope, 2)
36
  intercept = round(intercept, 2)
37
 
38
+ # Create a scatter plot of the data points
39
+ plt.figure(figsize=(8, 6))
40
+ plt.scatter(x_values, y_values, color='red', label='Data Points')
41
+
42
+ # Plot the regression line
43
+ x_range = np.linspace(min(x_values), max(x_values), 100)
44
+ y_range = slope * x_range + intercept
45
+ plt.plot(x_range, y_range, color='blue', label='Regression Line')
46
+
47
+ # Add labels for slope and intercept
48
+ plt.text(min(x_values), min(y_range), f"Slope: {slope}", fontsize=12, color='blue')
49
+ plt.text(min(x_values), min(y_range) - 0.5, f"Intercept: {intercept}", fontsize=12, color='blue')
50
+
51
+ plt.xlabel("X")
52
+ plt.ylabel("Y")
53
+ plt.legend()
54
+ plt.title("Linear Regression Visualization")
55
+
56
+ # Display the plot using Streamlit's pyplot function
57
+ st.pyplot(plt)
58
+
59
  else:
60
  st.write("Please provide 3 values for both vectors X and Y.")