-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check forest & s3e11 & s4e8 & spaceship, change params of forest & s3…
…e26 & spaceship
- Loading branch information
Showing
15 changed files
with
121 additions
and
188 deletions.
There are no files selected for viewing
99 changes: 0 additions & 99 deletions
99
...ent/scenarios/kaggle/experiment/forest-cover-type-prediction_template/cross_validation.py
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...scenarios/kaggle/experiment/forest-cover-type-prediction_template/model/model_catboost.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from catboost import CatBoostClassifier | ||
import pandas as pd | ||
|
||
def fit(X_train: pd.DataFrame, y_train: pd.Series, X_valid: pd.DataFrame, y_valid: pd.Series): | ||
# Define CatBoost parameters | ||
cat_params = { | ||
'iterations': 5000, | ||
'learning_rate': 0.03, | ||
'od_wait': 1000, | ||
'depth': 7, | ||
'task_type': 'GPU', | ||
'l2_leaf_reg': 3, | ||
'eval_metric': 'Accuracy', | ||
'devices': '0', | ||
'verbose': 1000 | ||
} | ||
|
||
# Initialize and train the CatBoost model | ||
model = CatBoostClassifier(**cat_params) | ||
model.fit(X_train, y_train, eval_set=(X_valid, y_valid)) | ||
|
||
return model | ||
|
||
def predict(model, X: pd.DataFrame): | ||
# Predict using the trained model | ||
y_pred = model.predict(X) | ||
return y_pred.reshape(-1, 1) |
75 changes: 75 additions & 0 deletions
75
rdagent/scenarios/kaggle/experiment/forest-cover-type-prediction_template/model/model_dnn.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import torch | ||
import torch.nn as nn | ||
import torch.optim as optim | ||
from torch.utils.data import DataLoader, TensorDataset | ||
import pandas as pd | ||
import numpy as np | ||
|
||
# Define the neural network model with Batch Normalization | ||
class NeuralNetwork(nn.Module): | ||
def __init__(self, input_size, num_classes): | ||
super(NeuralNetwork, self).__init__() | ||
self.layer1 = nn.Linear(input_size, 128) | ||
self.bn1 = nn.BatchNorm1d(128) | ||
self.layer2 = nn.Linear(128, 64) | ||
self.bn2 = nn.BatchNorm1d(64) | ||
self.layer3 = nn.Linear(64, num_classes) | ||
|
||
def forward(self, x): | ||
x = torch.relu(self.bn1(self.layer1(x))) | ||
x = torch.relu(self.bn2(self.layer2(x))) | ||
x = torch.softmax(self.layer3(x), dim=1) | ||
return x | ||
|
||
def fit(X_train: pd.DataFrame, y_train: pd.DataFrame, X_valid: pd.DataFrame, y_valid: pd.DataFrame): | ||
# Convert data to PyTorch tensors | ||
X_train_tensor = torch.tensor(X_train.values, dtype=torch.float32) | ||
y_train_tensor = torch.tensor(y_train.values, dtype=torch.long) | ||
X_valid_tensor = torch.tensor(X_valid.values, dtype=torch.float32) | ||
y_valid_tensor = torch.tensor(y_valid.values, dtype=torch.long) | ||
|
||
# Create datasets and dataloaders | ||
train_dataset = TensorDataset(X_train_tensor, y_train_tensor) | ||
valid_dataset = TensorDataset(X_valid_tensor, y_valid_tensor) | ||
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True) | ||
valid_loader = DataLoader(valid_dataset, batch_size=32, shuffle=False) | ||
|
||
# Initialize the model, loss function and optimizer | ||
model = NeuralNetwork(input_size=X_train.shape[1], num_classes=len(set(y_train))) | ||
criterion = nn.CrossEntropyLoss() | ||
optimizer = optim.Adam(model.parameters(), lr=0.001) | ||
|
||
# Train the model | ||
num_epochs = 150 | ||
for epoch in range(num_epochs): | ||
model.train() | ||
for X_batch, y_batch in train_loader: | ||
optimizer.zero_grad() | ||
outputs = model(X_batch) | ||
loss = criterion(outputs, y_batch) | ||
loss.backward() | ||
optimizer.step() | ||
|
||
# Validate the model | ||
model.eval() | ||
valid_loss = 0 | ||
correct = 0 | ||
with torch.no_grad(): | ||
for X_batch, y_batch in valid_loader: | ||
outputs = model(X_batch) | ||
valid_loss += criterion(outputs, y_batch).item() | ||
_, predicted = torch.max(outputs, 1) | ||
correct += (predicted == y_batch).sum().item() | ||
|
||
accuracy = correct / len(valid_loader.dataset) | ||
print(f'Epoch {epoch+1}/{num_epochs}, Validation Accuracy: {accuracy:.4f}') | ||
|
||
return model | ||
|
||
def predict(model, X): | ||
X_tensor = torch.tensor(X.values, dtype=torch.float32) | ||
model.eval() | ||
with torch.no_grad(): | ||
outputs = model(X_tensor) | ||
_, predicted = torch.max(outputs, 1) | ||
return predicted.numpy().reshape(-1, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
rdagent/scenarios/kaggle/experiment/playground-series-s4e9_template/model/model_nn.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters