Upload 2 files
Browse files- example_usage.py +40 -0
- water_potability_model.pkl +3 -0
example_usage.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import joblib
|
| 3 |
+
|
| 4 |
+
# Load the saved pipeline
|
| 5 |
+
try:
|
| 6 |
+
model = joblib.load('water_potability_model.pkl')
|
| 7 |
+
print("Model loaded successfully!")
|
| 8 |
+
except FileNotFoundError:
|
| 9 |
+
print("Error: The file 'water_potability_model.pkl' was not found.")
|
| 10 |
+
exit()
|
| 11 |
+
except Exception as e:
|
| 12 |
+
print("An unexpected error occurred while loading the pipeline:", e)
|
| 13 |
+
exit()
|
| 14 |
+
|
| 15 |
+
# Create a new water sample
|
| 16 |
+
# IMPORTANT: Use the same feature order and names as in training
|
| 17 |
+
sample_data = {
|
| 18 |
+
'ph': [7.2],
|
| 19 |
+
'Hardness': [180],
|
| 20 |
+
'Solids': [15000],
|
| 21 |
+
'Chloramines': [8.3],
|
| 22 |
+
'Sulfate': [350],
|
| 23 |
+
'Conductivity': [450],
|
| 24 |
+
'Organic_carbon': [10],
|
| 25 |
+
'Trihalomethanes': [70],
|
| 26 |
+
'Turbidity': [3]
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Convert to DataFrame with proper column names
|
| 30 |
+
sample_df = pd.DataFrame(sample_data)
|
| 31 |
+
|
| 32 |
+
# Make prediction
|
| 33 |
+
try:
|
| 34 |
+
prediction = model.predict(sample_df)
|
| 35 |
+
result = "Potable" if prediction[0] == 1 else "Not Potable"
|
| 36 |
+
print("Sample Prediction:", result)
|
| 37 |
+
except ValueError as e:
|
| 38 |
+
print("Error: Sample input has incorrect shape or type.", e)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print("An unexpected error occurred during prediction:", e)
|
water_potability_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e66ec01a9cc1916a5e08243d4136a92c103ac40ad2f5118c2dd0a23f7df2e895
|
| 3 |
+
size 7343234
|