File size: 5,850 Bytes
1893393 0d4e0c3 1893393 db00c81 0515eda db00c81 0515eda db00c81 f0b4e7a c510b99 f0b4e7a 5dd8ac6 1893393 facee97 af8cdca 517dfeb af8cdca 517dfeb af8cdca 517dfeb af8cdca 517dfeb af8cdca 517dfeb af8cdca 517dfeb f00a83b 2b337bb 3aca181 2b337bb f00a83b 8680283 facee97 a100343 f1a0cad 8680283 2b337bb 8680283 c81b385 facee97 c81b385 2433312 517dfeb facee97 517dfeb f00a83b 3aca181 f00a83b 3aca181 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
import streamlit as st
import numpy as np
import pickle
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
import joblib
import pandas as pd
def load_data():
X_train = pd.read_csv('preprocessed_slump.csv').values[:,:-1]
# X_train = df.iloc[:,:-1]
y_train = pd.read_csv('preprocessed_slump.csv').values[:, -1]
# y_train = df.iloc[:, -1]
print("X_train",X_train.shape)
print("y_train",y_train.shape)
return X_train, y_train
def load_model_artifacts():
with open('slump_regressor.pkl', 'rb') as f:
regressor = pickle.load(f)
with open('scaler.pkl', 'rb') as f:
scaler = pickle.load(f)
with open('pca.pkl', 'rb') as f:
pca = pickle.load(f)
return regressor, scaler, pca
def save_model_artifacts(regressor, scaler, pca):
with open('slump_regressor.pkl', 'wb') as f:
pickle.dump(regressor, f, protocol=pickle.HIGHEST_PROTOCOL)
with open('scaler.pkl', 'wb') as f:
pickle.dump(scaler, f, protocol=pickle.HIGHEST_PROTOCOL)
with open('pca.pkl', 'wb') as f:
pickle.dump(pca, f, protocol=pickle.HIGHEST_PROTOCOL)
# def preprocess_data(X):
# print('preprocess_data X',X)
# # Load the trained scaler and PCA
# scaler = joblib.load('scaler.pkl')
# pca = joblib.load('pca.pkl')
# # Check if the input has 8 features
# if X.shape[1] != 8:
# raise ValueError("Input data should have 8 features.")
# # Scale the input data using the loaded scaler
# X_scaled = scaler.transform(X)
# print("X_scaled",X_scaled)
# # Apply PCA using the loaded PCA transformer
# # X_pca = pca.transform(X_scaled) somehow dapat 4
# # print("X_pca",X_pca)
# return X_pca
def predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW):
# Prepare the input data
X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW]])
# Preprocess the data
# X_preprocessed = preprocess_data(X)
# print("predict_slump X",X)
# print("predict_slump X_preprocessed",X_preprocessed)
# Load the trained model
regressor = joblib.load('slump_regressor.pkl')
# Make the prediction
slump_prediction = regressor.predict(X)[0]
return slump_prediction
def main():
st.set_page_config(page_title="Concrete Slump Strength Prediction")
st.title("Concrete Slump Strength Prediction")
st.write("Enter the concrete mix parameters to predict the slump.")
try:
regressor, scaler, pca = load_model_artifacts()
print("main regressor", regressor,'scaler',scaler,'pca',pca)
except (FileNotFoundError, pickle.UnpicklingError):
X_train, y_train = load_data()
regressor = LinearRegression()
regressor.fit(X_train, y_train)
scaler = StandardScaler()
scaler.fit(X_train)
pca = PCA(n_components=4)
pca.fit(scaler.transform(X_train))
save_model_artifacts(regressor, scaler, pca)
cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=1.0)
blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=1.0)
fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=1.0)
water = st.number_input("Water (kg/m^3)", min_value=0.0, step=1.0)
superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=1.0)
coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=1.0)
fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=1.0)
FLOW = st.number_input("FLOW (cm)", min_value=0.0, step=1.0)
print('cement',cement,'blast_furnace_slag', blast_furnace_slag, 'fly_ash',fly_ash,'water', water, 'superplasticizer',superplasticizer, 'coarse_aggregate',coarse_aggregate, 'fine_aggregate',fine_aggregate, 'FLOW',FLOW)
# cement = 0.5532916014826834
# blast_furnace_slag =-0.005227944774632739
# fly_ash = -0.13155706473691084
# water = -0.8899452596015911
# superplasticizer = -0.8533594548721104
# coarse_aggregate = 0.7873497318642375
# fine_aggregate = 0.08018932948598978
# FLOW = 0.06250289692348374
if st.button("Predict Slump Strength"):
slump_prediction = predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW)
print('slump_prediction',slump_prediction)
st.write(f"Predicted Slump Strength: {slump_prediction:.2f} MPA")
st.title("Concrete Slump Strength Prediction and Sustainable Development Goals")
st.write("""Concrete slump strength prediction is an important topic that can have implications for several Sustainable Development Goals (SDGs) set by the United Nations.""")
col1, col2 = st.columns(2)
with col1:
st.subheader("SDG 9: Industry, Innovation, and Infrastructure")
st.markdown("""
- Accurate prediction of concrete slump strength can help in the design and construction of more robust and resilient infrastructure.
- Improved concrete strength prediction can lead to more efficient use of materials and resources, reducing waste and promoting sustainable construction practices.
""")
with col2:
st.subheader("SDG 11: Sustainable Cities and Communities")
st.markdown("""
- Reliable concrete slump strength prediction can contribute to the development of sustainable and resilient cities.
- Accurate slump strength prediction can help in the planning and construction of affordable and accessible housing.
""")
if __name__ == '__main__':
main()
import streamlit as st
|