-
Notifications
You must be signed in to change notification settings - Fork 26
/
tabular-playground-series-sep-2021.py
39 lines (29 loc) · 1.21 KB
/
tabular-playground-series-sep-2021.py
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
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
from lightgbm import LGBMClassifier
# Load the data
train_data = pd.read_csv("./input/train.csv")
test_data = pd.read_csv("./input/test.csv")
# Separate features and target
X = train_data.drop(columns=["id", "claim"])
y = train_data["claim"]
# Handle missing values by imputing with median
X.fillna(X.median(), inplace=True)
test_data.fillna(test_data.median(), inplace=True)
# Split the data into training and validation sets
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize the LightGBM model
model = LGBMClassifier(random_state=42)
# Train the model
model.fit(X_train, y_train)
# Predict on the validation set
val_predictions = model.predict_proba(X_val)[:, 1]
# Calculate the ROC AUC score
val_auc = roc_auc_score(y_val, val_predictions)
print(f"Validation ROC AUC Score: {val_auc}")
# Predict on the test set
test_predictions = model.predict_proba(test_data.drop(columns=["id"]))[:, 1]
# Create the submission file
submission = pd.DataFrame({"id": test_data["id"], "claim": test_predictions})
submission.to_csv("./working/submission.csv", index=False)