Receiving ValueError("bad input shape {0}".format(shape)) error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Receiving ValueError("bad input shape {0}".format(shape)) error (/thread-27194.html) |
Receiving ValueError("bad input shape {0}".format(shape)) error - SuryaCitizen - May-29-2020 Hi, I'm trying to run the below code but receiving "ValueError("bad input shape {0}".format(shape))" error. Can someone please help me resolve this issue? Note: The dataset has 5 rows.https://github.com/SuryaCitizen/Data #Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd #Importing the dataset dataset = pd.read_csv('Lingard.csv') X = dataset.iloc[:, :-2].values y = dataset.iloc[:, 7:9].values print(dataset.head()) #Splitting the dataset into the Training set and Test set from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0) print(X_train) print(X_test) print(y_train) print(y_test) #Feature Scaling from sklearn.preprocessing import StandardScaler sc_X = StandardScaler() sc_y = StandardScaler() X_train = sc_X.fit_transform(X_train) y_train = sc_y.fit_transform(y_train) #Training the SVR model on the Training set from sklearn.svm import SVR regressor = SVR(kernel = 'rbf') regressor.fit(X_train, y_train) #Predicting the Test set results y_pred = sc_y.inverse_transform(regressor.predict(sc_X.transform(X_test))) np.set_printoptions(precision=2) print(np.concatenate((y_pred.reshape(len(y_pred),2), y_test.reshape(len(y_test),2)),1)) #Evaluating the Model Performance from sklearn.metrics import r2_score r2_score(y_test, y_pred) RE: Receiving ValueError("bad input shape {0}".format(shape)) error - SuryaCitizen - Jun-01-2020 Please find below complete traceback. import numpy as np import matplotlib.pyplot as plt import pandas as pd #Importing the dataset dataset = pd.read_csv('Lingard.csv') X = dataset.iloc[:, :-2].values y = dataset.iloc[:, 7:9].values print(dataset.head()) #Splitting the dataset into the Training set and Test set from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0) print(X_train) print(X_test) print(y_train) print(y_test) #Feature Scaling from sklearn.preprocessing import StandardScaler sc_X = StandardScaler() sc_y = StandardScaler() X_train = sc_X.fit_transform(X_train) y_train = sc_y.fit_transform(y_train) #Training the SVR model on the Training set from sklearn.svm import SVR regressor = SVR(kernel = 'rbf') regressor.fit(X_train, y_train) #Predicting the Test set results y_pred = sc_y.inverse_transform(regressor.predict(sc_X.transform(X_test))) np.set_printoptions(precision=2) print(np.concatenate((y_pred.reshape(len(y_pred),2), y_test.reshape(len(y_test),2)),1)) #Evaluating the Model Performance from sklearn.metrics import r2_score r2_score(y_test, y_pred) Year Matches Shots On target ... Passes passes completed Goals Assists 0 2019 19 24 14 ... 29 86 4 3 1 2018 20 41 23 ... 29 88 8 5 2 2017 18 25 13 ... 30 88 1 2 3 2016 19 23 13 ... 30 85 4 1 4 2015 7 14 8 ... 44 85 2 1 [5 rows x 9 columns] [[2018 20 41 23 18 29 88] [2016 19 23 13 10 30 85] [2015 7 14 8 6 44 85]] [[2017 18 25 13 12 30 88] [2019 19 24 14 10 29 86]] [[8 5] [4 1] [2 1]] [[1 2] [4 3]] Traceback (most recent call last): File "<ipython-input-2-54cb4f9ef960>", line 30, in <module> regressor.fit(X_train, y_train) File "C:\Users\Surya\Anaconda3\lib\site-packages\sklearn\svm\base.py", line 146, in fit accept_large_sparse=False) File "C:\Users\Surya\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 724, in check_X_y y = column_or_1d(y, warn=True) File "C:\Users\Surya\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 760, in column_or_1d raise ValueError("bad input shape {0}".format(shape)) ValueError: bad input shape (3, 2) RE: Receiving ValueError("bad input shape {0}".format(shape)) error - pyzyx3qwerty - Jun-01-2020 Please use proper input/error/output tags while posting a thread - see BBCode to know more |