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 1 in Data Analytics by Abhirup
• 120 points
105 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 by MD
• 80,790 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
• 57,700 points
9,287 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
127 views
0 votes
1 answer

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

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

answered Apr 13, 2018 in Data Analytics by zombie
• 3,770 points
12,780 views
0 votes
1 answer

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
21,608 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
4,083 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,770 points
1,099 views
0 votes
1 answer

How can I print to stdout in R?

Hi@akhtar, Sometimes we need to print to stdout ...READ MORE

answered Oct 30 in Data Analytics by MD
• 80,790 points
43 views
0 votes
1 answer

​can we do the feature extraction using K means clustering? If yes how can we do that?

Hi@Pushpender, You can do that. But K-Means is ...READ MORE

answered Nov 24 in Data Analytics by MD
• 80,790 points
24 views