-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (33 loc) · 1000 Bytes
/
Copy pathutils.py
File metadata and controls
43 lines (33 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd
def load_data(file_path, index_col=None):
"""
Load a CSV file into a pandas DataFrame.
Parameters:
file_path (str): Path to the CSV file.
index_col (int, optional): Column to use as the index.
Returns:
pd.DataFrame: Loaded dataset.
"""
return pd.read_csv(file_path, index_col=index_col)
def save_score(score, file_path):
"""
Save the model score to a text file.
Parameters:
score (float): Model score (R²).
file_path (str): Output text file.
"""
with open(file_path, "w") as f:
f.write(f"{score:.4f}")
def save_predictions(df, file_path):
"""
Save predictions to a CSV file.
Parameters:
df (pd.DataFrame): DataFrame containing predictions.
file_path (str): Output CSV file.
"""
df.to_csv(file_path)
import joblib
def save_model(model, file_path):
joblib.dump(model, file_path)
def load_model(file_path):
return joblib.load(file_path)