Spaces:
Sleeping
Sleeping
Commit ·
3977aa0
1
Parent(s): 0922d39
fixe model path
Browse files
scripts/train_anomaly_detection.py
CHANGED
|
@@ -43,9 +43,16 @@ def main(args):
|
|
| 43 |
|
| 44 |
# Prepare results directory
|
| 45 |
if args.results_path is None:
|
|
|
|
| 46 |
args.results_path = os.path.join("results", f"{estimator.__class__.__name__}_Anomaly")
|
| 47 |
os.makedirs(args.results_path, exist_ok=True)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
# Load data
|
| 50 |
df = pd.read_csv(args.data_path)
|
| 51 |
print(f"Data loaded from {args.data_path}, initial shape: {df.shape}")
|
|
@@ -84,8 +91,7 @@ def main(args):
|
|
| 84 |
print(f"Anomaly detection training with {args.model_module} completed in {train_time:.2f} seconds.")
|
| 85 |
|
| 86 |
# Save the model
|
| 87 |
-
model_output_path = os.path.join(args.
|
| 88 |
-
os.makedirs(args.model_path, exist_ok=True)
|
| 89 |
joblib.dump(estimator, model_output_path)
|
| 90 |
print(f"Model saved to {model_output_path}")
|
| 91 |
|
|
@@ -149,7 +155,7 @@ if __name__ == "__main__":
|
|
| 149 |
help='Name of the anomaly detection model (e.g. isolation_forest, one_class_svm).')
|
| 150 |
parser.add_argument('--data_path', type=str, required=True,
|
| 151 |
help='Path to the CSV dataset file.')
|
| 152 |
-
parser.add_argument('--model_path', type=str, default=
|
| 153 |
help='Path to save the trained model.')
|
| 154 |
parser.add_argument('--results_path', type=str, default=None,
|
| 155 |
help='Directory to save results (predictions, plots).')
|
|
|
|
| 43 |
|
| 44 |
# Prepare results directory
|
| 45 |
if args.results_path is None:
|
| 46 |
+
# e.g., 'results/IsolationForest_Anomaly'
|
| 47 |
args.results_path = os.path.join("results", f"{estimator.__class__.__name__}_Anomaly")
|
| 48 |
os.makedirs(args.results_path, exist_ok=True)
|
| 49 |
|
| 50 |
+
# Prepare model directory
|
| 51 |
+
if args.model_path is None:
|
| 52 |
+
# e.g., 'saved_model/IsolationForest_Anomaly'
|
| 53 |
+
args.model_path = os.path.join('saved_models', f"{estimator.__class__.__name__}_Anomaly")
|
| 54 |
+
os.makedirs(args.model_path, exist_ok=True)
|
| 55 |
+
|
| 56 |
# Load data
|
| 57 |
df = pd.read_csv(args.data_path)
|
| 58 |
print(f"Data loaded from {args.data_path}, initial shape: {df.shape}")
|
|
|
|
| 91 |
print(f"Anomaly detection training with {args.model_module} completed in {train_time:.2f} seconds.")
|
| 92 |
|
| 93 |
# Save the model
|
| 94 |
+
model_output_path = os.path.join(args.model_path, "anomaly_model.pkl")
|
|
|
|
| 95 |
joblib.dump(estimator, model_output_path)
|
| 96 |
print(f"Model saved to {model_output_path}")
|
| 97 |
|
|
|
|
| 155 |
help='Name of the anomaly detection model (e.g. isolation_forest, one_class_svm).')
|
| 156 |
parser.add_argument('--data_path', type=str, required=True,
|
| 157 |
help='Path to the CSV dataset file.')
|
| 158 |
+
parser.add_argument('--model_path', type=str, default=None,
|
| 159 |
help='Path to save the trained model.')
|
| 160 |
parser.add_argument('--results_path', type=str, default=None,
|
| 161 |
help='Directory to save results (predictions, plots).')
|
scripts/train_clustering_model.py
CHANGED
|
@@ -45,6 +45,12 @@ def main(args):
|
|
| 45 |
# e.g., 'results/KMeans_Clustering'
|
| 46 |
args.results_path = os.path.join('results', f"{estimator.__class__.__name__}_Clustering")
|
| 47 |
os.makedirs(args.results_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Load data from CSV
|
| 50 |
df = pd.read_csv(args.data_path)
|
|
@@ -94,8 +100,7 @@ def main(args):
|
|
| 94 |
print(f"Training time (no tuning): {end_time - start_time:.2f}s")
|
| 95 |
|
| 96 |
# Ensure the model is fitted at this point
|
| 97 |
-
model_output_path = os.path.join(args.
|
| 98 |
-
os.makedirs(args.model_path, exist_ok=True) # ensure directory exists
|
| 99 |
joblib.dump(estimator, model_output_path)
|
| 100 |
print(f"Model saved to {model_output_path}")
|
| 101 |
|
|
@@ -165,7 +170,7 @@ if __name__ == "__main__":
|
|
| 165 |
help='Name of the clustering model module (e.g. kmeans, dbscan, etc.).')
|
| 166 |
parser.add_argument('--data_path', type=str, required=True,
|
| 167 |
help='Path to the CSV dataset.')
|
| 168 |
-
parser.add_argument('--model_path', type=str, default=
|
| 169 |
help='Path to save the trained model.')
|
| 170 |
parser.add_argument('--results_path', type=str, default=None,
|
| 171 |
help='Directory to save results (metrics, plots).')
|
|
|
|
| 45 |
# e.g., 'results/KMeans_Clustering'
|
| 46 |
args.results_path = os.path.join('results', f"{estimator.__class__.__name__}_Clustering")
|
| 47 |
os.makedirs(args.results_path, exist_ok=True)
|
| 48 |
+
|
| 49 |
+
# Prepare model directory
|
| 50 |
+
if args.model_path is None:
|
| 51 |
+
# e.g., 'saved_model/KMeans_Clustering'
|
| 52 |
+
args.model_path = os.path.join('saved_models', f"{estimator.__class__.__name__}_Clustering")
|
| 53 |
+
os.makedirs(args.model_path, exist_ok=True)
|
| 54 |
|
| 55 |
# Load data from CSV
|
| 56 |
df = pd.read_csv(args.data_path)
|
|
|
|
| 100 |
print(f"Training time (no tuning): {end_time - start_time:.2f}s")
|
| 101 |
|
| 102 |
# Ensure the model is fitted at this point
|
| 103 |
+
model_output_path = os.path.join(args.model_path, "best_model.pkl")
|
|
|
|
| 104 |
joblib.dump(estimator, model_output_path)
|
| 105 |
print(f"Model saved to {model_output_path}")
|
| 106 |
|
|
|
|
| 170 |
help='Name of the clustering model module (e.g. kmeans, dbscan, etc.).')
|
| 171 |
parser.add_argument('--data_path', type=str, required=True,
|
| 172 |
help='Path to the CSV dataset.')
|
| 173 |
+
parser.add_argument('--model_path', type=str, default=None,
|
| 174 |
help='Path to save the trained model.')
|
| 175 |
parser.add_argument('--results_path', type=str, default=None,
|
| 176 |
help='Directory to save results (metrics, plots).')
|
scripts/train_dimred_model.py
CHANGED
|
@@ -47,6 +47,12 @@ def main(args):
|
|
| 47 |
# e.g., 'results/PCA_DimRed'
|
| 48 |
args.results_path = os.path.join('results', f"{estimator.__class__.__name__}_DimRed")
|
| 49 |
os.makedirs(args.results_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Load data from CSV
|
| 52 |
df = pd.read_csv(args.data_path)
|
|
@@ -89,8 +95,7 @@ def main(args):
|
|
| 89 |
print(f"Dimensionality reduction done using {args.model_module}. Output shape: {X_transformed.shape}")
|
| 90 |
|
| 91 |
# Save the model
|
| 92 |
-
model_output_path = os.path.join(args.
|
| 93 |
-
os.makedirs(args.model_path, exist_ok=True) # ensure directory
|
| 94 |
joblib.dump(estimator, model_output_path)
|
| 95 |
print(f"Model saved to {model_output_path}")
|
| 96 |
|
|
@@ -135,7 +140,7 @@ if __name__ == "__main__":
|
|
| 135 |
help='Name of the dimred model module (e.g. pca, tsne, umap).')
|
| 136 |
parser.add_argument('--data_path', type=str, required=True,
|
| 137 |
help='Path to the CSV dataset file.')
|
| 138 |
-
parser.add_argument('--model_path', type=str, default=
|
| 139 |
help='Where to save the fitted model.')
|
| 140 |
parser.add_argument('--results_path', type=str, default=None,
|
| 141 |
help='Directory to store results (transformed data, plots).')
|
|
|
|
| 47 |
# e.g., 'results/PCA_DimRed'
|
| 48 |
args.results_path = os.path.join('results', f"{estimator.__class__.__name__}_DimRed")
|
| 49 |
os.makedirs(args.results_path, exist_ok=True)
|
| 50 |
+
|
| 51 |
+
# Prepare model directory
|
| 52 |
+
if args.model_path is None:
|
| 53 |
+
# e.g., 'saved_model/PCA_DimRed'
|
| 54 |
+
args.model_path = os.path.join('saved_models', f"{estimator.__class__.__name__}_DimRed")
|
| 55 |
+
os.makedirs(args.model_path, exist_ok=True)
|
| 56 |
|
| 57 |
# Load data from CSV
|
| 58 |
df = pd.read_csv(args.data_path)
|
|
|
|
| 95 |
print(f"Dimensionality reduction done using {args.model_module}. Output shape: {X_transformed.shape}")
|
| 96 |
|
| 97 |
# Save the model
|
| 98 |
+
model_output_path = os.path.join(args.model_path, "dimred_model.pkl")
|
|
|
|
| 99 |
joblib.dump(estimator, model_output_path)
|
| 100 |
print(f"Model saved to {model_output_path}")
|
| 101 |
|
|
|
|
| 140 |
help='Name of the dimred model module (e.g. pca, tsne, umap).')
|
| 141 |
parser.add_argument('--data_path', type=str, required=True,
|
| 142 |
help='Path to the CSV dataset file.')
|
| 143 |
+
parser.add_argument('--model_path', type=str, default=None,
|
| 144 |
help='Where to save the fitted model.')
|
| 145 |
parser.add_argument('--results_path', type=str, default=None,
|
| 146 |
help='Directory to store results (transformed data, plots).')
|