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...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
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...
Write a c code program to solve 5a. Given the data as follows: x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,3
Write a c code program to solve 5a. Given the data as follows: x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42}; y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48}. Compute the average, variance and standard deviation (S.D.) of x and y separately. 5b. Given the data as follows: x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42}; y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48}. Compute Linear regression, i.e., find a and b such that y=ax+b results in the smallest total error. 5c. For the data given in problem 5, check the relationship between average(x) and average(y), and also the relationship...
#2 A data processing company has a training program for new salespeople. After completing the training...
#2 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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT