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
gpu_info = !nvidia-smi | |
gpu_info = '\n'.join(gpu_info) | |
if gpu_info.find('failed') >= 0: | |
print('Not connected to a GPU') | |
else: | |
print(gpu_info) |
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
df['Boilerplate'] = mts.Boilerplate(sent_tok, n = 4, min_doc = 5, get_ngram = False) |
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 ._Class1 import Function1 | |
from ._Class1 import Function2 | |
from ._Class2 import Function1 | |
... |
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
# Call Model | |
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels = num_labels).to("cuda") |
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
##### AVERAGE | |
average_pred = (XGB_pred+ | |
KNN_pred+ | |
MLPC_pred+ | |
RandomForest_pred+ | |
DecisionTree_pred)/5 | |
#make submission table | |
FiveModelAveragePrediction = pd.DataFrame( | |
{'QuoteNumber':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
##### Decision Tree | |
DecisionTree = DecisionTreeClassifier() | |
DecisionTree.fit(data, label) | |
DecisionTree_pred = DecisionTree.predict(Test) | |
#make submission table | |
DecisionTreePrediction = pd.DataFrame( | |
{'QuoteNumber':df, | |
'QuoteConversion_Flag':DecisionTree_pred}) | |
#save file | |
DecisionTreePrediction.to_csv('DecisionTree1.csv', |
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 libraries | |
import pandas as pd | |
import numpy as np | |
#from statistics import * | |
import os | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.neural_network import MLPClassifier | |
from xgboost import XGBClassifier |
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
#set parameters | |
params = {'voting':['hard', 'soft'], | |
'weights':[(1,1,1,1,1), (2,1,1,1,1), | |
(1,2,1,1,1), (1,1,2,1,1), | |
(1,1,1,2,1), (1,1,1,1,2), | |
(1,1,1,2,2), (2,1,1,1,2)]} | |
#fit gridsearch & print best params | |
grid = GridSearchCV(vc, params) | |
grid.fit(X, y) |
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 | |
from sklearn.ensemble import VotingClassifier | |
from sklearn.model_selection import cross_val_score, GridSearchCV | |
#fit a base model | |
vc = VotingClassifier([('dt', DecisionTree), | |
('KNN', KNN), | |
('MLPC', MLPC), | |
('rf', RandomForest), | |
('xgb', XGB)]) |
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
def ThreeDplot(model): | |
"Creates TSNE model and plots it" | |
"Get the labels and vectors from ndoe2vec mode" | |
labels = [] | |
tokens = [] | |
for word in model.wv.vocab: | |
tokens.append(model[word]) | |
labels.append(word) |
NewerOlder