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
45 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
• 40,740 points

Related Questions In Data Analytics

+1 vote
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,550 points
8,036 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,080 points
98 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,750 points
2,857 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
13,366 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
2,226 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,750 points
943 views
0 votes
2 answers

How can we count TRUE values in a logical vector?

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

answered Aug 20, 2019 in Data Analytics by anonymous
• 32,460 points
5,327 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 19, 2018 in Data Analytics by zombie
• 3,750 points
3,288 views
0 votes
1 answer

How can I define Global Variables in R?

The variables declared inside a function are ...READ MORE

answered Apr 25, 2018 in Data Analytics by shams
• 3,600 points
3,405 views