Spaces:
Build error
Build error
Commit ·
6195581
1
Parent(s): 4afc0a1
change input to be df
Browse files
app.py
CHANGED
|
@@ -17,20 +17,50 @@ def predict(
|
|
| 17 |
'''
|
| 18 |
Predict the label for the data inputed
|
| 19 |
'''
|
| 20 |
-
# Combine the input data into a NumPy array
|
| 21 |
-
input_array = np.array([
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
#predict
|
| 33 |
-
label = MODEL.predict(input_array)
|
|
|
|
| 34 |
|
| 35 |
return label
|
| 36 |
|
|
|
|
| 17 |
'''
|
| 18 |
Predict the label for the data inputed
|
| 19 |
'''
|
| 20 |
+
# # Combine the input data into a NumPy array
|
| 21 |
+
# input_array = np.array([
|
| 22 |
+
# age, height, weight,
|
| 23 |
+
# waist, eye_L, eye_R,
|
| 24 |
+
# hear_L, hear_R, systolic,
|
| 25 |
+
# relaxation, fasting_blood_sugar, cholesterol,
|
| 26 |
+
# triglyceride, HDL, LDL,
|
| 27 |
+
# hemoglobin, urine_protein,
|
| 28 |
+
# serum_creatinine, AST, ALT,
|
| 29 |
+
# Gtp, dental_caries
|
| 30 |
+
# ])
|
| 31 |
+
|
| 32 |
+
# Create a dictionary with input data and dataset var names
|
| 33 |
+
input_data = {
|
| 34 |
+
"age": age,
|
| 35 |
+
"height(cm)": height,
|
| 36 |
+
"weight(kg)": weight,
|
| 37 |
+
"waist(cm)": waist,
|
| 38 |
+
"eyesight(left)": eye_L,
|
| 39 |
+
"eyesight(right)": eye_R,
|
| 40 |
+
"hearing(left)": hear_L,
|
| 41 |
+
"hearing(right)": hear_R,
|
| 42 |
+
"systolic": systolic,
|
| 43 |
+
"relaxation": relaxation,
|
| 44 |
+
"fasting blood sugar": fasting_blood_sugar,
|
| 45 |
+
"Cholesterol": cholesterol,
|
| 46 |
+
"triglyceride": triglyceride,
|
| 47 |
+
"HDL": HDL,
|
| 48 |
+
"LDL": LDL,
|
| 49 |
+
"hemoglobin": hemoglobin,
|
| 50 |
+
"Urine protein": urine_protein,
|
| 51 |
+
"serum creatinine": serum_creatinine,
|
| 52 |
+
"AST": AST,
|
| 53 |
+
"ALT": ALT,
|
| 54 |
+
"Gtp": Gtp,
|
| 55 |
+
"dental caries": dental_caries
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# Convert the dictionary to a pandas DataFrame
|
| 59 |
+
input_df = pd.DataFrame(input_data, index=[0])
|
| 60 |
|
| 61 |
#predict
|
| 62 |
+
# label = MODEL.predict(input_array)
|
| 63 |
+
label = MODEL.predict(input_df)
|
| 64 |
|
| 65 |
return label
|
| 66 |
|
model.py
CHANGED
|
@@ -31,7 +31,7 @@ class SmokerModel:
|
|
| 31 |
|
| 32 |
return new_data_scaled
|
| 33 |
|
| 34 |
-
def predict(self, X: np.ndarray) -> str:
|
| 35 |
"""
|
| 36 |
Make a prediction on one sample using the loaded model.
|
| 37 |
|
|
@@ -44,16 +44,20 @@ class SmokerModel:
|
|
| 44 |
predicted label
|
| 45 |
"""
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
# Check if the array is 1-dimensional aka one sample
|
| 48 |
-
if len(
|
| 49 |
raise ValueError("Input array must be one-dimensional (one sample), but got a shape of {}".format(X.shape))
|
| 50 |
return
|
| 51 |
|
| 52 |
# Reshape the array
|
| 53 |
-
X = X.reshape(1, -1)
|
|
|
|
| 54 |
|
| 55 |
-
# scale the data
|
| 56 |
-
X_scaled = self.scale(X)
|
| 57 |
|
| 58 |
# Now, use the scaled data to make predictions using the loaded model
|
| 59 |
array = self.model.predict(X_scaled)
|
|
|
|
| 31 |
|
| 32 |
return new_data_scaled
|
| 33 |
|
| 34 |
+
def predict(self, X: np.ndarray) -> str: #TODO: change type to pd df
|
| 35 |
"""
|
| 36 |
Make a prediction on one sample using the loaded model.
|
| 37 |
|
|
|
|
| 44 |
predicted label
|
| 45 |
"""
|
| 46 |
|
| 47 |
+
# scale the data
|
| 48 |
+
X_scaled = self.scale(X)
|
| 49 |
+
|
| 50 |
# Check if the array is 1-dimensional aka one sample
|
| 51 |
+
if len(X_scaled.shape) != 1:
|
| 52 |
raise ValueError("Input array must be one-dimensional (one sample), but got a shape of {}".format(X.shape))
|
| 53 |
return
|
| 54 |
|
| 55 |
# Reshape the array
|
| 56 |
+
# X = X.reshape(1, -1)
|
| 57 |
+
X_scaled = X_scaled.reshape(1, -1)
|
| 58 |
|
| 59 |
+
# # scale the data
|
| 60 |
+
# X_scaled = self.scale(X)
|
| 61 |
|
| 62 |
# Now, use the scaled data to make predictions using the loaded model
|
| 63 |
array = self.model.predict(X_scaled)
|