|
import pandas as pd |
|
import numpy as np |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.metrics import cohen_kappa_score |
|
import lightgbm as lgb |
|
|
|
|
|
train_data = pd.read_csv("./input/train.csv") |
|
test_data = pd.read_csv("./input/test.csv") |
|
|
|
|
|
X = train_data.drop(["Id", "quality"], axis=1) |
|
y = train_data["quality"] |
|
X_test = test_data.drop("Id", axis=1) |
|
|
|
|
|
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
model = lgb.LGBMRegressor(random_state=42) |
|
model.fit(X_train, y_train) |
|
|
|
|
|
val_predictions = model.predict(X_val) |
|
val_predictions = np.round(val_predictions).astype(int) |
|
|
|
|
|
kappa_score = cohen_kappa_score(y_val, val_predictions, weights="quadratic") |
|
print(f"Quadratic Weighted Kappa score on validation set: {kappa_score}") |
|
|
|
|
|
test_predictions = model.predict(X_test) |
|
test_predictions = np.round(test_predictions).astype( |
|
int |
|
) |
|
|
|
|
|
submission = pd.DataFrame({"Id": test_data["Id"], "quality": test_predictions}) |
|
submission.to_csv("./working/submission.csv", index=False) |
|
|