Question
Using these packages in python jupyter, import numpy as np import pandas as pd import seaborn as sns import math from sklearn import preprocessing from
Using these packages in python jupyter, import numpy as np import pandas as pd import seaborn as sns import math from sklearn import preprocessing from sklearn import datasets import sklearn from scipy import stats import matplotlib import matplotlib.pyplot as plt %matplotlib inline matplotlib.style.use('ggplot') np.random.seed(1) And this: X = datasets.load_wine(as_frame=True) data = pd.DataFrame(X.data, columns=X.feature_names) data['class'] = pd.Series(X.target) data = data.drop(list(data.columns[5:-1]),axis=1) #Keep only the first five columns and the class label print(" classes ",data['class'].unique()) #The different class labels in the data .. We have three class labels, 0, 1, 2 print(" class distribution ",data['class'].value_counts()) #Shows the number of rows for each class data.info() data.head()
Q3- Part A- Normalize the data such that each attribute has a minimum of 0 and a maximum of 1
Don't change the content of the original dataframe. The final result will be stored in data_scaled
#Normalizing all the columns .. Accessing the columns with the columns' names data_scaled = data.copy() Part B- Standarize the data such that each attribute has a mean 0 and a standard deviation of 1 (unit variance)
Hint: use preprocessing.StandardScaler
Don't change the content of the original dataframe. The final result will be stored in data_scaled
#Standarizing all the columns .. Accessing the columns with the columns' names data_scaled = data.copy() Part C-
Discretization
Equal-Width Binning, Convert the values in each attribute to discrete values and use 5 bins.
Use the pandas cut method, pd.cut data_discrete = data.copy
Part D- Equal Frequency Binning,Convert the values in each attribute to discrete values and use 5 bins.
Use the pandas qcut method, pd.qcut data_freq = data.copy()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started