Python Forum
ValueError: Input contains infinity or a value too large for dtype('float64')
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: Input contains infinity or a value too large for dtype('float64')
#1
Hello python community, i need help.
I'm working on machine learning. However, i have problem at the cleaning step.
i use this code:
# Importing the libraries 
import numpy as np 
import matplotlib.pyplot as plt 
import pandas as pd 

# Importing the dataset 
dataset = pd.read_csv('Rural3.csv') 

#cleaning missing data 
from sklearn.preprocessing import Imputer 
imputer= Imputer(missing_values='NaN', strategy='mean' , axis = 0) 
imputer.fit(dataset)
At this level, a notification appear: Columns (14,15) have mixed types. Specify dtype option on import or set low_memory=False.

I continue executing the following lines :
X = dataset.iloc[:, :-1].values 
y = dataset.iloc[:, 75].values
 
# Splitting the dataset into the Training set and Test set 
from sklearn.model_selection import train_test_split 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
 
# Feature Scaling 
from sklearn.preprocessing import StandardScaler 
sc = StandardScaler() 
X_train = sc.fit_transform(X_train) 
X_test = sc.transform(X_test)
At this level, the error appears: ValueError: Input contains infinity or a value too large for dtype('float64').

What should i do please ?! i didn't know what to do ?!
Reply
#2
Pandas is very flexible. So, you don't need to use Imputer, just do this work with Pandas:

dataset.fillna(dataset.mean(), inplace=True)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Found input variables with inconsistent numbers of samples: [5, 6] bongielondy 6 15,719 Jun-28-2021, 05:23 AM
Last Post: ricslato
  numpy.float64 object is not iterable jcdr91 1 10,042 Apr-22-2020, 04:09 PM
Last Post: jefsummers
  ValueError: Found input variables with inconsistent numbers of sample robert2joe 0 2,619 Mar-25-2020, 11:10 AM
Last Post: robert2joe
  ValueError: Found input variables AhmadMWaddah 3 2,013 Mar-03-2020, 10:19 PM
Last Post: AhmadMWaddah
  Data dtype error according to the rule "safe" AndreasMavro 5 5,337 Feb-27-2020, 10:46 PM
Last Post: Pama
  dtype in not working in mad() function ift38375 8 1,637 Jul-22-2019, 02:53 AM
Last Post: scidam
  ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long' MaJeFi 2 7,336 Mar-20-2019, 06:00 AM
Last Post: MaJeFi
  ValueError: could not broadcast input array from shape (75) into shape (25) route2sabya 0 4,867 Mar-14-2019, 01:14 PM
Last Post: route2sabya
  ValueError: Found input variables with inconsistent numbers of samples: [0, 3] ayaz786amd 2 8,005 Nov-27-2018, 07:12 AM
Last Post: ayaz786amd
  numpy dtype anomaly bluefrog 4 2,047 Nov-07-2018, 12:37 AM
Last Post: bluefrog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020