in Education by
I am trying to fit some (numpy) data into python skLearn modules, but keep getting error messages. When I use the example data-set from iris, where I load it as per below from sklearn import datasets iris = datasets.load_diabetes() # load pseudo test data print(np.shape(iris.data)) print(np.shape(iris.target)) (442, 10) (442,) It works fine. But when I use my own data-set which I convert to numpy array, it fails. I cannot figure out why, as I've explicitly converted it into the same shape type as iris fileLoc = 'C:\\Users\\2018_signal.csv' data = pd.read_csv(fileLoc) fl_data = data[['signal', 'sig_dig', 'std_prx']].values fl_target = data[['actual']].actual.values ml_data = fl_data[0:int(fraction * len(fl_data))] ml_target = fl_target[0:int(fraction * len(fl_target))] print(np.shape(ml_data)) print(np.shape(ml_target)) (6663, 3) (6663,) The skLearn code as per below start_time = time.time() SKknn_pred = KNeighborsClassifier(n_neighbors=1, algorithm='ball_tree', metric = 'euclidean').fit(ml_data, ml_target).predict(ml_data) print("knn --- %s seconds ---" % (time.time() - start_time)) print("Number of mislabeled points out of a total %d points : %d" % (fl_data.shape[0],(fl_target != SKknn_pred).sum())) l_time.append(['knn', 1000 * (time.time() - start_time)]) I get the error message below... Help!!!!! ValueError Traceback (most recent call last) in () 57 58 start_time = time.time() ---> 59 SKgnb_pred = GaussianNB().fit(ml_data, ml_target).predict(fl_data) 60 print("gnb --- %s seconds ---" % (time.time() - start_time)) 61 print("Number of mislabeled points out of a total %d points : %d" % (fl_data.shape[0],(fl_target != SKgnb_pred).sum())) C:\ProgramData\Anaconda3\lib\site-packages\sklearn\naive_bayes.py in fit(self, X, y, sample_weight) 183 X, y = check_X_y(X, y) 184 return self._partial_fit(X, y, np.unique(y), _refit=True, --> 185 sample_weight=sample_weight) 186 187 @staticmethod C:\ProgramData\Anaconda3\lib\site-packages\sklearn\naive_bayes.py in _partial_fit(self, X, y, classes, _refit, sample_weight) 348 self.classes_ = None 349 --> 350 if _check_partial_fit_first_call(self, classes): 351 # This is the first call to partial_fit: 352 # initialize various cumulative counters C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in _check_partial_fit_first_call(clf, classes) 319 else: 320 # This is the first call to partial_fit --> 321 clf.classes_ = unique_labels(classes) 322 return True 323 C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in unique_labels(*ys) 95 _unique_labels = _FN_UNIQUE_LABELS.get(label_type, None) 96 if not _unique_labels: ---> 97 raise ValueError("Unknown label type: %s" % repr(ys)) 98 99 ys_labels = set(chain.from_iterable(_unique_labels(y) for y in ys)) ValueError: Unknown label type: (array([-78.375, -67.625, -66.75 , ..., 71.375, 76.75 , 78.1 ]),) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
A way to use python to correct for your own error. from sklearn import preprocessing from sklearn import utils ml_target = lab_enc.fit_transform(ml_target) print(utils.multiclass.type_of_target(ml_target)) print(utils.multiclass.type_of_target(ml_target.astype('float'))) print(utils.multiclass.type_of_target(ml_target)) The skLearn module fits the data after the transform above

Related questions

0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to do the Udacity mini project and I've got the latest version of the SKLearn library ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm creating my first program on python. The objective is to get an output of trip cost. In the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Convert pandas DateTimeIndex to Unix Time? (7 answers) Closed 3 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    Let's say I have the following code: from types import coroutine @coroutine def stop(): yield 1 async ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I used the function for gower distance from this link: https://sourceforge.net/projects/gower-distance- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have two Dataframes : DF1(That i've just resampled): Mi_pollution.head(): Sensor_ID Time_Instant ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I want to get the values of col1 in 3 different columns with separate headers. Date/Time col1 0 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm working on a project which need these deep learning libraries - keras and tensorflow. Unfortunately, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Hi Everyone I'm Having This Two Columns: Mi_Meteo['Measurement'] = Mi_Meteo['Measurement'].str.rstrip(' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I'm testing such sentence to extract entity values: s = "Height: 3m, width: 4.0m, others: 3.4 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Hi Everyone I'm Having This Two Columns: Mi_Meteo['Measurement'] = Mi_Meteo['Measurement'].str.rstrip(' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
...