Search

ValueError: Masked arrays must be 1-D

The following code was written in python to generate a scatter plot of the test data after splitting it into test and train data. The data being read from a sample file was converted to matrix to be able to use the data for the the linear regression algorithm.



But using the same data for the scatter plot generated the following error.



This is because we are passing X_test and Y_test and matrices to scatter plot but which actually are one dimensional arrays. Thus to get around the problem we can cast the data into an numpy array.



The above modification should stop the error from being thrown. The modified code will be.


ValueError: Found input variables with inconsistent numbers of samples

The following code is written in python to run the liner regression algorithm on a given set of data. Two columns were chosen, namely X1 and and Y1 were chosen on which linear regression was to be performed. The code used for the same was



On executing the above code the following error was encountered.



The above error generally comes when the X and Y have different number of samples. But in this case the error appeared even though the number of samples in X_train and Y_train were same as shown in the output.



The problem with the code is that we converted the given data into numpy arrays, but it was required to convert them to numpy matrix to be able to pass it to fit. Thus we modify the reading of data to



While doing the train test split we will need to transpose the matrix



Passing these test data to the fit function should not throw the value error encountered previously. The modified code thus would be