Issue
A dataset has more than 2500 rows
and 22 columns
including the age column
. I have completed all of the processes for SVR. It going on. But I am still having to face an error. That is raise ValueError("bad input shape {0}".format(shape)), ValueError: bad input shape (977, 57)
. My input is SupportVectorRefModel.fit(X_train, y_train)
. How can I resolve this problem?
from sklearn.model_selection
import train_test_split
from sklearn.svm import SVR
X_train, y_train = dataset.loc[:1000], dataset.loc[:1000]
X_test, y_test = dataset.loc[1001], dataset.loc[1001]
train_X, train_y = X_train.drop(columns=['age']), y_train.pop('age')
test_X, test_y = X_test.drop(columns=['age']), y_test.pop('age')
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (977, 57)
Solution
if you want to drop the first x
rows of a given column, useDataFrame.drop
df = df.drop(range(end))
Where end
is the number of rows you want to remove from the beginning of the dataset.
Note: you cannot drop elements from a single column only. You must either drop all rows or replace the removed values with NaN or some other replacement value
Update
After further clarification by OP, the end result is to remove the age
column from the X_*
dataframes, and store the age
column in its own dataframe *_y
from sklearn.model_selection
import train_test_split
from sklearn.svm import SVR
X_train, y_train = dataset.loc[:1000], dataset.loc[:1000]
X_test, y_test = dataset.loc[1001], dataset.loc[1001]
train_X, train_y = X_train.drop(columns=['age']), y_train.pop('age')
test_X, test_y = X_test.drop(columns=['age']), y_test.pop('age')
Should give you the desired end result.
Answered By - Bobs Burgers
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.