Skip to content

Instantly share code, notes, and snippets.

View pyjaime's full-sized avatar
🎯
Focusing

Jaime Durán pyjaime

🎯
Focusing
View GitHub Profile
@pyjaime
pyjaime / word_cloud_example.py
Last active April 29, 2019 20:09
word_cloud
from wordcloud import WordCloud, ImageColorGenerator
from PIL import Image
from stop_words import get_stop_words
stopwords = get_stop_words('es')
mask = np.array(Image.open('img/logo/vox.png'))
wc = WordCloud(background_color="white", max_words=300, mask=mask,
width=900, height=450, min_font_size=7, max_font_size=100,
stopwords=stopwords, collocations=True, normalize_plurals=True,
@pyjaime
pyjaime / plotly_express_hbar_example.py
Created April 30, 2019 08:20
Creation of an horizontal bar chart with plotly_express, from a pandas dataframe
px.bar(
cis_df, x="concern", y="problem", template="plotly_white",
labels=dict(concern="% of respondents for whom the problem is Top 3", problem="Problem"),
width=970, height=800, title="Main (3) concerns of spanish people [March 2019]",
orientation='h'
)
@pyjaime
pyjaime / seaborn_table_heatmap_example.py
Created April 30, 2019 08:26
A table visualization using seaborn's heatmap function
plt.figure(figsize=(8,11))
ax = sns.heatmap(df.T, annot=True, fmt='d', cmap='Blues', cbar=False, linecolor='white', linewidths=2)
ax.tick_params(labelbottom=True, labeltop=True, labelsize=13, labelcolor='black')
ax.set_title('\nOccurrences of topic-related key words on each electoral program\n\n',
fontsize=16);
@pyjaime
pyjaime / seaborn_table_heatmap_example2.py
Created April 30, 2019 08:33
A table visualization using all seaborn's heatmap() potential
ax = sns.heatmap(df_rel.T.round(3), annot=True, fmt='g', cmap='Blues', linecolor='white', linewidths=1)
@pyjaime
pyjaime / pandas_barh_example.py
Created April 30, 2019 08:45
Horizontal Bars visualization for a pandas dataframe
ax = df_rel.T.plot(kind='barh', figsize=(11,30), fontsize=13)
@pyjaime
pyjaime / image_data_bunch_from_df.py
Last active June 3, 2019 16:45
Create a dataset from a pandas dataframe using ImageNet structure
data = ImageDataBunch.from_df(
df=df_styles, path=pictures_dir, label_col='style', fn_col='new_filename',
ds_tfms=get_transforms(), size=299, bs=48).normalize(imagenet_stats)
@pyjaime
pyjaime / cnn_fit_stage1.py
Last active June 3, 2019 17:04
Fit a CNN using 1cycle policy (fastai)
learner = cnn_learner(data, models.resnet50, metrics=[error_rate])
learner.fit_one_cycle(6)
@pyjaime
pyjaime / lr_finder.py
Created June 3, 2019 17:12
LR finder in fastai
learner.lr_find()
learner.recorder.plot()
@pyjaime
pyjaime / cnn_fit_stage2.py
Created June 3, 2019 17:19
1cycle fit - 2nd stage (fastai)
learner.unfreeze()
learner.fit_one_cycle(7, max_lr=slice(1e-6,3e-4))
@pyjaime
pyjaime / learner_predict.py
Created June 4, 2019 12:13
fastai's learner prediction for a single image
img = open_image('data/the_scream.jpg')
pred = learner.predict(img); pred