I'm trying to split data into sets: X_train
, y_train
, X_test
, y_test
using the train_test_split()
command. Unfortunately, I get this error:
AttributeError: 'dict' object has no attribute 'data
Below is the program code:
import numpy as np
from sklearn.model_selection import train_test_split
data_array = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
target_array = np.array([11, 12, 13, 14])
array1 = {'data': data_array, 'target': target_array}
X_train, y_train, X_test, y_test = train_test_split(
array1.data, array1.target)
array1.data
is not how you get dict value in Python.
Correct syntax is
array1["data1"]