Skip to content

Instantly share code, notes, and snippets.

@foohm71
foohm71 / txt-setup.py
Created January 7, 2021 17:19
text similarity setup
from google.colab import drive
drive.mount('/content/gdrive')
import gensim
from gensim.models import KeyedVectors
import numpy as np
import pandas as pd
import nltk
from nltk import word_tokenize
@foohm71
foohm71 / functions.py
Created September 12, 2020 00:55
Common functions
def make_autopct(values):
def my_autopct(pct):
total = sum(values)
val = int(round(pct*total/100.0))
return '{p:.1f}% ({v:d})'.format(p=pct,v=val)
return my_autopct
def plotPieChart(column):
freq_count = Counter(df[column])
fig, ax = plt.subplots(figsize=(15, 7), subplot_kw=dict(aspect="equal"))
@foohm71
foohm71 / main.py
Created September 12, 2020 00:49
Imports for survey results
import pandas as pd
import matplotlib.pylab as plt
import numpy as np
from collections import Counter
from wordcloud import WordCloud, STOPWORDS
from gensim.summarization.summarizer import summarize
from gensim.summarization import keywords
from IPython.display import display, Markdown
@foohm71
foohm71 / evaluate.py
Created July 27, 2020 03:27
Evaluate model
from sklearn.metrics import confusion_matrix
import matplotlib.pylab as plt
# Train/Test split was done earlier hence I just need to use Xtest and Ytest
result = []
for feature in Xtest:
p = get_prediction(feature, model_name)
result.append(p.payload[0].display_name)
labels = ['Optional', 'Trivial', 'Minor', 'Major', 'Critical', 'Blocker']
@foohm71
foohm71 / convert.py
Created July 27, 2020 01:26
AutoML conversion
# write training data function
def write_training_data_to_zipfile(path, Xdata, Ydata):
os.chdir(path)
count = {}
num_rows = Xdata.shape[0]
for i in range(1,num_rows):
label = Ydata.iloc[i]
feature = Xdata.iloc[i]
folder = path + "/" + label
if not os.path.exists(folder):
@foohm71
foohm71 / main.py
Created July 27, 2020 01:24
AppEngine code
# [START gae_python38_app]
from flask import Flask, request
import sys
import os
from google.api_core.client_options import ClientOptions
from google.cloud import automl_v1
from google.cloud.automl_v1.proto import service_pb2
# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.