Hola! Cómo puedo solucionar este error? Es el código copiado de "Haga lo que hicimos"
import numpy as np
x = datos[['horas_esperadas','precio']]
y = datos.finalizado
SEED = 42
np.random.seed(SEED)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, stratify=y )
print(f"Entrenaremos con {len(x_train)} elementos y probaremos con {len(x_test)} elementos")
model = LinearSVC()
model.fit(x_train,y_train)
previsiones= model.predict(x_test)
tasa_de_acierto = accuracy_score(y_test,previsiones)
print(f'La tasa de acierto fue de : {round(tasa_de_acierto*100,2)} %')
KeyError Traceback (most recent call last)
<ipython-input-57-e120d928d3d4> in <module>
1 import numpy as np
2
----> 3 x = datos[['horas_esperadas','precio']]
4 y = datos.finalizado
5
2 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in __getitem__(self, key)
3462 if is_iterator(key):
3463 key = list(key)
-> 3464 indexer = self.loc._get_listlike_indexer(key, axis=1)[1]
3465
3466 # take() does not accept boolean indexers
/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py in _get_listlike_indexer(self, key, axis)
1312 keyarr, indexer, new_indexer = ax._reindex_non_unique(keyarr)
1313
-> 1314 self._validate_read_indexer(keyarr, indexer, axis)
1315
1316 if needs_i8_conversion(ax.dtype) or isinstance(
/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis)
1372 if use_interval_msg:
1373 key = list(key)
-> 1374 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
1375
1376 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
KeyError: "None of [Index(['horas_esperadas', 'precio'], dtype='object')] are in the [columns]"