-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
There was a problem hiding this 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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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)) |
There was a problem hiding this comment.
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.
Made the changes, @mamtawardhani. |
There was a problem hiding this 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! 🚀
👋 @Sriparno08 🎉 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. |
Description
Added a new term entry on
Linear Discriminant Analysis
in Sklearn.Issue Solved
Closes #5306
Type of Change
Checklist
main
branch.Issues Solved
section.