Skip to content

Instantly share code, notes, and snippets.

View drorhilman's full-sized avatar

Dror Hilman PhD drorhilman

View GitHub Profile
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()
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)
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 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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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}}'));
import os
import subprocess
from moviepy.editor import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from tqdm import tqdm
import imageio
from rich.progress import track, SpinnerColumn, Progress
from rich import print