Skip to content

Instantly share code, notes, and snippets.

View jinhangjiang's full-sized avatar

Jinhang Jiang jinhangjiang

  • McKesson
View GitHub Profile
@jinhangjiang
jinhangjiang / f1.py
Last active September 13, 2023 22:33
transformers_linear_regression
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)
@jinhangjiang
jinhangjiang / boilerplate.py
Last active December 6, 2022 01:02
Demo of MoreThanSentiments
df['Boilerplate'] = mts.Boilerplate(sent_tok, n = 4, min_doc = 5, get_ngram = False)
@jinhangjiang
jinhangjiang / f1.py
Last active May 26, 2022 21:39
Instructions to publish python lib
from ._Class1 import Function1
from ._Class1 import Function2
from ._Class2 import Function1
...
@jinhangjiang
jinhangjiang / call_model.py
Last active May 17, 2022 04:15
Code Demo for Data2vec vs. SBERT on Text Classification
# Call Model
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels = num_labels).to("cuda")
@jinhangjiang
jinhangjiang / WeightedAverageEnsemble3.py
Last active November 15, 2021 00:53
WeightedAverageEnsemble3
##### AVERAGE
average_pred = (XGB_pred+
KNN_pred+
MLPC_pred+
RandomForest_pred+
DecisionTree_pred)/5
#make submission table
FiveModelAveragePrediction = pd.DataFrame(
{'QuoteNumber':df,
@jinhangjiang
jinhangjiang / WeightedAverageEnsemble2.py
Last active November 15, 2021 00:55
WeightedAverageEnsemble2
##### 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',
@jinhangjiang
jinhangjiang / WeightedAverageEnsemble1.py
Created November 15, 2021 00:47
WeightedAverageEnsemble1
#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
@jinhangjiang
jinhangjiang / votingclassifier2.py
Last active November 15, 2021 00:29
votingclassifier2
#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)
@jinhangjiang
jinhangjiang / votingclassifier1.py
Last active November 14, 2021 18:41
Voting Classifier in Python
#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)])
@jinhangjiang
jinhangjiang / 3DScatterGraph-2.py
Created June 25, 2021 09:44
Visualize High-Dimensional Network Data with 3D Scatter Plot
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)