Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
¿El objeto 'DataFrame' no tiene el atributo 'ravel' al transformar la variable de destino?

Estaba ajustando una regresión logística con un subconjunto de datos. Después de dividir el conjunto de datos y ajustar el modelo, recibí el siguiente mensaje de error:

/Users/Eddie/anaconda/lib/python3.4/site-packages/sklearn/utils/validation.py:526: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True)

Así que uso target_newrdn = target_newrdn.ravel() para modificar mi variable objetivo pero me dio esto:

AttributeError: 'DataFrame' object has no attribute 'ravel'

Me pregunto cuál fue el problema y cómo puedo solucionarlo. ¿Alguien puede ayudar, por favor?

Mi código:

 from sklearn.datasets import fetch_covtype import numpy as np import pandas as pd from sklearn.utils import shuffle from sklearn.model_selection import train_test_split cov = fetch_covtype() cov_data = pd.DataFrame(cov.data) cov_target = pd.DataFrame(cov.target) data_newrdn = cov_data.head(n=10000) target_newrdn = cov_target.head(n=10000) target_newrdn = target_newrdn.ravel() ## I thought this could fix it?? X_train2, X_test2, y_train2, y_test2 = train_test_split(data_newrdn, target_newrdn, random_state=42) scaler.fit(X_train2) X_train_scaled2 = scaler.transform(X_train2) # Logistic Regression param_grid = {'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]} print(param_grid) grid = GridSearchCV(LogisticRegression(), param_grid, cv=kfold) grid.fit(X_train_scaled2, y_train2) print("Best cross-validation score w/ kfold: {:.2f}".format(grid.best_score_)) print("Best parameters: ", grid.best_params_)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Claramente, el marco de datos no tiene función ravel . Tratar:

 target_newrdn.values.ravel()

target_newrdn.values devuelve un ndarray numpy y realizas ravel en eso. Tenga en cuenta que esto devuelve una matriz numpy aplanada. Es posible que deba volver a convertir a un marco de datos.

Pero creo que necesita flatten() en su lugar, porque devuelve una copia y, por lo tanto, si modifica la matriz devuelta por ravel, no modifica las entradas en la matriz original.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!