ValueError: Found array with 0 feature(s) (shape=(546, 0)) while a minimum of 1 is required
15,078
Your link in this line
dataset = pd.read_csv("https://github.com/Avik-Jain/100-Days-Of-ML-Code/blob/master/datasets/Data.csv", error_bad_lines=False)
is wrong.
The current link returns the webpage on github where this csv is shown, but not the actual csv data. So whatever data is present in dataset
is invalid.
Change that to:
dataset = pd.read_csv("https://raw.githubusercontent.com/Avik-Jain/100-Days-Of-ML-Code/master/datasets/Data.csv", error_bad_lines=False)
Other than that, there is a spelling mistake in LabelEncoder
import.
Now even if you correct these, there will still be errors, because of
Y = labelencoder_Y.fit_transform(Y)
LabelEncoder only accepts a single column array as input, but your current Y
will be of 2 columns due to
Y = dataset.iloc[:,1:3].values
Please explain more clearly what do you want to do.
Author by
Rushiraj Parmar
Updated on June 04, 2022Comments
-
Rushiraj Parmar about 2 years
I was just trying out for DataPreprocessing where I frequently get this error.Can anyone explain me what is wrong in this particular code for the given dataset?
Thanks in advance!
# STEP 1: IMPORTING THE LIBARIES import numpy as np import pandas as pd # STEP 2: IMPORTING THE DATASET dataset = pd.read_csv("https://github.com/Avik-Jain/100-Days-Of-ML-Code/blob/master/datasets/Data.csv", error_bad_lines=False) X = dataset.iloc[:,:-1].values Y = dataset.iloc[:,1:3].values # STEP 3: HANDLING THE MISSING VALUES from sklearn.preprocessing import Imputer imputer = Imputer(missing_values = "NaN",strategy = "mean",axis = 0) imputer = imputer.fit(X[ : , 1:3]) X[:,1:3] = imputer.transform(X[:,1:3]) # STEP 4: ENCODING CATEGPRICAL DATA from sklearn.preprocessing import LaberEncoder,OneHotEncoder labelencoder_X = LabelEncoder() # Encode labels with value between 0 and n_classes-1. X[ : , 0] = labelencoder_X.fit_transform(X[ : , 0]) # All the rows and first columns onehotencoder = OneHotEncoder(categorical_features = [0]) X = onehotencoder.fit_transform(X).toarray() labelencoder_Y = LabelEncoder() Y = labelencoder_Y.fit_transform(Y) # Step 5: Splitting the datasets into training sets and Test sets from sklearn.cross_validation import train_test_split X_train, X_test, Y_train, Y_test = train_test_split( X , Y , test_size = 0.2, random_state = 0) # Step 6: Feature Scaling from sklearn.preprocessing import StandardScaler sc_X = StandardScaler() X_train = sc_X.fit_transform(X_train) X_test = sc_X.fit_transform(X_test)
Returns Error:
ValueError: Found array with 0 feature(s) (shape=(546, 0)) while a minimum of 1 is required.
-
Eternal Blue almost 6 yearsCan you
print()
yourx
andy
variables? There may be a mismatch in dimensionality. -
Vivek Kalyanarangan almost 6 yearsCan you also post the full stack trace?
-
-
Rushiraj Parmar almost 6 yearsThanks! I tried and it worked out.Actually I am just a newbie to MachineLearning and I started the 100 days of ml code.the first one was DataPreprocessing and I got stuck there but after your suggestion the error is solved!