Skip to content

Commit

Permalink
deploy: c5e7875
Browse files Browse the repository at this point in the history
  • Loading branch information
hathawayj committed Feb 29, 2024
1 parent 3b5ce78 commit 77b4089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.html

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions slides/p4/d2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class=navbar-toggler-icon></span></button><div class="collapse navbar-collapse text-center" id=navigation><ul class="navbar-nav ml-auto"><li class=nav-item><a class="nav-link text-dark" href=/DS250-Cannon>Home</a></li><li class=nav-item><a class="nav-link text-dark" href=/DS250-Cannon/projects>Projects</a></li><li class=nav-item><a class="nav-link text-dark" href=/DS250-Cannon/contact>Contact</a></li><li class=nav-item><a class="nav-link text-dark" href=/DS250-Cannon/course-materials>Materials</a></li><li class="nav-item dropdown"><a class="nav-link dropdown-toggle text-dark" href=# role=button data-toggle=dropdown aria-haspopup=true aria-expanded=false>Navigate</a><div class=dropdown-menu><a class=dropdown-item href=/DS250-Cannon/slides>Slides</a>
<a class=dropdown-item href=/DS250-Cannon/course-materials/syllabus/>Syllabus</a>
<a class=dropdown-item href=/DS250-Cannon/faq>FAQ</a></div></li></ul></div></div></nav></header><section class="single section-sm pb-0"><div class=container><div class=row><div class=col-lg-3><div class=sidebar><ul class=list-styled><a class=back-btn href=/DS250-Cannon></a><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/ title=Slides class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/>Slides</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p4/ title="Week 8-9: Project 4 - Homes" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p4/>Week 8-9: Project 4 - Homes</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p4/d2/ title="Day 2: Intro to Machine Learning" class="sidelist
active"><a href=https://byuistats.github.io/DS250-Cannon/slides/p4/d2/>Day 2: Intro to Machine Learning</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p4/d1/ title="Day 1: Intro to ML" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p4/d1/>Day 1: Intro to ML</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/ title="Week 6-7: Project 3 - Baseball" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/>Week 6-7: Project 3 - Baseball</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d4/ title="Day 4: Practice Coding Challenge" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d4/>Day 4: Practice Coding Challenge</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d3/ title="Day 3: The end of baseball" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d3/>Day 3: The end of baseball</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d2/ title="Day 2: SQL Calculations" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d2/>Day 2: SQL Calculations</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d1/ title="Day 1: Intro to Project 3" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d1/>Day 1: Intro to Project 3</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/ title="Week 4-5: Project 2 - Flights" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/>Week 4-5: Project 2 - Flights</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d4/ title="Day 4: Exporting JSON" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d4/>Day 4: Exporting JSON</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d3/ title="Day 2B: Missing Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d3/>Day 2B: Missing Data</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d2/ title="Day 2: Transforming Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d2/>Day 2: Transforming Data</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d1/ title="Day 1: Intro to Flights Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d1/>Day 1: Intro to Flights Data</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/ title="Week 2-3: Project 1 - Names" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/>Week 2-3: Project 1 - Names</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d3/ title="Day 3: Making your name stand out" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d3/>Day 3: Making your name stand out</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d2/ title="Day 2: Seeing names with Altair" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d2/>Day 2: Seeing names with Altair</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d1/ title="Day 1: Exploring names with pandas" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d1/>Day 1: Exploring names with pandas</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/ title="Week 1: Introduction" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/>Week 1: Introduction</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/day02/ title="Day 2: Project 0" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/day02/>Day 2: Project 0</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/day01/ title="Day 1: Welcome" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/day01/>Day 1: Welcome</a></li></ul></li></ul></li></ul></div></div><div class=col-lg-9><div class="p-lg-5 p-4 bg-white"><h2 class=mb-5>Day 2: Intro to Machine Learning</h2><div class=content><h2 id=welcome-to-class>Welcome to class!</h2><h4 id=announcements>Announcements</h4><h4 id=spiritual-thought>Spiritual thought</h4><h5 id=are-facts-true>Are facts true?</h5><br><ul><li>How do you distinguish between truth and error?</li><li>Joshua and Caleb</li></ul><br><h2 id=building-a-decision-tree>Building a Decision Tree</h2><iframe width=560 height=315 src=https://www.youtube.com/embed/ZVR2Way4nwQ title="YouTube video player" frameborder=0 allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><div class="card mb-4 rounded-0 shadow border-0"><div class="card-header rounded-0 bg-white border p-0 border-0"><a class="card-link h4 d-flex tex-dark mb-0 py-3 px-4 justify-content-between" data-toggle=collapse href=#import-packages><span>Import packages</span> <i class="ti-plus text-primary text-right"></i></a></div><div id=import-packages class=collapse data-parent=#accordion><div class="card-body font-secondary text-color"><h2 id=splitting-the-data>Splitting the Data</h2><h4 id=1-start-with-packages-and-data-set>1. Start with packages and data set</h4><p>We&rsquo;ll be using some parts of SKLEARN package and the Seaborn package.</p><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=color:#75715e># If you haven&#39;t already, install scikit-learn and seaborn</span>
active"><a href=https://byuistats.github.io/DS250-Cannon/slides/p4/d2/>Day 2: Intro to Machine Learning</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p4/d1/ title="Day 1: Intro to ML" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p4/d1/>Day 1: Intro to ML</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/ title="Week 6-7: Project 3 - Baseball" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/>Week 6-7: Project 3 - Baseball</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d4/ title="Day 4: Practice Coding Challenge" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d4/>Day 4: Practice Coding Challenge</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d3/ title="Day 3: The end of baseball" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d3/>Day 3: The end of baseball</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d2/ title="Day 2: SQL Calculations" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d2/>Day 2: SQL Calculations</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p3/d1/ title="Day 1: Intro to Project 3" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p3/d1/>Day 1: Intro to Project 3</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/ title="Week 4-5: Project 2 - Flights" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/>Week 4-5: Project 2 - Flights</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d4/ title="Day 4: Exporting JSON" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d4/>Day 4: Exporting JSON</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d3/ title="Day 2B: Missing Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d3/>Day 2B: Missing Data</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d2/ title="Day 2: Transforming Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d2/>Day 2: Transforming Data</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p2/d1/ title="Day 1: Intro to Flights Data" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p2/d1/>Day 1: Intro to Flights Data</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/ title="Week 2-3: Project 1 - Names" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/>Week 2-3: Project 1 - Names</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d3/ title="Day 3: Making your name stand out" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d3/>Day 3: Making your name stand out</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d2/ title="Day 2: Seeing names with Altair" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d2/>Day 2: Seeing names with Altair</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/p1/d1/ title="Day 1: Exploring names with pandas" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/p1/d1/>Day 1: Exploring names with pandas</a></li></ul></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/ title="Week 1: Introduction" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/>Week 1: Introduction</a><ul><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/day02/ title="Day 2: Project 0" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/day02/>Day 2: Project 0</a></li><li data-nav-id=https://byuistats.github.io/DS250-Cannon/slides/introduction/day01/ title="Day 1: Welcome" class=sidelist><a href=https://byuistats.github.io/DS250-Cannon/slides/introduction/day01/>Day 1: Welcome</a></li></ul></li></ul></li></ul></div></div><div class=col-lg-9><div class="p-lg-5 p-4 bg-white"><h2 class=mb-5>Day 2: Intro to Machine Learning</h2><div class=content><h2 id=welcome-to-class>Welcome to class!</h2><p><img src=tropical-year-illustration.png alt="alt text"></p><p><a href=https://shire-reckoning.com/calendar.html>Shire Reckoning</a></p><h4 id=announcements>Announcements</h4><ol><li>Coding Challenge Practice - Thursday, March 7</li></ol><h4 id=spiritual-thought>Spiritual thought</h4><h5 id=are-facts-true>Are facts true?</h5><br><ul><li>How do you distinguish between truth and error?</li><li>Joshua and Caleb</li></ul><br><h2 id=building-a-decision-tree>Building a Decision Tree</h2><iframe width=560 height=315 src=https://www.youtube.com/embed/ZVR2Way4nwQ title="YouTube video player" frameborder=0 allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><div class="card mb-4 rounded-0 shadow border-0"><div class="card-header rounded-0 bg-white border p-0 border-0"><a class="card-link h4 d-flex tex-dark mb-0 py-3 px-4 justify-content-between" data-toggle=collapse href=#import-packages><span>Import packages</span> <i class="ti-plus text-primary text-right"></i></a></div><div id=import-packages class=collapse data-parent=#accordion><div class="card-body font-secondary text-color"><h2 id=splitting-the-data>Splitting the Data</h2><h4 id=1-start-with-packages-and-data-set>1. Start with packages and data set</h4><p>We&rsquo;ll be using some parts of SKLEARN package and the Seaborn package.</p><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=color:#75715e># If you haven&#39;t already, install scikit-learn and seaborn</span>
pip install scikit<span style=color:#f92672>-</span>learn seaborn
</code></pre></div><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=color:#f92672>from</span> types <span style=color:#f92672>import</span> GeneratorType
<span style=color:#f92672>import</span> pandas <span style=color:#f92672>as</span> pd
Expand All @@ -30,17 +30,20 @@
</code></pre></div><h4 id=4-split-into-training-and-testing-sets>4. Split into training and testing sets</h4><h3 id=what-does-the-train_test_split-function-do>What does the &ldquo;train_test_split()&rdquo; function do?</h3><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python>x_train, x_test, y_train, y_test <span style=color:#f92672>=</span> train_test_split(x, y, test_size <span style=color:#f92672>=</span> <span style=color:#75715e>#???, random_state = #???)</span>
</code></pre></div><p><strong>Read the documentation and tell me what is returned?</strong></p><p><strong><a href=https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html>Function documentation</a></strong></p><blockquote><p>Why do we use &ldquo;test_size&rdquo; and &ldquo;random_state&rdquo;?</p></blockquote><blockquote><p>What is &ldquo;x&rdquo; and &ldquo;y&rdquo; in the above function example?</p></blockquote><p>We need to take our data and build the feature and target data objects.</p><blockquote><p>What columns should we remove from our features (X)?</p></blockquote><blockquote><p>What column should we use as our target (y)?</p></blockquote><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python>x <span style=color:#f92672>=</span> dwellings_ml<span style=color:#f92672>.</span>filter([<span style=color:#75715e>#what variables will you use as &#34;features&#34;?])</span>
y <span style=color:#f92672>=</span> dwellings_ml[<span style=color:#75715e>#what variable is the &#34;target&#34;?]</span>
</code></pre></div><br><br><h2 id=training-a-classifier>Training a Classifier</h2><h4 id=decision-tree-example>Decision Tree Example</h4><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=color:#75715e># create the model</span>
classifier <span style=color:#f92672>=</span> DecisionTreeClassifier()
</code></pre></div><br><br><h2 id=training-a-classifier>Training a Classifier</h2><h4 id=decision-tree-example>Decision Tree Example</h4><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python>
<span style=color:#75715e>#%%</span>
<span style=color:#75715e># Create a decision tree</span>
classifier_DT <span style=color:#f92672>=</span> DecisionTreeClassifier(max_depth <span style=color:#f92672>=</span> <span style=color:#ae81ff>4</span>)

<span style=color:#75715e># train the model</span>
classifier<span style=color:#f92672>.</span>fit(x_train, y_train)
<span style=color:#75715e># Fit the decision tree</span>
classifier_DT<span style=color:#f92672>.</span>fit(x_train, y_train)

<span style=color:#75715e># make predictions</span>
y_predictions <span style=color:#f92672>=</span> classifier<span style=color:#f92672>.</span>predict(x_test)
<span style=color:#75715e># Test the decision tree (make predictions)</span>
y_predicted_DT <span style=color:#f92672>=</span> classifier_DT<span style=color:#f92672>.</span>predict(x_test)

<span style=color:#75715e># Evaluate the decision tree</span>
<span style=color:#66d9ef>print</span>(<span style=color:#e6db74>&#34;Accuracy:&#34;</span>, metrics<span style=color:#f92672>.</span>accuracy_score(y_test, y_predicted_DT))

<span style=color:#75715e># test how accurate predictions are</span>
metrics<span style=color:#f92672>.</span>accuracy_score(y_test, y_predictions)
</code></pre></div><h4 id=how-to-improve-accuracy>How to Improve Accuracy</h4><p>To improve the accuracy of your model, you could:</p><ul><li>Change what variables are used in the features (x) data set</li><li>Change what type of model you are using</li><li>Tune (aka, &ldquo;change&rdquo; or &ldquo;tweak&rdquo;) the parameters of the model</li></ul><h4 id=other-classification-models>Other Classification Models</h4><p>Here are some other models you could try.</p><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=color:#f92672>from</span> sklearn.naive_bayes <span style=color:#f92672>import</span> GaussianNB
<span style=color:#f92672>from</span> sklearn.ensemble <span style=color:#f92672>import</span> RandomForestClassifier
<span style=color:#f92672>from</span> sklearn.ensemble <span style=color:#f92672>import</span> GradientBoostingClassifier
Expand Down

0 comments on commit 77b4089

Please sign in to comment.