How do I download .csv dataset directly from Kaggle with Matlab code.

63 visualizaciones (últimos 30 días)
Hello, I found a dataset on Kaggle which I want to use for my Machine learning project. However, I'm required to download the dataset from the code itself. I tried this:
url1 = 'https://www.kaggle.com/competitions/mrs-spring-2023-battery-prediction-challenge/data?select=example_submission.csv';
url2 = 'https://www.kaggle.com/competitions/mrs-spring-2023-battery-prediction-challenge/data?select=test_data.csv';
url3 = 'https://www.kaggle.com/competitions/mrs-spring-2023-battery-prediction-challenge/data?select=training_data.csv';
example = websave('example_submission.csv',url1);
test = websave('test_data.csv',url2);
training = websave('training_data.csv',url3);
data_example = readtable("example_submission.csv");
data_test = readtable("test_data.csv");
data_train = readtable("training_data.csv");
I was able to download them, however instead of downloading the .csv files, it is downloading an HTML page that contains the Kaggle website.
  3 comentarios
Emil Buratovic
Emil Buratovic el 19 de Mayo de 2024
Thank you for your effort.
Are there any other sites with similar datasets which I could use to download directly through code?
Star Strider
Star Strider el 19 de Mayo de 2024
My pleasure!
Not that I am aware of. You probably need to search for the sort of information you want, since I am not certain what that is.
If you have access to a university library, search using those computers because the data could be in journals that have paywalls, and the university could have access to them. Once the data are downloaded, you can send the files to your home computer via e-mail. (That is the approach I have used in the past. The university library computers I am familiar with prohibit using SD cards and such because of the malware danger.)

Iniciar sesión para comentar.

Respuesta aceptada

Harsh
Harsh el 28 de Ag. de 2024
Hi there,
It seems you're looking to download datasets from Kaggle using MATLAB. Currently, this is not feasible using only MATLAB for now. However, if Python is available, you can follow the workaround below to accomplish this by leveraging Kaggle's API commands, which are conveniently available on each dataset's page.
To start, you'll need to install the Kaggle package via pip:
pip install kaggle
Once installed, you can utilize MATLAB's system commands to execute these API calls and save the datasets as .csv files. Here's a snippet of the script I've written for this purpose:
% Download the zip file from kaggle
callSystemCmd('kaggle datasets download -d spypsc07/amazon-products')
% Unzip the zip file
callSystemCmd('tar -xf amazon-products.zip')
Here, in the above code I have created a function “callSystemCmd
%% Here’s the code for it
function callSystemCmd(cmd)
% Execute the command
[status, cmdout] = system(cmd);
% Check if the command was successful
if status == 0
disp('Command executed successfully:');
disp(cmdout);
else
disp('Command execution failed.');
end
end
After running the script above, you should see the dataset files neatly stored in your directory.
I hope this helps, thanks!
  1 comentario
Emil Buratovic
Emil Buratovic el 30 de Ag. de 2024
Thank you, I have tried that route myself but the task forbid me from using more than 1 program language.
I found completely new data set elsewhere and completed my task, however, your suggestion works,

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by