Can someone resolve this problem

0 votes

# split data into its X and y components
X, y = data1.values[:,0:1], data1.values[:,1]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.50, random_state=0)

logreg = LogisticRegression()

# Fit logreg to the train set
logreg.fit(X_train,y_train)

ValueError                                Traceback (most recent call last)
<ipython-input-59-c70ce69fd488> in <module>
      2 
      3 # Fit logreg to the train set
----> 4 logreg.fit(X_train,y_train)
      5 

~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
   1525 
   1526         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1527                          accept_large_sparse=solver != 'liblinear')
   1528         check_classification_targets(y)
   1529         self.classes_ = np.unique(y)

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
    753                     ensure_min_features=ensure_min_features,
    754                     warn_on_dtype=warn_on_dtype,
--> 755                     estimator=estimator)
    756     if multi_output:
    757         y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,

~\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)
    529                     array = array.astype(dtype, casting="unsafe", copy=False)
    530                 else:
--> 531                     array = np.asarray(array, order=order, dtype=dtype)
    532             except ComplexWarning:
    533                 raise ValueError("Complex data not supported\n"

~\anaconda3\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
     83 
     84     """
---> 85     return array(a, dtype, copy=False, order=order)
     86 
     87 

ValueError: could not convert string to float: 'yes'
Jul 2, 2020 in Data Analytics by Abhirup
• 120 points
875 views

1 answer to this question.

0 votes

Hi@Abhirup,

Your dataset contains a string value. You need to remove the string value or convert the string value into some dummy variable. Machine Learning does not understand string values. You can use one concept named OneHotEncoding. It will create dummy variables for your string value.

answered Jul 9, 2020 by MD
• 95,440 points

Related Questions In Data Analytics

+2 votes
3 answers

Problem with installation of Wordcloud in anaconda

Using Anaconda Python 3.6 version For Windows ...READ MORE

answered Aug 7, 2018 in Data Analytics by Priyaj
• 58,090 points
18,058 views
0 votes
1 answer

How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,090 points
781 views
0 votes
1 answer

How can I measuring running time of R Code ?

5 ways to measure running time of ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
12,255 views
0 votes
1 answer

How can we trim leading and trailing whitespaces in R?

trimws {base} //Remove Leading/Trailing Whitespace Removes leading and/or ...READ MORE

answered Apr 18, 2018 in Data Analytics by zombie
• 3,790 points
1,817 views
+1 vote
2 answers

How can we count TRUE values in a logical vector?

Hi, You can get a count of all ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
9,748 views
0 votes
1 answer

How can I import multiple .csv files into R ?

## import_multiple_csv_files_to_R # Purpose: Import multiple csv files ...READ MORE

answered Apr 20, 2018 in Data Analytics by zombie
• 3,790 points
6,001 views
+1 vote
2 answers

How can I drop columns by name in a data frame ?

We can Drop Columns by name in ...READ MORE

answered Apr 14, 2018 in Data Analytics by zombie
• 3,790 points
28,076 views
+1 vote
2 answers

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
74,562 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP