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
Which of the following strings P is a Python program. (b) P = “def f(x): x...
Which of the following strings P is a Python program. (b) P = “def f(x): x = 'am I a Python program?'” (d) P = “def f(x,y,z): return y” (e) P = “def f(x): return y” For each of the following Python programs P and input strings I, give the output P(I), (f) P = “def f(x): return str(len(x+x+'x'))”, I = “GAGAT” (g) P = “def f(x): return str(len(x))”, I=P (h) P = “def f(x): return str(1/int(x))”, I = “0”
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 data processing company has a training program for new salespeople. After completing the training program,...
A data processing company has a training program for new salespeople. After completing the training program, each trainee is ranked by his or her instructor. After a year of sales, the same class of trainees is again ranked by a company supervisor according to net value of the contracts they have acquired for the company. The results for a random sample of 11 salespeople trained in the last year follow, where x is rank in training class and y is...
A data processing company has a training program for new salespeople. After completing the training program,...
A data processing company has a training program for new salespeople. After completing the training program, each trainee is ranked by his or her instructor. After a year of sales, the same class of trainees is again ranked by a company supervisor according to net value of the contracts they have acquired for the company. The results for a random sample of 11 salespeople trained in the last year follow, where x is rank in training class and y is...
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z...
4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of...
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...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Charged Spheres #1 Charged spheres are placed as follows: Name Charge (μC) x location (m) y...
Charged Spheres #1 Charged spheres are placed as follows: Name Charge (μC) x location (m) y location (m) A +7.0 0.0 0.0 B -8.0 -2.0 3.0 a. Determine the electric field (x and y components) created by charge A at the location (-2.0, 0.0). b. Determine the electric field (x and y components) created by charge B at the location (-2.0, 0.0). c. Determine the net electric field (x and y components) at the location (-2.0, 0.0). d. Determine the...
For each X-Y data set (n = 12):    Data Set (a) X 64.7 25.9 65.6...
For each X-Y data set (n = 12):    Data Set (a) X 64.7 25.9 65.6 49.6 50.3 26.7 39.5 56.0 90.8 35.9 39.9 64.1 Y 5.8 18.1 10.6 11.9 11.4 14.6 15.7 4.4 2.2 15.4 14.7 9.9      Data Set (b) X 55.1 59.8 72.3 86.4 31.1 41.8 40.7 36.8 42.7 28.9 24.8 16.2 Y 15.7 17.5 15.2 20.6 7.3 8.2 9.8 8.2 13.7 11.2 7.5 4.5      Data Set (c) X 53.3 18.1 49.8 43.8 68.3 30.4 18.6...