I am new to machine learning, I am trying to apply logistic regression on my sample data set I have a single feature that contains a list of numbers and want to predict class.
the following is my code
from sklearn.linear_model import LogisticRegression
a = [[1,2,3], [1,2,3,4,5,6], [4,5,6,7], [0,0,0,7,1,2,3]]
b = [0,1,0, 0]
p = [[9,0,2,4]]
clfModel1 = LogisticRegression(class_weight='balanced')
clfModel1.fit(a,b)
clfModel1.predict(p)
I am getting the following error
Traceback (most recent call last):
File "F:\python_3.4\NLP\t.py", line 7, in <module>
clfModel1.fit(a,b)
File "C:\Python34\lib\site-packages\sklearn\linear_model\logistic.py", line 1173, in fit
order="C")
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 521, in check_X_y
ensure_min_features, warn_on_dtype, estimator)
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 382, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: setting an array element with a sequence.
>>>
Is there some way to change the data such that I can the apply the classifier and predict the results
ais not a valid input - it is a staggered "matrix". In logistic regression, each feature needs to be a number, not a list. How is this suppose to work with logistic regression?LogisticRegression.fitmethod work is to make all the sublists inathe same size, however, wihtout understanding your data there is no way to say how you could do that in a valid and useful way.