-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.txt
39 lines (32 loc) · 1.37 KB
/
a.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pandas as pd
import numpy as np
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
# Load the concrete data
url = 'https://cocl.us/concrete_data'
data = pd.read_csv(url)
# Prepare the data
X = data.drop('Strength', axis=1) # Features
y = data['Strength'] # Target variable (concrete strength)
# --- A. Baseline Model ---
# Function to build and evaluate the baseline model
def build_and_evaluate_model():
model = Sequential()
model.add(Dense(10, activation='relu', input_shape=(X.shape[1],)))
model.add(Dense(1, activation='linear')) # Output layer for regression
model.compile(optimizer='adam', loss='mean_squared_error')
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
model.fit(X_train, y_train, epochs=50, verbose=0) # Suppress training output for clarity
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
return mse
# Repeat the experiment 50 times
mse_values = [build_and_evaluate_model() for _ in range(50)]
# Report the results
mean_mse = np.mean(mse_values)
std_dev_mse = np.std(mse_values)
print(f"Mean MSE: {mean_mse:.2f}")
print(f"Standard Deviation of MSE: {std_dev_mse:.2f}")