Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
# Logistic Regression with Split

logreg = LogisticRegression()
logreg.fit(Feature_Train, Class_Train)
Y_pred = logreg.predict(Feature_Test)
acc_log = round(logreg.score(Feature_Test, Class_Test) * 100, 2)
acc_log

What I have tried:

--------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-85-0bf2d4538de5> in <module>
2
3 logreg = LogisticRegression()
----> 4 logreg.fit(Feature_Train, Class_Train)
5 Y_pred = logreg.predict(Feature_Test)
6 acc_log = round(logreg.score(Feature_Test, Class_Test) * 100, 2)

~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
1340 _dtype = [np.float64, np.float32]
1341
-> 1342 X, y = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype,
1343 order="C",
1344 accept_large_sparse=solver != 'liblinear')

~\anaconda3\lib\site-packages\sklearn\base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
430 y = check_array(y, **check_y_params)
431 else:
--> 432 X, y = check_X_y(X, y, **check_params)
433 out = X, y
434

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74

~\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, estimator)
806 else:
807 y = column_or_1d(y, warn=True)
--> 808 _assert_all_finite(y)
809 if y_numeric and y.dtype.kind == 'O':
810 y = y.astype(np.float64)

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in _assert_all_finite(X, allow_nan, msg_dtype)
94 not allow_nan and not np.isfinite(X).all()):
95 type_err = 'infinity' if allow_nan else 'NaN, infinity'
---> 96 raise ValueError(
97 msg_err.format
98 (type_err,

ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
Posted
Updated 22-Apr-21 0:50am

1 solution

We don't know - we can't run your code in isolation, and we have no access to your data.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need. This may help: pdb — The Python Debugger — Python 3.9.4 documentation[^]


Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900