grep-rohan / GenderRecognitionByVoice

Using machine learning to recognise gender by analysing recorded voice.
12 stars 6 forks source link

"Reshape your data either using array.reshape(-1, 1) if " 520 "your data has a single feature or array.reshape(1, -1) " #1

Closed GullNadia closed 4 years ago

GullNadia commented 5 years ago

Training Results:

ValueError Traceback (most recent call last)

in 17 18 if option == '1': ---> 19 neural_net.run() 20 elif option == '2': 21 if not os.path.isfile('trained_neural_net'): # check if neural_net file exists ~\GenderRecognitionByVoice\neural_net.py in run() 45 46 print('\nCalculating accuracy...\n') ---> 47 get_accuracy(x_train, x_test, y_train, y_test, trained_neural_net) # print results 48 49 ~\GenderRecognitionByVoice\data_process.py in get_accuracy(x_train, x_test, y_train, y_test, clf) 89 correct = 0 90 for index in range(len(y_train)): ---> 91 predicted = clf.predict(x_train.iloc[index, :]) 92 actual = y_train[index] 93 if actual == predicted: ~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py in predict(self, X) 956 """ 957 check_is_fitted(self, "coefs_") --> 958 y_pred = self._predict(X) 959 960 if self.n_outputs_ == 1: ~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py in _predict(self, X) 660 The decision function of the samples for each class in the model. 661 """ --> 662 X = check_array(X, accept_sparse=['csr', 'csc', 'coo']) 663 664 # Make sure self.hidden_layer_sizes is a list ~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) 519 "Reshape your data either using array.reshape(-1, 1) if " 520 "your data has a single feature or array.reshape(1, -1) " --> 521 "if it contains a single sample.".format(array)) 522 523 # in the future np.flexible dtypes will be handled like object dtypes ValueError: Expected 2D array, got 1D array instead: array=[-0.06840044 -0.04569167 -0.07454539 0.05122191 -0.13215234 -0.18143853 0.00378831 -0.01562295 0.05008664 0.10544558 -0.02366944 -0.06840044 0.05960946 0.1704949 -0.11786657 0.05839372 0.2281493 -0.04817778 -0.05295515 0.20075652]. 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.
GullNadia commented 5 years ago

there is an issue in your code kindly resolve the issue and update i am interested in ur work and want to use that

puneetbawa commented 4 years ago

you need to use the reshape(-1,1) function corresponding to the particular array generated before the predict() is called. Otherwise, both the way returns exactly the same data, therefore the 'data contiguity' is likely a non-issue as the data is not changed, only the view is changed. For more information, one can logon to the following link:

https://stackoverflow.com/questions/28385666/numpy-use-reshape-or-newaxis-to-add-dimensions

@raghav7203 check this if you can resolve.

raghav7203 commented 4 years ago

Surely could do that.I just need to copy the contents of two array in temporary array and pass on to the predict() function. I have tested and in my case it is working fine. will be generating the pull request. Thanks @puneetbawa

raghav7203 commented 4 years ago

@i-Rohan, I have commited the code change for the data_process.py. I have tested, it is working fine. Please find below the pull request:

https://github.com/i-Rohan/GenderRecognitionByVoice/pull/2

puneetbawa commented 4 years ago

Thanks @raghav7203. looks fine to me. @i-Rohan please verify for the pull request. It's much needed for the informative repositories like this.

raghav7203 commented 4 years ago

@GullNadia check for the changes. Hope it answers your question

grep-rohan commented 4 years ago

I have merged the pull request. Closing the issue.

raghav7203 commented 4 years ago

Thanks @i-Rohan