Linear Discriminant Analysis (LDA) is used to solve multiclass classification problems in machine learning. Let’s say we have two-dimensional data points. In LDA, we create a new axis and plot the data points on the new axis such that:
- The distance between the means of the two classes is maximized.
- The variance within an individual class is minimized.
Thus, we can maximize the separation between the two classes and use that to solve the classification problem.
Interested readers who want to know more may want to refer to the following link: https://www.youtube.com/watch?v=azXCzI57Yfc
Linear Discriminant Analysis (LDA) using sklearn in Python
We can use the following Python code to implement Linear Discriminant Analysis (LDA) in sklearn.
import pandas from sklearn.model_selection import KFold from sklearn.discriminant_analysis import LinearDiscriminantAnalysis from sklearn.model_selection import cross_val_score data = pandas.read_csv("diabetes.csv") D = data.values X = D[:, :-1] y = D[:, -1] k_fold = KFold(n_splits=10, shuffle=True, random_state=1) classifier = LinearDiscriminantAnalysis() results = cross_val_score(classifier, X, y, cv=k_fold, scoring="accuracy") mean_score = results.mean() print("Accuracy: ", mean_score)
Here, we are first using the pandas Python library to read the Pima Indians Diabetes dataset. The dataset contains various …






0 Comments