votes up 2

Unable to convert array of bytes/strings into decimal numbers with dtype='numeric'

Exception Class:

Raise code

"0.24 and will be removed in 1.1 (renaming of 0.26). Please "
                "convert your data to numeric values explicitly instead.",
                FutureWarning, stacklevel=2
                array = array.astype(np.float64)
            except ValueError as e:
                raise ValueError(
                    "Unable to convert array of bytes/strings "
                    "into decimal numbers with dtype='numeric'") from e
        if not allow_nd and array.ndim >= 3:
            raise ValueError("Found array with dim %d. %s expected <= 2."
                             % (array.ndim, estimator_name))

        if force_all_finite:
🙏 Scream for help to Ukraine
Today, 8th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 3 votes down

Error code:

from sklearn.utils.validation import check_array
import numpy as np 

X = np.array([('str','res')])
array = check_array(X)

check_array - Input validation on an array, list, sparse matrix, or similar.

By default, the input is checked to be a non-empty 2D array containing only finite values.

If the dtype of the array is an object, attempt converting to float, raising on failure.

Fix code:

from sklearn.utils.validation import check_array
import numpy as np 

X = np.array([(3,6)])
array = check_array(X)

Note: scikit-learn version is 0.24.2

Sep 18, 2021 anonim answer
anonim 13.0k
votes up 1 votes down

sc_X = StandardScaler()

X2_train = sc_X.fit_transform(X_train)

X2_test = sc_X.fit_transform(X_test)

y2_train = y_train

y2_test = y_test

y3 = y

X3 = df.drop(['GDP ($ per capita)','Country','Population', 'Area (sq. mi.)', 'Coastline (coast/area ratio)', 'Arable (%)',

           'Crops (%)', 'Other (%)', 'Climate', 'Deathrate', 'Industry'], axis=1)

X3_train, X3_test, y3_train, y3_test = train_test_split(X3, y3, test_size=0.2, random_state=101)

lm1 = LinearRegression(),y_train)

lm2 = LinearRegression(),y2_train)

lm3 = LinearRegression(),y3_train)

Apr 19, 2022 hamad264khan answer

Add a possible fix

Please authorize to post fix