Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LR train.py train error #1

Closed
Jacquelin803 opened this issue Apr 8, 2019 · 2 comments
Closed

LR train.py train error #1

Jacquelin803 opened this issue Apr 8, 2019 · 2 comments

Comments

@Jacquelin803
Copy link

Jacquelin803 commented Apr 8, 2019

def train_lr_model(train_file,model_coef,model_file):
    total_feature_num=118
    train_label = np.genfromtxt (train_file, dtype=np.int32, delimiter=",", usecols=-1)
    feature_list = range (total_feature_num)
    train_feature = np.genfromtxt (train_file, dtype=np.int32, delimiter=",", usecols=feature_list)
    lr_cf=LRCV(Cs=[1],penalty='l2',tol=0.0001,max_iter=500,cv=5).fit(train_feature,train_label)
    scores=lr_cf.scores_.values()[0]

File "/Users/jacquelin/PycharmProjects/LR/production/train.py", line 27, in train_lr_model
lr_cf=LRCV(Cs=[1],penalty='l2',tol=0.0001,max_iter=500,cv=5).fit(train_feature,train_label)
File "/Users/jacquelin/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/logistic.py", line 1754, in fit
" class: %r" % classes[0])
ValueError: This solver needs samples of at least 2 classes in the data, but the data contains only one class: 0

could you run this train.py well?I can`t get the solution,please help me~~

@ma-zhiyuan
Copy link
Owner

This is due to too little training data. Please try some ways to extend the data.
Provide some references:
· lensacom/sparkit-learn#49

 train_Z[:, 'y']._rdd.map(lambda x: np.unique(x).size).filter(lambda x: x < 2).count()

· used a scikitlearn utils module

 from sklearn.utils import shuffle
 X_shuf, Y_shuf = shuffle(X_transformed, Y)

@Jacquelin803
Copy link
Author

This is due to too little training data. Please try some ways to extend the data.
Provide some references:
· lensacom/sparkit-learn#49

 train_Z[:, 'y']._rdd.map(lambda x: np.unique(x).size).filter(lambda x: x < 2).count()

· used a scikitlearn utils module

 from sklearn.utils import shuffle
 X_shuf, Y_shuf = shuffle(X_transformed, Y)

thank you a lot~~the error disappeared ~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants