Spaces:
No application file
No application file
Update engine_model.pkl
Browse files- engine_model.pkl +9 -19
engine_model.pkl
CHANGED
|
@@ -1,38 +1,28 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
import numpy as np
|
| 3 |
import xgboost as xgb
|
| 4 |
import joblib
|
| 5 |
|
| 6 |
-
#
|
| 7 |
url = "https://raw.githubusercontent.com/datasets-machine-learning/nasa-turbofan-failure-prediction/master/data/train_FD001.txt"
|
| 8 |
cols = ['unit', 'cycles', 'os1', 'os2', 'os3'] + [f's{i}' for i in range(1, 22)]
|
| 9 |
df = pd.read_csv(url, sep='\s+', header=None, names=cols)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
# We find the maximum cycle for each engine and subtract the current cycle
|
| 13 |
max_cycles = df.groupby('unit')['cycles'].max().reset_index()
|
| 14 |
max_cycles.columns = ['unit', 'max_of_unit']
|
| 15 |
df = df.merge(max_cycles, on='unit', how='left')
|
| 16 |
df['RUL'] = df['max_of_unit'] - df['cycles']
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
features = ['cycles', 's2', 's3', 's4', 's7', 's8', 's11', 's12', 's13', 's15', 's17', 's20', 's21']
|
| 21 |
X = df[features]
|
| 22 |
y = df['RUL']
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
model = xgb.XGBRegressor(
|
| 27 |
-
n_estimators=100,
|
| 28 |
-
learning_rate=0.1,
|
| 29 |
-
max_depth=5,
|
| 30 |
-
objective='reg:squarederror'
|
| 31 |
-
)
|
| 32 |
model.fit(X, y)
|
| 33 |
|
| 34 |
-
#
|
| 35 |
joblib.dump(model, 'engine_model.pkl')
|
| 36 |
-
|
| 37 |
-
print("✅ Success! 'engine_model.pkl' has been created in your folder.")
|
| 38 |
-
print("Now, upload this file to your Hugging Face Space.")
|
|
|
|
| 1 |
import pandas as pd
|
|
|
|
| 2 |
import xgboost as xgb
|
| 3 |
import joblib
|
| 4 |
|
| 5 |
+
# Load the dataset directly from the web
|
| 6 |
url = "https://raw.githubusercontent.com/datasets-machine-learning/nasa-turbofan-failure-prediction/master/data/train_FD001.txt"
|
| 7 |
cols = ['unit', 'cycles', 'os1', 'os2', 'os3'] + [f's{i}' for i in range(1, 22)]
|
| 8 |
df = pd.read_csv(url, sep='\s+', header=None, names=cols)
|
| 9 |
|
| 10 |
+
# Calculate RUL (Remaining Useful Life)
|
|
|
|
| 11 |
max_cycles = df.groupby('unit')['cycles'].max().reset_index()
|
| 12 |
max_cycles.columns = ['unit', 'max_of_unit']
|
| 13 |
df = df.merge(max_cycles, on='unit', how='left')
|
| 14 |
df['RUL'] = df['max_of_unit'] - df['cycles']
|
| 15 |
|
| 16 |
+
# We use exactly 15 features to match the app.py logic
|
| 17 |
+
# (cycles + 14 sensor/settings columns)
|
| 18 |
+
features = ['cycles', 's2', 's3', 's4', 's7', 's8', 's11', 's12', 's13', 's15', 's17', 's20', 's21', 'os1', 'os2']
|
| 19 |
X = df[features]
|
| 20 |
y = df['RUL']
|
| 21 |
|
| 22 |
+
# Train the model
|
| 23 |
+
model = xgb.XGBRegressor(n_estimators=100, learning_rate=0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
model.fit(X, y)
|
| 25 |
|
| 26 |
+
# SAVE THE FILE
|
| 27 |
joblib.dump(model, 'engine_model.pkl')
|
| 28 |
+
print("✅ Done! 'engine_model.pkl' created in your folder.")
|
|
|
|
|
|