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

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
)
try:
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:
_ass
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.
Links to the raise (1)
https://github.com/scikit-learn/scikit-learn/blob/c67518350f91072f9d37ed09c5ef7edf555b6cf6/sklearn/utils/validation.py#L709Ways to fix
Error code:
from sklearn.utils.validation import check_array
import numpy as np
X = np.array([('str','res')])
array = check_array(X)
print(array)
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)
print(array)
Note: scikit-learn version is 0.24.2
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()
lm1.fit(X_train,y_train)
lm2 = LinearRegression()
lm2.fit(X2_train,y2_train)
lm3 = LinearRegression()
lm3.fit(X3_train,y3_train)