Python ML App Challenge

Task: Summarize the given YouTube video transcript and classify it as Entertainment, Educational, or Other. If the transcript is Educational, provide a bulleted list of key points. If code is explained in the video, include it in a code block. Identify any mentioned models, tokenizers, embeddings, or other files, and create a list in the footer. Additionally, include the title of the transcript as a footer note. If the transcript is Educational, summarize the text with references and provide a list of references in the footer. Input: The input will be a transcript of a YouTube video. Output: Part 1: Classification: [Entertainment/Educational/Other]:{Title} Part 2: Summary: [Summary of the transcript] [Bulleted list of key points (if Educational)] [Code block (if applicable)] Footer: [(if applicable)Models, Tokenizers, Embeddings, Files mentioned:] [List of mentioned items, URL’s] References (if mentioned)(if Educational): [List of references] Create a list of Follow up questions for deeper learning:[Follow up Questions:]
Title: “I tried to build a Python Machine Learning Streamlit App in 7 Minutes | Coding Challenge”
Transcript: “what happened to the titanic was quite possibly one of the worst nautical disasters this millennium i mean rose could have saved jack we’ve seen the numbers mate that was last millennia that doesn’t stop us from using machine learning and streamline to build an amazing app what’s happening guys welcome to another episode of code that where i try to build machine learning apps in a ridiculously short time frame in this episode we are going to be building our very own streamlit and scikit-learn machine learning model and application that we’re going to be able to use to make predictions as to whether or not rose could have saved jack but before we do that let’s go ahead and take a look at the rules of code that so first and foremost we’re gonna have some constraints namely in this particular instance we are going to be having a time limit of seven minutes that’s less than my usual 15 and we all know how that’s gone in the past but nonetheless we shall progress second i’m not going to be able to look at any doco stacko aka stack overflow or any pre-existing code if i do it’s a one minute time penalty and last but not least if i don’t make that time limit it’s gonna be a 50 amazon gift card to you guys alrighty ready to do it let’s get to it all righty seven minutes on the clock let’s go okay so the first thing that we are going to need to do is create a new file and we’re going to call it app. pi then what we need to do is import a bunch of dependencies so we are going to import streamlit as st and then we are also going to import uh we’ve got a bunch of preprocessors inside of this utils.pi file so this is just part of building the machine learning model and i will share the machine learning model files with you if you guys want to test this out so we are going to uh from utils import prep pre-processor prep processor and then we are also going to import columns which just represents the different column orders that we’ve got within our machine learning model all right cool so those are those imported then we need to import numpy as mp we need to import pandas as pd and we are also going to import job lib import job lab all right uh and then think think think uh we then need to import our model so model equals job lib i’ve started using job joblib as of late it’s actually kind of nice so xgb pipe so this is an xgb classifier model so we are going to be able to punch in a bunch of different features from our user we’ll be able to collect them inside a streamlit and then run it to our xgb classifier okay so that is that we then need to save that and then let’s add a title so we can use st.title to title our app and we are going to call it a did they survive and then we the cool thing is you can add emojis in this you know i love a good emoji so we are going to do that we can add the emoji using the colon symbol and then the name of the emoji all right let’s start our app up so we can run streamlit app oh streamlit run app dot pi i’m just making sure we don’t cover that with my head cool so that is the beginnings of our app and it says do they survive so we are progressing at a good rate okay cool so that is happening so then what we need to do is add in a bunch of columns to handle all of the different features in our machine learning model so these are the columns that we’re going to need so passenger is the first one so we can add in st dot text input and we’re going to say a passenger input passenger id and we’ll just import a uh include a random number so one two three four five six for now right and if we refresh that cool so we can input our passenger id in here all good all right then the next one is the class so for that we’ll use the slider so st dot select slider and then we are going to say uh choose passenger plus and then we need an array and that array we need to close that and that array needs to include one two and three so these are going to be the different classes that our passenger would have potentially had cool all right so we can select those we’re looking good there all right what else let’s punch out a bunch all right so we need a name sex age so let’s grab those just minimize this all right so we then need st text input for our name so these are just different um components that you can add in so input the passengers name and then we’ll just add in a placeholder so john smith and then st dot uh what is it so this one’s male female so we can use select slider um select gender and then we’re going to have male in lower class female all right and the machine learning model is hand set up to handle these as well so like we’ve actually got a scikit-learn pipeline that’s driving all of this oh my gosh three minutes uh st dot um what is this select uh wait we just need a slider here and then input age and then we set the zero or the the low value st oh my gosh this web i is so much faster than i expected oh guys i don’t know if we’re gonna make this sd all right so we need another slide out for siblings input siblings and then that’s we’re gonna set that 0 to 10 number of parents and children oh no we need to set the values it was at this moment that he knew he flew no passenger id equals that um class equals that because we need to be able to uh store them in a variable passenger us and then this is going to be a name [Music] equals that and then make this a bit bigger again we’ll come back to that and then we need gender equals that and then age equals that and then sp equals that and then so that is that one done so these are just different features that we’d be passing through into our machine learning model so what’s this one number of parents children i’m going to set that between zero to two uh the ticket number is ticket id equals st dot uh number input i think yep all right uh ticket number and then we’ll just set one two three four five to begin with and then they’re fair so this is the fair amount st dot um let’s say st dot number input fair amount oh my god a minute left okay uh so zero to i don’t know 100 and then cabin equals st text input and we are going to say select or enter cabin at c52 uh we have undoubtedly got some errors in this uh whether or not they where they embarked from so this is churrborg queenstown or southampton st dot um oh what is it select box we’ll do that uh choose embarkation point i don’t know if i spelt that right we’re just going to assume uh so our options are going to be s see i really said we need to tighten up my typing all right that’s those features let’s save how’s this running [Music] all right we got i don’t think we were even close on that one all right all right let’s wrap this up so we’ve at least got all of our features done and we can collect all these features so if you actually take a look you can now drive all of these inputs we definitely needed more time on this particular challenge but that is okay guys this is part of the code that uh journey eventually your boy’s gonna hit some of these all right so but let’s wrap this up so then we need a button so we can type in st button and that is going to say predict and then we’re going to say on click equals predict and then this is going to have a function called predict and basically we’re going to take all these features in a particular order and we are going to be able to pass them through to our machine learning app so we can then go create a value called row and then set that equal to mp.array and then pass each one of these features in now order is important so we need to follow the order inside of this columns value here let me show you that yeah there was no way i was making all right so that’s passenger id and then we need p class which is passenger class and then we need name gender age sib sp ph and the cabin and whether or not they embark or where they embarked from right so that sets up a basic row so you can see that there we then throw it into a data frame so we’re going to call it x equals pd.data frame pass through the row you know what i reckon i’d make all of these if i just could type accurately all right columns equals and then we pass through columns and then we make a prediction so we go prediction equals uh model.predict pass through our x value and then grab the first prediction and then let’s just refresh that see how we’re looking all right so we’ve got did they survive and we’ve got a predict button down there so that’s looking all good i’ve just detached my zoomy thing right so you can see that we’ve got all of our features and then what we’ll do is say if prediction equals equals one that means they survived i believe they survived prediction um and then we are going to say st success and then we’re going to return passenger survived and then thumbs up and then else st error passenger did not survive and then we can do uh throwing an emoji thumbs down all right cool let’s run that all right so let’s refresh we hit predict you can see passenger did not survive so you can see that’s making a prediction so if we change a bunch of these features set it’s female input the number of siblings uh input the parent number of parents children change the amount or the fair let’s set that to 125 predict so in this case a passenger would survive so this shows you in a super fast nutshell how to go ahead and build your very own streamlink app but you could hook this up to just about any other scikit-learn model anyway in this particular case we did not make the challenge so here is the amazon gift card again whoever gets it first manages to claim it thanks again for tuning in guys hopefully you enjoyed this one peace thanks so much for tuning in guys hopefully you’ve enjoyed this video if you have be sure to give it a big thumbs up hit subscribe and tick that bell and let me know how you found this particular episode of code that i got a bunch more coming next week so tune in then”

Part 1: Classification: [Educational]: “I tried to build a Python Machine Learning Streamlit App in 7 Minutes | Coding Challenge”

Part 2: Summary:
The video is a coding challenge where the host attempts to build a Python machine learning Streamlit app in just seven minutes. The challenge involves creating a machine learning model using Scikit-learn and Streamlit to predict whether or not a person would have survived the Titanic disaster. The host explains the rules of the challenge, which include a time limit, no access to external resources or pre-existing code, and a penalty for exceeding the time limit.

In the video, the host starts by creating a new file called `app.py` and imports the necessary dependencies, including Streamlit, preprocessors from a `utils.py` file, NumPy, Pandas, and Joblib. The model used is an XGBoost classifier. The host then adds a title to the app using `st.title` and sets it as “Did They Survive” with an emoji. The app is run using `streamlit run app.py`.

Next, the host adds various input components for the different features of the machine learning model, such as passenger ID, class, name, gender, age, siblings, number of parents and children, ticket number, fare amount, cabin, and the point of embarkation. These inputs are added using Streamlit’s input components like `st.text_input`, `st.select_slider`, and `st.number_input`. The inputs are collected and stored in variables.

After setting up the input components, the host adds a button with the label “Predict” using `st.button` and assigns a function called `predict` to handle the click event. Inside the `predict` function, the host creates an array of the input values in the correct order specified by the columns of the machine learning model. The array is converted into a DataFrame and passed to the model for prediction. The predicted value is then displayed on the app, indicating whether the passenger would have survived or not.

The host acknowledges that the challenge was difficult and mentions that there were errors and mistakes made during the time constraint. However, the video serves as a demonstration of building a Streamlit app for machine learning prediction using Scikit-learn.

Footer: Files mentioned:
– `utils.py` (preprocessors file)
– Models: XGBoost classifier
– Tokenizers: N/A
– Embeddings: N/A

Follow-up Questions:
1. How does Streamlit help in building machine learning apps?
2. What other machine learning models could be used instead of XGBoost in this app?
3. How can you improve the accuracy of the machine learning model used in the app?
4. Can Streamlit be used for real-time predictions?
5. What are the limitations of the app built in this video?
There is enough code mentioned to write an requirements.txt file and a app.py please do so
requirements.txt:
“`
streamlit
scikit-learn
numpy
pandas
joblib
xgboost
“`

app.py:
“`python
import streamlit as st
import numpy as np
import pandas as pd
import joblib

from utils import preprocessor
from utils import columns

# Load the trained model
model = joblib.load(‘model.pkl’)

# Create the Streamlit app
def main():
st.title(“Did They Survive 👍👎”)
st.write(“Enter passenger details to predict survival.”)

# Input components for passenger details
passenger_id = st.text_input(“Passenger ID”, value=”123456″)
p_class = st.select_slider(“Class”, options=[1, 2, 3], value=1)
name = st.text_input(“Name”, value=”John Smith”)
gender = st.select_slider(“Gender”, options=[“Male”, “Female”], value=”Male”)
age = st.slider(“Age”, min_value=0, max_value=100, value=30)
siblings = st.slider(“Number of Siblings”, min_value=0, max_value=10, value=0)
parents_children = st.slider(“Number of Parents/Children”, min_value=0, max_value=10, value=0)
ticket_number = st.number_input(“Ticket Number”, value=12345)
fare_amount = st.number_input(“Fare Amount”, value=0.0)
cabin = st.text_input(“Cabin”, value=”C52″)
embarkation_point = st.selectbox(“Embarkation Point”, options=[“Cherbourg”, “Queenstown”, “Southampton”], index=0)

# Create a row with the input values
row = np.array([passenger_id, p_class, name, gender, age, siblings, parents_children, ticket_number, fare_amount, cabin, embarkation_point])

# Create a DataFrame from the row
x = pd.DataFrame([row], columns=columns)

# Make a prediction using the model
prediction = model.predict(x)[0]

# Display the prediction
if prediction == 1:
st.success(“Passenger Survived 👍”)
else:
st.error(“Passenger Did Not Survive 👎”)

if __name__ == “__main__”:
main()
“`

Please note that in the `app.py` file, the model (`model.pkl`) and the `utils.py` file are assumed to be present in the same directory as the `app.py` file. You would need to adjust the file paths accordingly if they are located in different directories.