Question

i'm receiving an 'a' is not defined error. what is the command to define 'a'? import...

i'm receiving an 'a' is not defined error. what is the command to define 'a'?

import numpy as np
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv')
df.head()

from sklearn.preprocessing import StandardScaler

a_scaled=StandardScaler().fit_transform(a)
a_scaled[:5]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Standard Scaler is one of the preprocessing methods present in the scikit learn library. Actually, the Standard Scaler is a data pre-processing method which transforms our data/dataframe in such a way that its distribution would be having a 0 mean and unit (1) standard deviation/variance i.e  μ = 0 and σ = 1. So basically, the standard scaler just normalizes the features (columns) present in our data/data frame one by one and hence gives us the scaled data then.

Now, the error you are receiving as 'a' is not defined because when you are using the code:

1. import numpy as np
2. import pandas as pd
3. df = pd.read_csv('https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv')
4. df.head()
5. from sklearn.preprocessing import StandardScaler
6. a_scaled=StandardScaler().fit_transform(a)
7. a_scaled[:5]

is because, you have not defined what variable/object 'a' actually is before using the 6th line of code that is:

a_scaled=StandardScaler().fit_transform(a)

Here, you must know that the in the StandardScalre().fit_transform() function, the input parameter should be a data/data frame. So you should type the following line of code in the 6th line:

a_scaled=StandardScaler().fit_transform(df)

because here, the input to the StandardScalre().fit_transform() function is now (df) which is actually a data frame/CSV file you just loaded through Pandas in line 3. After correcting your code, you will not get this error anymore.

But, in case you wish to use the same 6th line of code as:

a_scaled=StandardScaler().fit_transform(a)

then you must first define what 'a' is. before using this 6th line of code.

You can simply do this by adding the following assignment before line 6:

a = df.copy();

it will simply copy your data frame named 'df' into am another data frame/variable named 'a', and then you can continue using your 6th line of code as a_scaled=StandardScaler().fit_transform(a).

Now you might have understood that you first need to define any variable before using it in your code. Your error will be surely solved now!

Thanks!

Add a comment
Know the answer?
Add Answer to:
i'm receiving an 'a' is not defined error. what is the command to define 'a'? import...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my code: import numpy as np import pandas as pd import sys from keras.models...

    This is my code: import numpy as np import pandas as pd import sys from keras.models import Sequential from keras.layers import Dense from sklearn.preprocessing import StandardScaler from keras.layers.normalization import BatchNormalization from keras.layers import Dropout file_full=pd.read_csv("/Users/anwer/Desktop/copy/FULL.csv") file_bottom=pd.read_csv("/Users/anwer/Desktop/copy/bottom.csv") train=[] train_targets=[] test=[] test_targets=[] p=[] q=[]    # We will generate train data using 50% of full data and 50% of bottom data. #is train target for labeling ? yes for train data train_df = file_full[:len(file_full)//2] labels=[ 0 for i in range(len(file_full)//2)] train_df=train_df.append(file_bottom[:len(file_bottom)//2]) for...

  • You are to build trees with varying max tree depth for the dataset provided (use maximum...

    You are to build trees with varying max tree depth for the dataset provided (use maximum tree depths 2-10). For each tree of a given maximum depth, record the accuracy, precision and recall. Plot each of these metrics as a line plot (tree depth on the x axis and % on the y axis). Below is what I have attempted. In [1]: import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics...

  • Please help! I am trying to make a convolution but i am receiving a syntax error....

    Please help! I am trying to make a convolution but i am receiving a syntax error. If anyone can help with how to do the convolution it would be much appreciated! This first part is the main program. import numpy as np from numpy import * import pylab as pl import wave import struct from my_conv import myconv #import scipy.signal as signal ##-------------------------------------------------------------------- ## read the input wave file "speech.wav" f = wave.open("speech.wav", "rb") params = f.getparams() nchannels, sampwidth, framerate,...

  • You have just been hired as an analyst for an investment firm. Your first assignment is...

    You have just been hired as an analyst for an investment firm. Your first assignment is to analyze data for stocks in the S&P 500. The S&P 500 is a stock index that contains the 500 largest publicly traded companies. You have been given two sources of data to work with. The first is an XML file that contains the Symbol (ticker), company name, sector, and industry for every stock in the S&P 500, as of summer 2016. The second...

  • Python with Pandas dataframe I have a csv file that contains a large number of columns...

    Python with Pandas dataframe I have a csv file that contains a large number of columns and rows. I need to write a script that concatenates some elements of the first row with some elements of the 2 row. Something like # if data[1][0] starts with ch then concatenate the element right below it. I have attached a picture of just a sample of my data. The booleans have to stay on there as is. But I must drop the...

  • this is my code to predict a housing price based on data but i get a...

    this is my code to predict a housing price based on data but i get a lot errors, how do i resolve all these errors 9]: import seaborn as sns from sklearn.linear model import LinearRegression 20]: import numpy as np import matplotlib.pyplot as plt %matplotlib inline import pandas as pd data- pd.read_csv('C:\\Users \\Downloads \\house-prices -advanced-regression-techniques\\test.csv) I data 20]: ScreenPorch PoolArea PoolQC Fence Id MSSubClass MSZoning LotFrontage LotArea Street Alley LotShape LandContour Utilities NaN MnPry 120 Lvl AlPub Pave NaN Reg...

  • In Python!! 1. Correcting string errors It's easy to make errors when you're trying to type...

    In Python!! 1. Correcting string errors It's easy to make errors when you're trying to type strings quickly. Don't forget to use quotes! Without quotes, you'll get a name error. owner = DataCamp Use the same type of quotation mark. If you start with a single quote, and end with a double quote, you'll get a syntax error. fur_color = "blonde' Someone at the police station made an error when filling out the final lines of Bayes' Missing Puppy Report....

  • I need to create the "nnclassifier using the euclidean distance formula to find nearest neighbor. I...

    I need to create the "nnclassifier using the euclidean distance formula to find nearest neighbor. I am using the inis dataset from seabom. I have loaded the data and split the database into values and species. I have created a function to find the nearest neighbor by also calculating the euclidean distance and appending them to a distance list. I am able to see the positions of the nearest neighbors. Smart numpy as Import pandas as pd Import seaborn as...

  • Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from...

    Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from number #1 link provided for the Data: -----> https://docs.google.com/spreadsheets/d/1TqhyxFKQlOHAyXpQBL-4C96kgZFBoMwUgE8-b33CqPQ/edit?usp=sharing PROBLEMS # 0.0 Import the libraries (pandas, matplotlib, and seaborn) Include the code line: %matplotlib inline #Include the code line: plt.style.use(“ggplot”) #Load the data using pandas #Inspect the data using head(), dtypes ANSWERD: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns plt.style.use('ggplot') %matplotlib inline df = pd.read_csv() print(df.head()) print(df.dtypes) # 1...

  • You are asked to define a user-defined data type for students, that will contain the following...

    You are asked to define a user-defined data type for students, that will contain the following information about a student: ID number, first name, last name, major, GPA. Your structure should be cal Student. Based on the defined structure, user name on the command line, show how you will use a loop to search for the given name within the array of 5 students. use an array to record information about 5 students. Then, given a Write a C program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT