Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ from sklearn.preprocessing import StandardScaler
|
|
7 |
from sklearn.linear_model import LinearRegression
|
8 |
from sklearn.metrics import mean_squared_error, r2_score
|
9 |
|
|
|
|
|
10 |
# Load the California Housing dataset
|
11 |
data = fetch_california_housing(as_frame=True)
|
12 |
X = data.data
|
@@ -15,24 +17,33 @@ y = data.target
|
|
15 |
# Split the dataset into training and test sets
|
16 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
17 |
|
|
|
18 |
# Standardize features
|
19 |
scaler = StandardScaler()
|
20 |
X_train = scaler.fit_transform(X_train)
|
21 |
X_test = scaler.transform(X_test)
|
22 |
|
|
|
23 |
# Train the model
|
24 |
model = LinearRegression()
|
25 |
model.fit(X_train, y_train)
|
26 |
|
|
|
27 |
# Make predictions on the test set
|
28 |
y_pred = model.predict(X_test)
|
29 |
|
|
|
30 |
# Evaluate the model
|
31 |
mse = mean_squared_error(y_test, y_pred)
|
32 |
r2 = r2_score(y_test, y_pred)
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
38 |
|
|
|
7 |
from sklearn.linear_model import LinearRegression
|
8 |
from sklearn.metrics import mean_squared_error, r2_score
|
9 |
|
10 |
+
st.write("begin of house prediction")
|
11 |
+
st.write("load dataset")
|
12 |
# Load the California Housing dataset
|
13 |
data = fetch_california_housing(as_frame=True)
|
14 |
X = data.data
|
|
|
17 |
# Split the dataset into training and test sets
|
18 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
19 |
|
20 |
+
st.write("standardize")
|
21 |
# Standardize features
|
22 |
scaler = StandardScaler()
|
23 |
X_train = scaler.fit_transform(X_train)
|
24 |
X_test = scaler.transform(X_test)
|
25 |
|
26 |
+
st.write("train")
|
27 |
# Train the model
|
28 |
model = LinearRegression()
|
29 |
model.fit(X_train, y_train)
|
30 |
|
31 |
+
st.write("make predictions")
|
32 |
# Make predictions on the test set
|
33 |
y_pred = model.predict(X_test)
|
34 |
|
35 |
+
st.write("evaluate")
|
36 |
# Evaluate the model
|
37 |
mse = mean_squared_error(y_test, y_pred)
|
38 |
r2 = r2_score(y_test, y_pred)
|
39 |
|
40 |
+
st.write(f"Mean Squared Error: {mse:.2f}")
|
41 |
+
st.write(f"R-squared Score: {r2:.2f}")
|
42 |
+
|
43 |
+
# print(f"Mean Squared Error: {mse:.2f}")
|
44 |
+
# print(f"R-squared Score: {r2:.2f}")
|
45 |
+
|
46 |
+
st.write("end of house prediction")
|
47 |
|
48 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
49 |
|