Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- ml_model/train_model.py +4 -4
ml_model/train_model.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from sklearn.model_selection import train_test_split, RandomizedSearchCV
|
| 2 |
from sklearn.metrics import classification_report, confusion_matrix
|
| 3 |
from imblearn.over_sampling import SMOTE
|
| 4 |
-
from imblearn.pipeline import Pipeline
|
| 5 |
from xgboost import XGBClassifier
|
| 6 |
from scipy.stats import uniform, randint
|
| 7 |
|
|
@@ -17,7 +17,7 @@ def train_model(X, y):
|
|
| 17 |
)
|
| 18 |
ratio = sum(y == 0) / sum(y == 1)
|
| 19 |
|
| 20 |
-
pipeline =
|
| 21 |
[("sampler", SMOTE(random_state=42)), ("clf", XGBClassifier(random_state=42))]
|
| 22 |
)
|
| 23 |
param_dist = {
|
|
@@ -44,12 +44,12 @@ def train_model(X, y):
|
|
| 44 |
)
|
| 45 |
random.fit(X_train, y_train)
|
| 46 |
|
| 47 |
-
best_model = random.best_estimator_
|
| 48 |
best_params = random.best_params_
|
| 49 |
cv_f1 = random.best_score_
|
| 50 |
|
| 51 |
# Éval test (pédagogique)
|
| 52 |
-
y_pred = best_model.predict(X_test)
|
| 53 |
print("Meilleurs params:", best_params)
|
| 54 |
print("Meilleur CV F1:", cv_f1)
|
| 55 |
print(classification_report(y_test, y_pred))
|
|
|
|
| 1 |
from sklearn.model_selection import train_test_split, RandomizedSearchCV
|
| 2 |
from sklearn.metrics import classification_report, confusion_matrix
|
| 3 |
from imblearn.over_sampling import SMOTE
|
| 4 |
+
from imblearn.pipeline import Pipeline as ImbPipeline
|
| 5 |
from xgboost import XGBClassifier
|
| 6 |
from scipy.stats import uniform, randint
|
| 7 |
|
|
|
|
| 17 |
)
|
| 18 |
ratio = sum(y == 0) / sum(y == 1)
|
| 19 |
|
| 20 |
+
pipeline = ImbPipeline(
|
| 21 |
[("sampler", SMOTE(random_state=42)), ("clf", XGBClassifier(random_state=42))]
|
| 22 |
)
|
| 23 |
param_dist = {
|
|
|
|
| 44 |
)
|
| 45 |
random.fit(X_train, y_train)
|
| 46 |
|
| 47 |
+
best_model = random.best_estimator_ # type: ignore[assignment]
|
| 48 |
best_params = random.best_params_
|
| 49 |
cv_f1 = random.best_score_
|
| 50 |
|
| 51 |
# Éval test (pédagogique)
|
| 52 |
+
y_pred = best_model.predict(X_test) # type: ignore[attr-defined]
|
| 53 |
print("Meilleurs params:", best_params)
|
| 54 |
print("Meilleur CV F1:", cv_f1)
|
| 55 |
print(classification_report(y_test, y_pred))
|