Click here to Skip to main content
15,887,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have four .csv files containing the training data (data points and their classes) plus test data (data points and their classes) that has been stored into X_train, y_train, X_test and y_test variables respectively.

I need to train a CSV model and test it with the test data and as sklearn.svm.SVC gets numpy arrays as input I tried converting pandas data frames to numoy arrays as follows:

Python
X_train_gene = pd.read_csv("Khan_xtrain.csv").drop('Unnamed: 0', axis=1).values.ravel()
y_train_gene = pd.read_csv("Khan_ytrain.csv").drop('Unnamed: 0', axis=1).values.ravel()
X_test_gene = pd.read_csv("Khan_xtest.csv").drop('Unnamed: 0', axis=1).values.ravel()
y_test_gene = pd.read_csv("Khan_ytest.csv").drop('Unnamed: 0', axis=1).values.ravel()


How can I fix this issue?

What I have tried:

Then I tried the following lines of code to train my model:
Python
from sklearn.svm import SVC
svm_gene = SVC(C=10, kernel='linear')
svm_gene.fit(X_train_gene, y_train_gene)


But I get a value error:

ValueError: Expected 2D array, got 1D array instead: array=[ 0.7733437 -2.438405 -0.4825622 ... -1.115962 -0.7837286 -1.339411 ]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900