Skip to content

Instantly share code, notes, and snippets.

View drorhilman's full-sized avatar

Dror Hilman PhD drorhilman

View GitHub Profile
@drorhilman
drorhilman / jupyter_echarts.py
Last active January 17, 2024 17:48
A script to display echarts charts in jupyter notebook, both in notebook and in vscode!
# -- consts --
ECHARTS_CDN = "https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min"
ECHARTS_REQUIREJS_CONF = f"requirejs.config({{paths: {{echarts: '{ECHARTS_CDN}',}}}});"
ECHARTS_TEMPLATE = f"""
<div id="{{ID}}" style="width: {{WIDTH}};height:{{HEIGHT}};"></div>
<script type="module">
{ECHARTS_REQUIREJS_CONF}
requirejs(["echarts"], (echarts) => {{
let myChart = echarts.init(document.getElementById('{{ID}}'));
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from keras.layers import Dense, Dropout, Input, BatchNormalization
from keras.models import Model
def get_nn_model(dropout=0.6):
inp = Input(shape = (90,))
x = Dense(100, activation='relu')(inp)
x = BatchNormalization()(x)
x = Dropout(dropout)(x)
x = Dense(50, activation='relu')(x)
x = BatchNormalization()(x)
def is_nuc(nuc):
try:
n1, n2 = nuc.split(':')
if not n1 in 'ATGC' and n2 in 'ATGC':
return np.nan
else:
return nuc
except:
return np.nan
from sklearn.metrics import confusion_matrix
import seaborn as sns
forest.fit(x,y)
predict = forest.predict(x)
cm = pd.DataFrame(confusion_matrix(y, predict), columns=forest.classes_, index=forest.classes_)
sns.heatmap(cm)
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
forest = RandomForestClassifier(n_estimators=30, class_weight='balanced')
x = encoded[[c for c in encoded.columns if 'snp' in c]].values
y = classes.values
scores = cross_val_score(forest, x, y, cv=5)
scores.mean(), scores.std()