fadzwan commited on
Commit
af8cdca
·
verified ·
1 Parent(s): e5d0494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -37,39 +37,39 @@ def save_model_artifacts(regressor, scaler, pca):
37
  with open('pca.pkl', 'wb') as f:
38
  pickle.dump(pca, f, protocol=pickle.HIGHEST_PROTOCOL)
39
 
40
- def preprocess_data(X):
41
- print('preprocess_data X',X)
42
- # Load the trained scaler and PCA
43
- scaler = joblib.load('scaler.pkl')
44
- pca = joblib.load('pca.pkl')
45
 
46
- # Check if the input has 8 features
47
- if X.shape[1] != 8:
48
- raise ValueError("Input data should have 8 features.")
49
 
50
- # Scale the input data using the loaded scaler
51
- X_scaled = scaler.transform(X)
52
- print("X_scaled",X_scaled)
53
- # Apply PCA using the loaded PCA transformer
54
- X_pca = pca.transform(X_scaled)
55
- print("X_pca",X_pca)
56
 
57
- return X_pca
58
 
59
  def predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW):
60
  # Prepare the input data
61
  X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW]])
62
 
63
  # Preprocess the data
64
- X_preprocessed = preprocess_data(X)
65
- print("predict_slump X",X)
66
- print("predict_slump X_preprocessed",X_preprocessed)
67
 
68
  # Load the trained model
69
  regressor = joblib.load('slump_regressor.pkl')
70
 
71
  # Make the prediction
72
- slump_prediction = regressor.predict(X_preprocessed)[0]
73
 
74
  return slump_prediction
75
 
 
37
  with open('pca.pkl', 'wb') as f:
38
  pickle.dump(pca, f, protocol=pickle.HIGHEST_PROTOCOL)
39
 
40
+ # def preprocess_data(X):
41
+ # print('preprocess_data X',X)
42
+ # # Load the trained scaler and PCA
43
+ # scaler = joblib.load('scaler.pkl')
44
+ # pca = joblib.load('pca.pkl')
45
 
46
+ # # Check if the input has 8 features
47
+ # if X.shape[1] != 8:
48
+ # raise ValueError("Input data should have 8 features.")
49
 
50
+ # # Scale the input data using the loaded scaler
51
+ # X_scaled = scaler.transform(X)
52
+ # print("X_scaled",X_scaled)
53
+ # # Apply PCA using the loaded PCA transformer
54
+ # # X_pca = pca.transform(X_scaled) somehow dapat 4
55
+ # # print("X_pca",X_pca)
56
 
57
+ # return X_pca
58
 
59
  def predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW):
60
  # Prepare the input data
61
  X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW]])
62
 
63
  # Preprocess the data
64
+ # X_preprocessed = preprocess_data(X)
65
+ # print("predict_slump X",X)
66
+ # print("predict_slump X_preprocessed",X_preprocessed)
67
 
68
  # Load the trained model
69
  regressor = joblib.load('slump_regressor.pkl')
70
 
71
  # Make the prediction
72
+ slump_prediction = regressor.predict(X)[0]
73
 
74
  return slump_prediction
75