Skip to content

Instantly share code, notes, and snippets.

View AmolMavuduru's full-sized avatar

Amol Mavuduru AmolMavuduru

View GitHub Profile
@AmolMavuduru
AmolMavuduru / train_model.py
Created May 12, 2021 14:32
Function that trains a simple CNN on an input dataset. This function is designed for the MNIST Dataset.
def train_model(X_train, y_train, X_test, y_test):
model = Sequential()
model.add(Conv2D(kernel_size=(3, 3), filters=32,
input_shape=input_shape))
model.add(Activation('relu'))
model.add(Conv2D(kernel_size=(3, 3), filters=32))
model.add(Activation('relu'))
model.add(MaxPooling2D(2, 2))
@AmolMavuduru
AmolMavuduru / main.py
Created March 17, 2021 19:02
FastAPI app code for my Medium article "How you can quickly deploy your ML models with FastAPI"
import joblib
import re
from sklearn.neural_network import MLPClassifier
from sklearn.feature_extraction.text import TfidfVectorizer
from fastapi import FastAPI
app = FastAPI()
model = joblib.load('spam_classifier.joblib')
@AmolMavuduru
AmolMavuduru / train_spam_detector.py
Created March 15, 2021 21:37
Model training code for my Medium article: How you can quickly deploy your ML models with FAST API
import numpy as np
import pandas as pd
# Read the Data
data = pd.read_csv('./data/spam_data.csv')
# Text Preprocessing
import re # regex library
@AmolMavuduru
AmolMavuduru / streamlit_app.py
Created March 9, 2021 21:05
Streamlit app for my article: "How you can quickly build ML web apps with Streamlit."
import joblib
import re
from sklearn.neural_network import MLPClassifier
from sklearn.feature_extraction.text import TfidfVectorizer
import streamlit as st
from lime.lime_text import LimeTextExplainer
import streamlit.components.v1 as components
st.write("# Spam Detection Engine")
@AmolMavuduru
AmolMavuduru / train_spam_classifier.py
Last active March 9, 2021 15:02
Code for training and saving a spam classifier in Python.
import numpy as np
import pandas as pd
# Read the Data
data = pd.read_csv('./data/spam_data.csv')
# Text Preprocessing
import re # regex library
@AmolMavuduru
AmolMavuduru / recommend_songs.py
Last active January 21, 2021 22:45
Functions for generating song recommendations using Spotify data. Sample code for my Medium article: "How to build an amazing music recommendation algorithm."
from collections import defaultdict
from scipy.spatial.distance import cdist
import difflib
number_cols = ['valence', 'year', 'acousticness', 'danceability', 'duration_ms', 'energy', 'explicit',
'instrumentalness', 'key', 'liveness', 'loudness', 'mode', 'popularity', 'speechiness', 'tempo']
def get_song_data(song, spotify_data):
"""
@AmolMavuduru
AmolMavuduru / find_song.py
Created January 21, 2021 18:02
Function for finding Spotify songs. Sample code for my Medium article: "How to build an amazing music recommendation algorithm."
from spotipy.oauth2 import SpotifyClientCredentials
from collections import defaultdict
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=os.environ["SPOTIFY_CLIENT_ID"],
client_secret=os.environ["SPOTIFY_CLIENT_SECRET"]))
def find_song(name, year):
"""
@AmolMavuduru
AmolMavuduru / recommend_next_movies.py
Created January 7, 2021 22:56
Sample code for my Medium article "How to build powerful deep recommender systems using Spotlight".
"""
Utility functions for generating movie recommendations using sequence models.
"""
import difflib
def get_movie_id(movie_title, metadata):
"""
Gets the movie id for a movie title
"""
@AmolMavuduru
AmolMavuduru / recommend_movies.py
Created January 7, 2021 22:43
Sample code for my Medium article "How to build powerful deep recommender systems using Spotlight".
"""
Utility functions for generating movie recommendations using matrix factorization models
"""
def get_metadata(movie_id, metadata):
"""
Retrieves the metadata for a movie given the movie ID
"""
movie_data = metadata[metadata['movieId'] == movie_id]
return movie_data[['original_title', 'release_date', 'genres']].to_dict(orient='records')
@AmolMavuduru
AmolMavuduru / generate_recommendation.py
Last active December 23, 2020 17:23
Sample code for my Medium article: "How you can build recommender systems with Surprise."
import difflib
import random
def get_book_id(book_title, metadata):
"""
Gets the book ID for a book title based on the closest match in the metadata dataframe.
"""
existing_titles = list(metadata['title'].values)