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
# load packages | |
import pandas as pd | |
from fast_ml.utilities import display_all | |
from fast_ml.feature_selection import get_duplicate_features | |
# load dataset | |
df = pd.read_csv('/kaggle/input/dataset-1/dataset_1.csv') | |
# function to detect duplicate features | |
duplicate_features = get_duplicate_features(df) |
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
# load packages | |
import pandas as pd | |
from fast_ml.utilities import display_all | |
from fast_ml.feature_selection import get_duplicate_features | |
# load dataset | |
df = pd.read_csv('/kaggle/input/dataset-1/dataset_1.csv') | |
# function to detect duplicate features | |
duplicate_features = get_duplicate_features(df) |
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
import pandas as pd | |
df = pd.read_csv('/kaggle/input/bluebook-for-bulldozers/TrainAndValid.csv', parse_dates=['saledate'], low_memory=False) | |
# Let's say we want to split the data in 80:10:10 for train:valid:test dataset | |
train_size = 0.8 | |
valid_size=0.1 | |
train_index = int(len(df)*train_size) |
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
import pandas as pd | |
df = pd.read_csv('/kaggle/input/bluebook-for-bulldozers/TrainAndValid.csv', parse_dates=['saledate'], low_memory=False) | |
from fast_ml.model_development import train_valid_test_split | |
X_train, y_train, X_valid, y_valid, X_test, y_test = train_valid_test_split(df, target = 'SalePrice', | |
method='sorted', sort_by_col='saledate', | |
train_size=0.8, valid_size=0.1, test_size=0.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
import pandas as pd | |
df = pd.read_csv('/kaggle/input/bluebook-for-bulldozers/TrainAndValid.csv', parse_dates=['saledate'], low_memory=False) | |
from fast_ml.model_development import train_valid_test_split | |
X_train, y_train, X_valid, y_valid, X_test, y_test = train_valid_test_split(df, target = 'SalePrice', | |
train_size=0.8, valid_size=0.1, test_size=0.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
import pandas as pd | |
df = pd.read_csv('/kaggle/input/bluebook-for-bulldozers/TrainAndValid.csv', parse_dates=['saledate'], low_memory=False) | |
from sklearn.model_selection import train_test_split | |
# Let's say we want to split the data in 80:10:10 for train:valid:test dataset | |
train_size=0.8 | |
X = df.drop(columns = ['SalePrice']).copy() |
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
# Get test data loss and accuracy | |
test_losses = [] # track loss | |
num_correct = 0 | |
# init hidden state | |
h = net.init_hidden(batch_size) | |
net.eval() | |
# iterate over test data |
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
from string import punctuation | |
def tokenize_review(test_review): | |
test_review = test_review.lower() # lowercase | |
# get rid of punctuation | |
test_text = ''.join([c for c in test_review if c not in punctuation]) | |
# splitting by spaces | |
test_words = test_text.split() |
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
# loss and optimization functions | |
lr=0.001 | |
criterion = nn.BCELoss() | |
optimizer = torch.optim.Adam(net.parameters(), lr=lr) | |
# training params | |
epochs = 4 # 3-4 is approx where I noticed the validation loss stop decreasing |
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
import torch.nn as nn | |
class SentimentLSTM(nn.Module): | |
""" | |
The RNN model that will be used to perform Sentiment analysis. | |
""" | |
def __init__(self, vocab_size, output_size, embedding_dim, hidden_dim, n_layers, drop_prob=0.5): | |
""" | |
Initialize the model by setting up the layers. |