Generation

generate functionMon, 27 Mar 2023

There are variables X_train, X_test, y_train, y_test created through sklearn train_test_split. They contain text data in string format. Convert them to float numbers.

import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(10, 2), columns=['Col1', 'Col2']) X_train, X_test, y_train, y_test = train_test_split( df['Col1'], df['Col2'], random_state=1 ) def convert_to_float(x_train, x_test, y_train, y_test): return ( x_train.astype(float), x_test.astype(float), y_train.astype(float), y_test.astype(float) ) convert_to_float(X_train, X_test, y_train, y_test)

Questions about programming?Chat with your personal AI assistant