Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compute remaining time + regression task #1

Open
federicotorrielli opened this issue Jun 14, 2024 · 0 comments
Open

Add compute remaining time + regression task #1

federicotorrielli opened this issue Jun 14, 2024 · 0 comments

Comments

@federicotorrielli
Copy link

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report

### REMAINING TIME CALCULATION ###
df_log['TIMESTAMP'] = pd.to_datetime(df_log['TIMESTAMP'])
df_log = df_log.sort_values(by=['CaseID', 'TIMESTAMP'])
df_log['remaining_time'] = df_log.groupby('CaseID')['TIMESTAMP'].transform(lambda x: x.max() - x)

### CONVERT REMAINING TIME TO SECONDS ###
df_log['remaining_time_seconds'] = df_log['remaining_time'].dt.total_seconds()

### DEFINE FEATURES AND TARGET ###
activity_columns = [col for col in df_log.columns if col.startswith('ACTIVITY_')]
X = df_log[activity_columns + ['remaining_time_seconds']]
y = df_log['OUTCOME']

### SPLIT DATA ###
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

### TRAIN LOGISTIC REGRESSION MODEL ###
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)

### PREDICT AND EVALUATE ###
y_pred = model.predict(X_test)
report = classification_report(y_test, y_pred, output_dict=True)
report_df = pd.DataFrame(report).transpose()

### DISPLAY CLASSIFICATION REPORT ###
print(report_df)

Non so neanche se sia 100% corretto, prova tu :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant