Question

Python program to Normalize data for KNN Classifier data = pd.read_csv('iris.data') Y=data['status'] X=data[data.columns.difference(['status','name'])] # split the...

Python program to Normalize data for KNN Classifier

data = pd.read_csv('iris.data')

Y=data['status']

X=data[data.columns.difference(['status','name'])]
# split the data in testing and training
train_in,test_in,train_out,test_out=train_test_split(X,Y,train_size=0.8)

knn = KNeighborsClassifier()

  1. use sklearn.preprocessing.scalar(), Stan- dardScaler(), MinMaxScaler(), MaxAbsScaler()) to normalize data

Homework Answers

Answer #1
import pandas as pd
from sklearn.preprocessing import MinMaxScaler,StandardScaler,MaxAbsScaler

data = pd.read_csv('iris.data')

Y=data['status']

X=data[data.columns.difference(['status','name'])]

# split the data in testing and training

train_in,test_in,train_out,test_out=train_test_split(X,Y,train_size=0.8)

# Normalize feature data using MinMax scaler
scaler = MinMaxScaler()

X_train_scaled = scaler.fit_transform(train_in)
X_test_scaled = scaler.transform(test_in)

# Normalize feature data using StandardScaler
standarad_scaler = StandardScaler()

X_train_scaled = standarad_scaler.fit_transform(train_in)
X_test_scaled = standarad_scaler.transform(test_in)

# Normalize feature data using MaxAbsScaler
max_abs_scaler = MaxAbsScaler()

X_train_scaled = max_abs_scaler.fit_transform(train_in)
X_test_scaled = max_abs_scaler.transform(test_in)


knn = KNeighborsClassifier()
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python 3 Rewrite KNN sample code using KNeighborsClassifier . ● Repeat KNN Step 1 – 5,...
Python 3 Rewrite KNN sample code using KNeighborsClassifier . ● Repeat KNN Step 1 – 5, for at least five times and calculate average accuracy to be your result. ● If you use the latest version of scikit -learn, you need to program with Python >= 3.5. ● Use the same dataset: “ iris.data ” ● Split your data: 67% for training and 33% for testing ● Draw a line chart: Use a “for loop” to change k from 1...
Coding in Python Add radio button options for filing status to the tax calculator program of...
Coding in Python Add radio button options for filing status to the tax calculator program of Project 1. The user selects one of these options to determine the tax rate. The Single option’s rate is 20%. The Married option is 15%. The Divorced option is 10%. The default option is Single. Be sure to use the field names provided in the comments in your starter code. ================== Project 1 code: # Initialize the constants TAX_RATE = 0.20 STANDARD_DEDUCTION = 10000.0...
A statistical program is recommended. Consider the following data for two variables, x and y. xi...
A statistical program is recommended. Consider the following data for two variables, x and y. xi 135 110 130 145 175 160 120 yi 145 105 120 115 130 130 110 (a) Compute the standardized residuals for these data. (Round your answers to two decimal places.) xi yi Standardized Residuals 135 145 110 105 130 120 145 115 175 130 160 130 120 110 Do the data include any outliers? Explain. (Round your answers to two decimal places.) The standardized...
The table below shows a set of bivariate data: X and Y. Calculate the covariance and...
The table below shows a set of bivariate data: X and Y. Calculate the covariance and correlation coefficients by completing the below table, assuming sample data. Show all workings. (Note: You can calculate the mean and standard deviation of X & Y with Excel or your calculator; no working for their calculation is required.) X Y (X - X bar) (Y - Y bar) (X - X bar)(Y - Y bar) 5 5 -0.2 -0.6 0.12 2 3 -3.2 -2.6...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
1. For a pair of sample x- and y-values, what is the difference between the observed...
1. For a pair of sample x- and y-values, what is the difference between the observed value of y and the predicted value of y? a) An outlier b) The explanatory variable c) A residual d) The response variable 2. Which of the following statements is false: a) The correlation coefficient is unitless. b) A correlation coefficient of 0.62 suggests a stronger correlation than a correlation coefficient of -0.82. c) The correlation coefficient, r, is always between -1 and 1....
Clinical Scenario: CHIEF COMPLAINT: Acute Altered Mental Status HISTORY OF PRESENT ILLNESS: Mrs. X is a...
Clinical Scenario: CHIEF COMPLAINT: Acute Altered Mental Status HISTORY OF PRESENT ILLNESS: Mrs. X is a 56-year-old Caucasian female with medical history notable for chronic pain and polypharmacy. Beginning three days ago she felt as though she had a flu-like illness. The symptoms began with a cough 3 days ago, then progressed to a feeling of fatigue 2 days ago, and then 1 day ago she became confused. She has been barely verbal and unable to communicate with her family....
In narrative essay format, I want you to address a business/organization case study using multiple concepts...
In narrative essay format, I want you to address a business/organization case study using multiple concepts from class. The case question and case text begin on page 5 of this document. You need to demonstrate their best understanding of management and organizational behavior theory, and the application of those ideas to improve the understanding of various issues. You need to clearly identify at least 3 distinct, substantive issues. For each issue you need to 1), identify evidence from the case...