When you want to predict a variable, would it not make sense for the csv file not to have the prediction labels? Does it need that extra column?
This would be the case for all kaggle competitions / competitions that focus on predicting an output variable.
What's the best way to deal with this sort of error?
looking at the data from the (Kaggle Titanic Link)[https://www.kaggle.com/c/titanic/] I ran an experiment:
ludwig experiment --data_csv data/train.csv --model_definition_file model_definition.yaml
And then get the trained model, I want to use that to predict the classes from the 'test.csv'.
The issue is that the test.csv (by design) doesn't have 'survived' labels. Ludwig throws an error
(ludwig) ➜ testing_ludwig git:(master) ✗ ludwig predict --data_csv data/test.csv -m results/experiment_run_1/model
_ _ _
| |_ _ __| |_ __ _(_)__ _
| | || / _` \ V V / / _` |
|_|\_,_\__,_|\_/\_/|_\__, |
|___/
ludwig v0.1.0 - Predict
Dataset type: generic
Dataset path: data/test.csv
Model path: results/experiment_run_1/model
Output path: results_0
Loading metadata from: results/experiment_run_1/model/train_set_metadata.json
/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/features/numerical_feature.py:63: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
np.float32).as_matrix()
Traceback (most recent call last):
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2656, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Survived'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/tommylees/miniconda3/envs/ludwig/bin/ludwig", line 10, in <module>
sys.exit(main())
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/cli.py", line 86, in main
CLI()
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/cli.py", line 64, in __init__
getattr(self, args.command)()
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/cli.py", line 73, in predict
predict.cli(sys.argv[2:])
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/predict.py", line 379, in cli
full_predict(**vars(args))
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/predict.py", line 86, in full_predict
only_predictions
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 674, in preprocess_for_prediction
train_set_metadata=train_set_metadata
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 62, in build_dataset
**kwargs
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 90, in build_dataset_df
global_preprocessing_parameters
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 153, in build_data
preprocessing_parameters
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 174, in handle_missing_values
dataset_df[feature['name']] = dataset_df[feature['name']].fillna(
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/pandas/core/frame.py", line 2927, in __getitem__
indexer = self.columns.get_loc(key)
File "/Users/tommylees/miniconda3/envs/ludwig/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2658, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Survived'
PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C
PassengerId,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
892,3,"Kelly, Mr. James",male,34.5,0,0,330911,7.8292,,Q
893,3,"Wilkes, Mrs. James (Ellen Needs)",female,47,1,0,363272,7,,S
What happens if you just add the "Survived" column to the header row in test.csv?
Please use the --only_predictions option as documented in the docs and asked in many other questions already. The next release of Ludwig will default to it.
Sorry! I am reading the docs now. They are extremely detailed. Thank you very much for your hard work!
Thank you for your kind words, you're welcome. I love the noble causes you use machine learning for, and if Ludwig can help you with that, I'm even more glad.
Most helpful comment
What happens if you just add the "Survived" column to the header row in test.csv?