MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How does Quadratic Discriminant Analysis work in ML in python

This recipe explains how Quadratic Discriminant Analysis work in ML in python

Quadratic Discriminant Analysis is a classifier with a quadratic decision boundary, generated by fitting class conditional densities to the data and using Bayesâ€™ rule. It fits a Gaussian density to each class.

So this recipe is a short example on how does Quadratic Discriminant Analysis work. Let's get started.

```
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
```

Let's pause and look at these imports. We have exported train_test_split which helps in randomly breaking the datset in two parts. Here sklearn.dataset is used to import one classification based model dataset. Also, we have exported QuadraticDiscriminantAnalysis to build our model.

```
X,y=load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
```

Here, we have used load_iris function to import our dataset in two list form (X and y) and therefore kept return_X_y to be True. Further with have broken down the dataset into 2 parts, train and test with ratio 3:4.

Now our dataset is ready.

```
model = QuadraticDiscriminantAnalysis()
```

We have simply built a classification model with QuadraticDiscriminantAnalysis with default values.

```
model.fit(X_train, y_train)
y_pred= model.predict(X_test)
```

Here we have simply fit used fit function to fit our model on X_train and y_train. Now, we are predicting the values of X_test using our built model.

```
print(model.score(X_train,y_train))
print(model.score(X_test,y_test))
```

Here we have calculated accuracy score using score function for both our train and test set.

Once we run the above code snippet, we will see:

0.9910714285714286 0.9736842105263158

Clearly, the model built for the given datset is highly efficient on any unknown set. It might be best model to fit on iris Dataset.

In this time series project, you will build a model to predict the stock prices and identify the best time series forecasting model that gives reliable and authentic results for decision making.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

In this Deep Learning Project, you will use the credit card fraud detection dataset to apply Anomaly Detection with Autoencoders to detect fraud.