Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How I Built and Deployed a Python Loan Eligibility Prediction App on Streamlit

#1
How I Built and Deployed a Python Loan Eligibility Prediction App on Streamlit

<div>
<div class="kk-star-ratings kksr-auto kksr-align-left kksr-valign-top" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1080976&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;2&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;4.5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;4.5\/5 - (2 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;128&quot;,&quot;_legend&quot;:&quot;{score}\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 128px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 4.5/5 – (2 votes) </div>
</p></div>
<p>In this tutorial, I will walk you through a machine-learning project on <strong>Loan Eligibility Prediction</strong> with Python. Specifically, I will show you how to create and deploy machine learning web applications using <a href="https://streamlit.io/" data-type="URL" data-id="https://streamlit.io/" target="_blank" rel="noreferrer noopener">Streamlit</a>.</p>
<p>Streamlit makes it easy for data scientists with little or no knowledge of web development to develop and deploy machine learning apps quickly. Its compatibility with data science libraries makes it an excellent choice for data scientists looking to deploy their applications.</p>
<p><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f449.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> You can <a href="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" data-type="URL" data-id="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" target="_blank" rel="noreferrer noopener">try the live demo app here</a>:</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" target="_blank" rel="noreferrer noopener"><img decoding="async" loading="lazy" width="1014" height="955" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-305.png" alt="" class="wp-image-1084225" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-305.png 1014w, https://blog.finxter.com/wp-content/uplo...00x283.png 300w, https://blog.finxter.com/wp-content/uplo...68x723.png 768w" sizes="(max-width: 1014px) 100vw, 1014px" /></a></figure>
</div>
<h2>Prerequisites</h2>
<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="683" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-255-1024x683.png" alt="" class="wp-image-1075808" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-255-1024x683.png 1024w, https://blog.finxter.com/wp-content/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x512.png 768w, https://blog.finxter.com/wp-content/uplo...ge-255.png 1282w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p>Although I will try my best to explain some concepts and the steps I took in this project, I assumed you already have a <a href="https://blog.finxter.com/python-crash-course/" data-type="post" data-id="3951" target="_blank" rel="noreferrer noopener">basic knowledge of Python</a> and its application in machine learning.</p>
<p>For Streamlit, I will only explain the concepts that have a bearing on this project. If you want to know more, you can check the documentation.</p>
<h2>Loan Eligibility Prediction</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="810" height="591" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-282.png" alt="" class="wp-image-1081016" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-282.png 810w, https://blog.finxter.com/wp-content/uplo...00x219.png 300w, https://blog.finxter.com/wp-content/uplo...68x560.png 768w" sizes="(max-width: 810px) 100vw, 810px" /></figure>
</div>
<p>Banks and other financial institutions give out loans to people. But before they approve the loan, they have to make sure the applicant is eligible to receive the loan. There are many factors to consider before deciding whether or not the applicant is eligible for the loan. Such factors are but not limited to credit history and the applicant’s income.</p>
<p>To automate the loan approval process, banks and other financial institutions require the applicant to fill in a form in which some personal information will be gathered. These include gender, education, credit history, and so on. An applicant’s loan request will either be approved or rejected based on such information.</p>
<p>In this project, we are going to build a Streamlit dashboard where our users will fill in their details and check if they are eligible for a loan or not. This is a <a href="https://blog.finxter.com/cheat-sheet-6-pillar-machine-learning-algorithms/" data-type="post" data-id="2613" target="_blank" rel="noreferrer noopener">classification problem</a>. Hence, we will use machine learning with Python and a dataset containing information on customers’ past transactions to solve the problem. So, let’s get started.</p>
<h2>The Dataset</h2>
<p>Let’s load <a href="https://github.com/finxter/loan_predicition" data-type="URL" data-id="https://github.com/finxter/loan_predicition" target="_blank" rel="noreferrer noopener">our dataset</a> using the <a href="https://blog.finxter.com/pandas-quickstart/" data-type="post" data-id="16511" target="_blank" rel="noreferrer noopener">Pandas</a> library.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pandas as pd
data = pd.read_csv('LoanApprovalPrediction.csv')
data.shape
# (598, 13)</pre>
<p>Our dataset contains 598 rows and 13 columns. Using the <code>.info()</code> method, we can get more information about the dataset.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data.info()</pre>
<p>We can see all the columns that make up the dataset. If you view the first five rows using <code>data.head()</code>, you will notice that some columns are categorical but their datatypes are shown as object. More on this soon. Let’s check if there are missing values.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data.isna().sum()</pre>
<p>Output:</p>
<pre class="wp-block-preformatted"><code>Loan_ID 0
Gender 0
Married 0
Dependents 12
Education 0
Self_Employed 0
ApplicantIncome 0
CoapplicantIncome 0
LoanAmount 21
Loan_Amount_Term 14
Credit_History 49
Property_Area 0
Loan_Status 0
dtype: int64</code></pre>
<p>Wow! Our dataset contains lots of missing values. We have a lot of data cleaning to do. Finally, let’s check if our <code>Loan_ID</code> contains duplicates.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data.Loan_ID.nunique()
# 598</pre>
<p><code>Loan_ID</code> has the exact number of rows. No duplicates. So, we can safely drop it as it will not be used for training.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># Dropping Loan_ID column
data.drop(['Loan_ID'], axis=1, inplace=True)
</pre>
<p>By setting the <code>inplace</code> parameter to <code>True</code>, we want the change to be directly applied to our dataset. The <code>axis=1</code> parameter corresponds to the column side. It’s now time to clean and prepare our dataset for training.</p>
<h2>Data Cleaning and Preparation</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="810" height="540" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-283.png" alt="" class="wp-image-1081022" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-283.png 810w, https://blog.finxter.com/wp-content/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x512.png 768w" sizes="(max-width: 810px) 100vw, 810px" /></figure>
</div>
<p>Seeing that our dataset contains many missing values, we have several options to choose from. It is either we drop the missing rows or we fill them up with a given value. To determine which action to take, let’s first check the total number of missing values.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data.isna().sum().sum()
# 96</pre>
<p>The dataset contains 96 missing values representing 16% of our dataset, a not-so-insignificant number indeed. I choose to fill them up instead of dropping them. Let’s fill them up with the mean value of their respective columns.</p>
<p>Oh! We can’t fill in a number in a categorical column. So, we will first convert the categorical columns to int datatype.</p>
<p>For this, we can choose to use Pandas’ <code>map</code> function or use <code>LabelEncoder</code> from the <a href="https://blog.finxter.com/scikit-learn-cheat-sheets/" data-type="post" data-id="20549" target="_blank" rel="noreferrer noopener">Scikit-learn</a> library.</p>
<p>If we use the Pandas’ <code>map</code> function, we will repeat the same process for every categorical column. If you are like me and don’t like constant repetition (DRY), you will choose the second option.</p>
<p>This, though, does not rule out the importance of Pandas’ <code>map</code> function. Therefore, to show its importance and to add to your knowledge, let me show you how to apply it to our dataset.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data.Gender = data.Gender.map({'Male': 0, 'Female':1})</pre>
<p>With that, the Gender column gets converted to <code>int</code> datatype. You will have to do it to all the columns involved. But since we are changing all our categorical columns to a binary number, we have to follow the easy way using <code>LabelEncoder</code>.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
obj = (data.dtypes == 'object')
for col in list(obj[obj].index): data[col] = label_encoder.fit_transform(data[col])
</pre>
<p>We want to select only the columns with the datatype as object. We started by creating a Boolean in line 12 which returns <code>True</code> to object datatypes. Then in line 13, we perform what we call a Boolean mask. This filters out only the columns with the <code>object</code> datatype and transforms them to a binary number in each iteration.</p>
<p>You can confirm it using the <code>.info()</code> method and you will see that all our categorical columns have been converted to <code>int</code> datatype. Having done that, we can now fill in the missing values.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">for col in data.columns: data[col] = data[col].fillna(data[col].mean())</pre>
<p>We fill in the missing rows with the mean value of their respective columns. Again, you can confirm it by typing <code>data.isnull().sum()</code> or <code>data.isna().sum()</code>.</p>
<h2>Model Training</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="810" height="540" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-284.png" alt="" class="wp-image-1081024" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-284.png 810w, https://blog.finxter.com/wp-content/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x512.png 768w" sizes="(max-width: 810px) 100vw, 810px" /></figure>
</div>
<p>It’s now time to train our data using selected models. We will first divide our model into two: features (<code>x</code>) and target (<code>y</code>) variables.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">x = data.drop(['Loan_Status'], axis=1)
y = data.Loan_Status</pre>
<p>For each variable, we divide further into two for training and testing the model using <code>train_test_split</code> from Scikit-Learn.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=7)
</pre>
<p>We reserved 30% of our dataset for testing the model. By setting a <code>random_state</code> to a given number, we ensure we get the same set of data whenever the code is run. It’s now time to select a model.</p>
<p>We don’t know what algorithm or model will do well on our dataset. For this reason, we will test our data with different models and select the model with the highest accuracy score.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import RidgeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
form sklearn.ensembles import RandomForestClassifier models = []
models.append(('LR', LogisticRegression(max_iter=1000)))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier()))
models.append(('CART', DecisionTreeClassifier()))
models.append(('NB', GaussianNB()))
models.append((‘SVC’, SVC()))
models.append(('RC', RidgeClassifier()))
models.append(('RF', RandomForestClassifier())) def modeling(model): model.fit(x_train, y_train) y_pred = model.predict(x_test) return accuracy_score(y_test, y_pred) * 100 for name, model in models: print(f'{name} = {modeling(model)}') LR = 80.83333333333333
LDA = 82.5
KNN = 63.74999999999999
CART = 68.33333333333333
NB = 81.66666666666667
SVC = 69.16666666666667
RC = 82.91666666666667
RF = 81.66666666666667
</pre>
<p>The result shows that Ridge Classifier performs more than the models, followed by <strong><em>Linear Discriminant Analysis</em></strong> with only a slight difference. Both could benefit from further study. </p>
<p>However, we will use the Ridge Classifier algorithm.</p>
<p>Here is the full code. Save the model as <code>model.py</code>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.linear_model import RidgeClassifier
from sklearn.metrics import accuracy_score
import pickle # load the data
data = pd.read_csv('LoanApprovalPrediction.csv')
# Drop Loan_ID column
data.drop(['Loan_ID'], axis=1, inplace=True)
# convert to int datatype
label_encoder = LabelEncoder()
obj = (data.dtypes == 'object')
for col in list(obj[obj].index): data[col] = label_encoder.fit_transform(data[col]) # fill in missing rows
for col in data.columns: data[col] = data[col].fillna(data[col].mean())
# divide model into features and target variable
x = data.drop(['Loan_Status'], axis=1)
y = data.Loan_Status # divide into training and testing data
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=7)
# define the model
model = RidgeClassifier()
# fit the model on the training data
model.fit(x_train, y_train)
#save the train model
with open('train_model.pkl', mode='wb') as pkl: pickle.dump(model, pkl)
</pre>
<p>By saving our model in a pickle file, it can easily be called to make predictions, thus saving ourselves the time of waiting for the model to get trained each time it’s run.</p>
<h2>Preparing Streamlit Dashboard</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="810" height="539" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-285.png" alt="" class="wp-image-1081026" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-285.png 810w, https://blog.finxter.com/wp-content/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x511.png 768w" sizes="(max-width: 810px) 100vw, 810px" /></figure>
</div>
<p>Now that we are done with training our model. Let’s prepare the Streamlit interface. We will start by defining our main function. Since we also want it to run when we open the Streamlit app, we will call it using the <code>__name__</code> variable. Save this script with the name <code>app.py</code>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import streamlit as st def main(): bg = """&lt;div style='background-color:black; padding:13px'> &lt;h1 style='color:white'>Streamlit Loan Elgibility Prediction App&lt;/h1> &lt;/div>""" st.markdown(bg, unsafe_allow_html=True) left, right = st.columns((2,2)) gender = left.selectbox('Gender', ('Male', 'Female')) married = right.selectbox('Married', ('Yes', 'No')) dependent = left.selectbox('Dependents', ('None', 'One', 'Two', 'Three')) education = right.selectbox('Education', ('Graduate', 'Not Graduate')) self_employed = left.selectbox('Self-Employed', ('Yes', 'No')) applicant_income = right.number_input('Applicant Income') coApplicantIncome = left.number_input('Coapplicant Income') loanAmount = right.number_input('Loan Amount') loan_amount_term = left.number_input('Loan Tenor (in months)') creditHistory = right.number_input('Credit History', 0.0, 1.0) propertyArea = st.selectbox('Property Area', ('Semiurban', 'Urban', 'Rural')) button = st.button('Predict') # if button is clicked if button: # make prediction result = predict(gender, married, dependent, education, self_employed, applicant_income, coApplicantIncome, loanAmount, loan_amount_term, creditHistory, propertyArea) st.success(f'You are {result} for the loan')
</pre>
</p>
<p>We imported the Streamlit library. Then, we added color using HTML tags and since Python does not recognize such, we used the parameter <code>unsafe_allow_html</code> to make it to be recognized, without which the black color will not appear.</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" target="_blank" rel="noreferrer noopener"><img decoding="async" loading="lazy" width="731" height="411" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-280.png" alt="" class="wp-image-1081000" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-280.png 731w, https://blog.finxter.com/wp-content/uplo...00x169.png 300w" sizes="(max-width: 731px) 100vw, 731px" /></a></figure>
</div>
<p>We displayed several text boxes, and select boxes to get data from our users which will, in turn, be used to make predictions. </p>
<p>Notice that we used the exact data found in the datasets including their features. Since we have already transformed the categorical columns to <code>int</code> datatypes, you may have to reload the dataset and use the <code>.value_counts()</code> method on each column to see the features. </p>
<p>Let’s now define our <code>predict()</code> function.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># load the train model
with open('train_model.pkl', 'rb') as pkl: train_model = pickle.load(pkl) def predict(gender, married, dependent, education, self_employed, applicant_income, coApplicantIncome, loanAmount, loan_amount_term, creditHistory, propertyArea): # processing user input gen = 0 if gender == 'Male' else 1 mar = 0 if married == 'Yes' else 1 dep = float(0 if dependent == 'None' else 1 if dependent == 'One' else 2 if dependent == 'Two' else 3) edu = 0 if education == 'Graduate' else 1 sem = 0 if self_employed == 'Yes' else 1 pro = 0 if propertyArea == 'Semiurban' else 1 if propertyArea == 'Urban' else 2 Lam = loanAmount / 1000 cap = coApplicantIncome / 1000 # making predictions prediction = train_model.predict([[gen, mar, dep, edu, sem, applicant_income, coApplicantIncome, Lam, loan_amount_term, creditHistory, pro]]) verdict = 'Not Eligible' if prediction == 0 else 'Eligible' return verdict
</pre>
<p>The <code>predict()</code> function has all the features of our dataset. Then, we used a <a rel="noreferrer noopener" href="https://blog.finxter.com/python-one-line-ternary/" data-type="post" data-id="10641" target="_blank">t</a><a href="https://blog.finxter.com/python-one-line-ternary/" data-type="post" data-id="10641" target="_blank" rel="noreferrer noopener">ernary</a><a rel="noreferrer noopener" href="https://blog.finxter.com/python-one-line-ternary/" data-type="post" data-id="10641" target="_blank"> operator</a> to change the user input into a number. Notice that we <a href="https://blog.finxter.com/python-float-function/" data-type="post" data-id="22782" target="_blank" rel="noreferrer noopener">converted</a> the <code>dep</code> variable to a float. We did all these things to ensure they correspond to the datatype in our datasets.</p>
<p>Also, we made sure that the order in which we placed our parameters both at the beginning and end of the function corresponds with the one in the <code>main()</code> function. Anything contrary will either lead to an error or poor prediction.</p>
<p>Why did we divide the <code>loanAmount</code> and <code>coApplicantIncome</code> by 1,000? Well, I will leave that to you to answer. Just to give you a little hint, type this, <code>data.loanAmount.describe()</code>, and see if you can figure it out yourself.</p>
<h2>Conclusion</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="810" height="541" src="https://blog.finxter.com/wp-content/uploads/2023/01/image-286.png" alt="" class="wp-image-1081031" srcset="https://blog.finxter.com/wp-content/uploads/2023/01/image-286.png 810w, https://blog.finxter.com/wp-content/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x513.png 768w" sizes="(max-width: 810px) 100vw, 810px" /></figure>
</div>
<p>This is how we come to the end of this tutorial. </p>
<p>You have learned how to apply machine learning to a classification problem such as loan prediction. </p>
<p>You also learned how to create an interactive dashboard using Streamlit. Now, to deploy it on Streamlit Cloud so that others can use it, sign up on Streamlit and GitHub if you haven’t done so. </p>
<p>Check my <a rel="noreferrer noopener" href="https://github.com/finxter/loan_predicition" data-type="URL" data-id="https://github.com/finxter/loan_predicition" target="_blank">GitHub page</a> for the full code. Create a repository and deploy it to Streamlit Cloud. You can <a rel="noreferrer noopener" href="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" data-type="URL" data-id="https://jonaben1-loan-predicition-app-bnti80.streamlit.app/" target="_blank">view my live demo app here</a>. In a future article, I will show you how to use machine learning to solve a regression problem. Alright, have a nice day.</p>
</div>


https://www.sickgaming.net/blog/2023/01/...streamlit/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016