Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|