Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Concept Entry] Sklearn: Linear Discriminant Analysis #5824

Merged
merged 4 commits into from
Dec 21, 2024

Conversation

Sriparno08
Copy link
Collaborator

Description

Added a new term entry on Linear Discriminant Analysis in Sklearn.

Issue Solved

Closes #5306

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@Sriparno08 Sriparno08 added new entry New entry or entries sklearn Sklearn labels Dec 15, 2024
@mamtawardhani mamtawardhani self-assigned this Dec 16, 2024
@mamtawardhani mamtawardhani added the status: under review Issue or PR is currently being reviewed label Dec 16, 2024
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Sriparno08, thank you for contributing to Codecademy Docs, the entry is nicely written! 😄

I've suggested a few changes, could you please review and modify those at your earliest convenience? Thank you! 😃

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

# Create an LDA model
model = LinearDiscriminantAnalysis()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add parameters for the LinearDiscriminantAnalysis to increase its readability?
Reference - https://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we can certainly do that.

Comment on lines 76 to 99
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

# Load the Diabetes dataset
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target

# Create training and testing sets by splitting the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=44)

# Create an LDA model
model = LinearDiscriminantAnalysis()

# Fit the model to the training data
model.fit(X_train, y_train)

# Make predictions on the test set
y_pred = model.predict(X_test)

# Evaluate the model
print("Accuracy:", accuracy_score(y_test, y_pred))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should use Iris data set here, because the Diabetes dataset from sklearn.datasets is a regression dataset, not a classification dataset. Linear Discriminant Analysis (LDA) is designed for classification tasks where the target variable (y) has discrete class labels, not continuous values as in the case of the Diabetes dataset.

@Sriparno08
Copy link
Collaborator Author

Made the changes, @mamtawardhani.

Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing to Codecademy Docs @Sriparno08 😄

The entry looks good to be merged! 🚀

@mamtawardhani mamtawardhani merged commit 193437f into Codecademy:main Dec 21, 2024
6 checks passed
Copy link

👋 @Sriparno08
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 Your contribution(s) can be seen here:

https://www.codecademy.com/resources/docs/sklearn/linear-discriminant-analysis

Please note it may take a little while for changes to become visible.
If you're appearing as anonymous and want to be credited, see here.

@Sriparno08 Sriparno08 deleted the sklearn-lda branch December 22, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Concept Entry] Sklearn Linear Discriminant Analysis Linear Discriminant Analysis
2 participants