Jennifer Chen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CS410 Homework 6: Linear Regression > **Due Date: 11/2/2024** > **Need help?** Remember to check out Edstem and our website for TA assistance. ## Assignment Overview Linear Regression is one of the most standard methods of machine learning. ## Learning Goals and Objectives 1. Applying knowledge from lecture to implement linear regression 2. Evaluating and Preprocessing Time Series data 3. Implementing Binary Classification via Logistic Regression 4. Implementing One vs Rest Logistic Regression 5. Interpreting Model Results ## Introduction ==TODO maybe use this? https://x.com/Rainmaker1973/status/1527220014578905088== ## Getting Started ### Stencil Please click [here](https://github.com/BrownCSCI410/assignment-6-regression) to get the stencil code. It should contain these files: `main.py'... ==TODO== ### Environment You will need to use the virtual environment that you made in Homework 0 to run code in this assignment, which you can activate by using `conda activate csci410`. ==TODO== ## Linear Regression Now that Steve's civilization is pretty developed, he's interested in predicting the life expectancy of the average individual in his new village. What a caring leader! After surfing the web, Steve stumbled upon some Life Expectancy data from the World Health Organization. Since Steve is still relatively new to machine learning, he's curious about using the trusty linear regression to model and predict the life expectancy of his villagers. Linear regression is one of the simplest yet most foundational models for predictions that rely on ## Data You can find the life_expectancy.csv dataset in your project folder! This dataset, from the WHO, contains data for a range of countries on health indicators for the years 2000-2015. It contains statistics on life expectancy, as well as related health categories such as infant deaths, BMI, and polio rates, in addition to country-specific data such as GDP and population. In addition, it separates countries into developing vs. developed countries. The purpose of the dataset is to capture relations between life expectancy and the other information in the dataset, and for governments to be able to focus on improving the life expectancy in their country by locating which factors have the greatest effect. The dataset is located at this link: https://www.kaggle.com/datasets/kumarajarshi/life-expectancy-who?resource=download ## Tasks Exploratory analysis -> heatmap, correlation matrices Data preprocessing -> filtering data Implement regression model Evaluate model with testing looking at loss functions, the strengths of diff loss functions ### Step 1: ### Step 2: #### Part 1: Loss Function For this model, you will be evaluating and training the model using L2 loss (sum squared loss). Mathematically, the L2 loss function is defined as: $L_s(y_{predict}) = \sum^n_{i=1}(y_i-y_{predict}(x_i))^2$ Where $y_i$ is the actual value of the $i^{th}$ value and $y_{predict}(x_i)$ is the predicted value of that sample given the learned weights. Your model will aim to minimize this loss through matrix inversion. #### Part 2: LinearRegression You will be implementing this model using the given stencil code. For training the model, since you know that the data is linearly independent, you can use matrix inversion to compute the weight vector $\mathbf{w}$ that minimizes the sum squared loss. The equation to find $\mathbf{w}$ given a set of data points $X$ and their labels $\mathbf{y}$ is: $\mathbf{w} = (X^TX)^{-1}X^T\mathbf{y}$ :::spoiler HINT Use the numpy function **np.linalg.pinv** to calculate matrix inverses!</details> ::: ### Step 3: Great! Now you have made your model! In order to test the functionality, you have (smartly) decided to use the mean-squared error, root mean-squared error, and R squared functions. Here is what they look like mathematically: ==TODO: Don't make the student implement this== - MSE: $\frac{\sum_{i=1}^n(y_i - y_{predict}(x_i))^2}{n}$ - RMSE: $\sqrt{\frac{\sum_{i=1}^n(y_i - y_{predict}(x_i))^2}{n}}$ - $R^2$: $1 - \frac{\sum_{i=1}^n(y_i - y_{predict}(x_i))^2}{\sum_{i=1}^n(y_i - \bar{y})^2}$ For these equations, $y_i$ is the actual value of the $i^{th}$ value, $y_{predict}(x_i)$ is the predicted value of that sample given the learned weights, and $\bar{y}$ is the mean of all $y$ values. Implement these functions (RMSE, MSE, R squared) in `test_linreg.py` and use these to interpret the performance of the model. ### Step 4: include Writeup/interpretation of the model? ==TODO: Add feature selection testing== ==TODO: Add takeaways== --> <!-- ## Logistic Regression ## Data You will be using the same dataset as above (@UTA, any ideas for how to visualize/break down the dataset to help the student understand why a logistic regression could possibly work here? Or may not work? Also, will definitely need elaboration on preprocessing/making target class out of a feature) **Visualize data with violin plot? not sure** ## Tasks ### Step 1: Implement binary logistic regression (please add more details <3) ==TODO why is logistic regression accuracy so bad :(== <!-- ## One vs Rest As you may have noticed, Steve's model doesn't do so hot a lot of the time :-( This is largely because there are actually **three** classes of irises represented in the dataset he is using. Trying to conduct binary classification on more than two classes is very difficult. However, we can extend our knowledge of binary classification to handle multiple classes. In **one-vs-rest** logistic regression, a separate binary classification model is trained for each class. For each model, a class of interest is treated as the positive class, and all other classes are grouped into the negative class... --> <!-- ### Step 2: Implement One vs Rest logistic regression --> ## Submission ### Grading ### Hand-In Submit the assignment via Gradescope under the corresponding project assignment by **zipping up your hw** folder or through **GitHub** (recommended). To submit through GitHub, follow these commands: 1. `git add -A` 2. `git commit -m "commit message"` 3. `git push` Now, you are ready to upload the repo to Gradescope. :::success Congrats on submitting your homework; Steve is proud of you!! ![image](https://hackmd.io/_uploads/S1OQ2aCwA.png) :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully