Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Explore Dataset | Model Building
Principal Component Analysis

Scorri per mostrare il menu

book
Explore Dataset

Now we will take a closer look at the creation of a PCA model using the example of one dataset. As a dataset, we will use wine from the scikit-learn set. It contains 13 wine characteristics and 3 classes. It is especially convenient for us because there are no categorical variables in it.

Let's load the dataset:

# Importing library
from sklearn.datasets import load_wine

# Reading the dataset
data = load_wine()
X = data.data

Now let's explore the dataset to understand what data we are working with. Let's convert the numpy array X to a pandas dataframe and check the amount of missing data:

# Importing library
import pandas as pd

# Checking for missing data
df = pd.DataFrame(X, columns = data.feature_names)
(df.isnull() | df.empty | df.isna()).sum()

To get a complete description of each column (mean, standard deviation, etc.), use the .describe() method:

df.describe()

Before loading the dataset into the PCA model, let's process our data. Based on the previous lessons, you may have noticed that an important step is data standardization. We implement this using the StandardScaler() class:

# Importing class
from sklearn.preprocessing import StandardScaler

# Standardization
X_scaled = StandardScaler().fit_transform(X)
Compito

Swipe to start coding

Read the data from the train.csv (from web) file. Remove the "Id" column from the dataset and standardize it.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 2
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

Awesome!

Completion rate improved to 5.26

book
Explore Dataset

Now we will take a closer look at the creation of a PCA model using the example of one dataset. As a dataset, we will use wine from the scikit-learn set. It contains 13 wine characteristics and 3 classes. It is especially convenient for us because there are no categorical variables in it.

Let's load the dataset:

# Importing library
from sklearn.datasets import load_wine

# Reading the dataset
data = load_wine()
X = data.data

Now let's explore the dataset to understand what data we are working with. Let's convert the numpy array X to a pandas dataframe and check the amount of missing data:

# Importing library
import pandas as pd

# Checking for missing data
df = pd.DataFrame(X, columns = data.feature_names)
(df.isnull() | df.empty | df.isna()).sum()

To get a complete description of each column (mean, standard deviation, etc.), use the .describe() method:

df.describe()

Before loading the dataset into the PCA model, let's process our data. Based on the previous lessons, you may have noticed that an important step is data standardization. We implement this using the StandardScaler() class:

# Importing class
from sklearn.preprocessing import StandardScaler

# Standardization
X_scaled = StandardScaler().fit_transform(X)
Compito

Swipe to start coding

Read the data from the train.csv (from web) file. Remove the "Id" column from the dataset and standardize it.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

close

Awesome!

Completion rate improved to 5.26

Scorri per mostrare il menu

some-alt