Concrete Strength.ipynb - Colab
Concrete Strength.ipynb - Colab
ipynb - Colab
Initial Data:
CementComponent BlastFurnaceSlag FlyAshComponent WaterComponent \
0 540.0 0.0 0.0 162.0
1 540.0 0.0 0.0 162.0
2 332.5 142.5 0.0 228.0
3 332.5 142.5 0.0 228.0
4 198.6 132.4 0.0 192.0
SuperplasticizerComponent CoarseAggregateComponent \
0 2.5 1040.0
1 2.5 1055.0
2 0.0 932.0
3 0.0 932.0
4 0.0 978.4
Enter 'remove' to drop missing values or 'median' to fill with median: median
Missing values filled with median.
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 1/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
SuperplasticizerComponent CoarseAggregateComponent \
0 2.5 1040.0
1 2.5 1055.0
2 0.0 932.0
3 0.0 932.0
4 0.0 978.4
outlier_method = input("Enter 'iqr' for IQR method or 'zscore' for Z-score method to hand
if outlier_method == 'iqr':
data = remove_outliers_iqr(data)
print("Outliers handled using IQR.")
elif outlier_method == 'zscore':
data = remove_outliers_zscore(data)
print("Outliers handled using Z-score.")
Enter 'iqr' for IQR method or 'zscore' for Z-score method to handle outliers: zscore
Outliers handled using Z-score.
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 2/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
SuperplasticizerComponent CoarseAggregateComponent \
0 2.5 1040.0
1 2.5 1055.0
5 0.0 932.0
7 0.0 932.0
8 0.0 932.0
SuperplasticizerComponent CoarseAggregateComponent \
0 -0.673726 0.839761
1 -0.673726 1.032749
2 -1.129625 -0.549747
3 -1.129625 -0.549747
4 -1.129625 -0.549747
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 3/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define Models
models = {
"Decision Tree": DecisionTreeRegressor(random_state=42),
"Random Forest": RandomForestRegressor(random_state=42),
"XGBoost": XGBRegressor(random_state=42, objective='reg:squarederror')
}
xgb_param_grid = {
'n_estimators': [50, 100, 200],
'max_depth': [3, 5, 10],
'learning_rate': [0.01, 0.1, 0.3]
}
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 4/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
XGBoost Best Parameters: {'learning_rate': 0.3, 'max_depth': 5, 'n_estimators': 200}
Decision Tree - Percentage of predictions within ±10 units of true value: 100.0%
Random Forest - Percentage of predictions within ±10 units of true value: 100.0%
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 5/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
XGBoost - Percentage of predictions within ±10 units of true value: 100.0%
# Initialize models
models = {
"Decision Tree": DecisionTreeRegressor(random_state=42),
"Random Forest": RandomForestRegressor(n_estimators=100, random_state=42),
"XGBoost": XGBRegressor(n_estimators=100, random_state=42, objective='reg:squarederro
}
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 6/7
11/8/24, 3:48 PM concrete strength.ipynb - Colab
------------------------------
Performance Comparison:
Mean Absolute Error Mean Squared Error R^2 Score
Decision Tree 0.310904 0.232784 0.753157
Random Forest 0.230687 0.120433 0.872293
XGBoost 0.199964 0.107200 0.886325
https://colab.research.google.com/drive/1OaThaXg5S2tBw172V5NmebklkrofR9HK#scrollTo=HrAqhLmHxtqv&printMode=true 7/7