Adjust the structure of your data by utilizing the Python function array.reshape(-1, 1)

Hello, I'm in need of some assistance with this error:

ValueError: Expected to receive a 2D array, but instead got a 1D array:
array=[0. 0. 0. ... 0. 0. 1.].
To resolve this, you can reshape your data by using either array.reshape(-1, 1) if it's a single feature or array.reshape(1, -1) if it's a single sample.

The relevant code is as follows:

train, test = train_test_split(dataset_ordenado, test_size = 0.30, random_state = 20201122) 

Objetivo_train=train['results']

Objetivo_test=test['results']

Indep_train=train.drop(['results'],axis=1)

Indep_test=test.drop(['results'],axis=1)


TS = TimeSeriesSplit(n_splits = 5)

dt = DecisionTreeClassifier()

grid = {'max_depth': [5,7,9,11,15], 'min_samples_leaf': [5,7,9,11,13],'criterion': ['gini', 'entropy']}

gs = GridSearchCV(dt, param_grid=grid, cv=TS)


gs.fit(Objetivo_train, Indep_train)

Answer №1

After realizing my mistake, I discovered that the data I downloaded from AWS was in pickle format and all the values were stored as objects. Therefore, I needed to convert all the values into numbers.

In case anyone else encounters this issue, I have shared the code for transforming all the columns into numbers.

FIRSTLY, I OBTAIN THE VARIABLES IN A LIST FORMAT columns_names = dataset_ordenado.columns.values[1:]

Next, I convert the column names into a list columns_names_list = list(columns_names)

CONVERSION PROCESS dataset_ordenado[columns_names_list]=dataset_ordenado[columns_names_list].apply(pd.to_numeric)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

BeautifulSoup fails to detect tables within webpage

I am struggling to extract the data from the first table on a website. Despite attempting various solutions found here, I have been unsuccessful in locating the table and consequently retrieving the data within it. The methods I have tried are as follows: ...

Using the storage() method in Pytorch, all Tensor storages will share the same id

Currently, I am delving into the realm of tensor storage by exploring a blog written in my mother tongue, Vietnamese. While tinkering with various examples, I stumbled upon a concept that proved to be quite perplexing. Consider three tensors x, zzz, and x_ ...

Discovering the highest possible result when multiplying three numbers within a list of varying lengths

After completing a practice problem, I came up with the following solution: The task was to find the largest product that could be made by multiplying any three integers from a given list. For instance, if the list is [-10, -10, 5, 2], the answer should ...

What is preventing Python ECDSA from being able to handle negative numbers?

I am currently working on a Python script to validate an ECDSA signature, but I am facing challenges in the process. Below is the code snippet I am using: public_key = ecdsa.VerifyingKey.from_string(pubkey, curve=ecdsa.SECP256k1) verified = public_key.ve ...

The send_keys function in Selenium fails to function properly when using Chrome browser

Recently, I've been working on writing Python autotests for a web UI and encountered an issue with the send_keys() method after updating my Chrome driver. When trying to input text into a field using send_keys(), it behaves strangely. For example: na ...

Issue encountered when running Python scripts using Selenium

I have set up python, pip, and selenium on my computer and I am currently running a sample code on some basic websites. Code: from selenium import webdriver import time driver = webdriver.Chrome("C:\\Users\\skandregula\\Py ...

Implementing Python multiprocessing to execute x number of processes simultaneously

My current project involves multiple python functions, each belonging to a different class. I want to be able to run x of these functions in parallel at any given time, unless there are fewer than x remaining. Essentially, I am looking to create a queue o ...

Combining DataFrames in Pandas with custom weights

This question resembles: Merge DataFrames in Pandas using the mean, however, I require arbitrary weights instead of just the simple mean. I possess two DFs structured like this: df1 from_code to_code frequency a a 0.2 a b 0.4 df2 from_code ...

How can we extract word array in Python that works like CryptoJS.enc.Hex.parse(hash)?

Is there a method in Python to convert a hash into a word array similar to how it's done in JavaScript? In JavaScript using CryptoJS, you can achieve this by using: CryptoJS.enc.Hex.parse(hash), which will provide the word array. I've searched ...

Python's request function is only retrieving a single element

Below is the code snippet I have: import base64 import requests import json import csv USERNAME, PASSWORD = 'Username', 'Password' req = requests.get( url="https://api.mysportsfeeds.com/v1.1/pull/nhl/2017-2018-regular/game_startin ...

A deep dive into the nuances of DP: Unlocking the

Examining the codes below, I implemented two different approaches to solve the problem (simple recursive and DP). Why is the DP method slower? Do you have any suggestions? #!/usr/local/bin/python2.7 # encoding: utf-8 Problem Statement: An array contains ...

Having trouble running Selenium Chrome Driver on Pi Zero with error code -4?

Having trouble setting up a script on my new Pi Zero W after it was previously working on my Pi 3 B. It seems like the hardware may be the culprit as simply transferring the entire operating system to the new pi results in this issue, with no other changes ...

Error occurs when Django MultipleChoiceField options selected by users are not valid choices

I need help creating a form that allows users to select multiple users from a specific group. However, I encountered an error stating that the 'User' object does not support indexing when trying to use the list of users as options. The form is p ...

Utilizing Blender Python scripting to ensure seamless user interface functionality during extensive computational processes

Currently, I am engaged in scripting with Blender to handle multiple objects simultaneously. However, whenever I run my script, it causes the user interface to freeze while executing its tasks. I am seeking a way to prevent this issue so that I can monitor ...

Exploring mammoth text data in Python

I am currently diving into Python development with my first project, which involves parsing a hefty 2GB file. After discovering that processing it line by line would be agonizingly slow, I decided to opt for the buffering method. Here's what I'm ...

Performing mathematical operations with Pandas on specific columns based on conditions set by other columns in the dataset

I am working with a Pandas DataFrame import pandas as pd inp = [{'c1':1, 'c2':100}, {'c1':1,'c2':110}, {'c1':1,'c2':120},{'c1':2, 'c2':130}, {'c1':2,'c2':14 ...

Error: The variable "tree" has not been declared

Hello, I am a Python newcomer and I'm currently following a tutorial. However, I encountered the following error: NameError: name 'tree' is not defined. The goal of my program is to classify fruits as either apples or oranges based on t ...

Encountering problems with Python type annotations when inheriting types and overloading members

Here is an example below using Python 3.7 where I am struggling to correctly annotate my code. Mypy is showing errors in the annotations which are explained in comments. I have a "generic class" that contains "generic members", and concrete classes along ...

Converting Grouped Pandas DataFrames to JSON format

I am encountering some difficulties converting the given dataframe into a JSON structure. Despite my attempts, I haven't been able to complete the final step successfully. Here is the data frame I have: serialNumber | date | part | value | n ...

How to interact with a button inside a span element without an ID using Selenium

Can anyone help me figure out how to click a button in the browser using Selenium and Python? The button I am trying to click is located within this HTML code: <div id="generate"> <i class="fa fa-bolt"></i> <span>D ...