How to load Wine Dataset using Sklearn?
The sklearn.datasets.load_wine() function allows you to load the Wine dataset directly into NumPy arrays or pandas DataFrame objects. By setting the return_X_y and as_frame parameters, you can control the format of the returned data.
Syntax: sklearn.datasets.load_wine(*, return_X_y=False, as_frame=False)
In the following code, we utilize the pandas library to load the wine dataset from scikit-learn’s built-in datasets module. It converts the dataset into a pandas DataFrame, allowing easy manipulation and analysis.
import pandas as pd
from sklearn.datasets import load_wine
# Load the wine dataset into a DataFrame
wine_data = load_wine(as_frame=True)
wine_df = wine_data.frame
print(wine_df.head())
# Display the shape of the DataFrame
print("Shape of the Wine DataFrame:", wine_df.shape)
Output:
alcohol malic_acid ash alcalinity_of_ash magnesium total_phenols \
0 14.23 1.71 2.43 15.6 127.0 2.80
1 13.20 1.78 2.14 11.2 100.0 2.65
2 13.16 2.36 2.67 18.6 101.0 2.80
3 14.37 1.95 2.50 16.8 113.0 3.85
4 13.24 2.59 2.87 21.0 118.0 2.80
flavanoids nonflavanoid_phenols proanthocyanins color_intensity hue \
0 3.06 0.28 2.29 5.64 1.04
1 2.76 0.26 1.28 4.38 1.05
2 3.24 0.30 2.81 5.68 1.03
3 3.49 0.24 2.18 7.80 0.86
4 2.69 0.39 1.82 4.32 1.04
od280/od315_of_diluted_wines proline target
0 3.92 1065.0 0
1 3.40 1050.0 0
2 3.17 1185.0 0
3 3.45 1480.0 0
4 2.93 735.0 0
Shape of the Wine DataFrame: (178, 14)
Wine Dataset in Sklearn
The Wine Recognition dataset is a classic benchmark dataset widely used in machine learning for classification tasks. It provides valuable insights into wine classification based on various chemical attributes. In this article, we delve into the characteristics, attributes, and significance of the Wine Recognition dataset, along with its applications in research and practical implementations.
Table of Content
- Understanding Wine Dataset
- Characteristics of Wine Dataset
- Types of Wine Datasets
- 1. Chemical Composition Datasets
- 2. Sensory Evaluation Datasets
- How to load Wine Dataset using Sklearn?
- Significance of Wine Dataset in Machine Learning
- Application of Wine Dataset
- Challenges and Considerations of Wine Datasets