前提・実現したいこと
pickleでファイルを保存したいがエラーが出て保存できない
機械学習の構築した学習データを用いて,ロジスティック回帰モデルで学習させたい
発生している問題・エラーメッセージ
エラーメッセージ Traceback (most recent call last): File ".py", line 36, in <module> clf = clf.fit(X_train, y_train) File "/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/_logistic.py", line 1342, in fit accept_large_sparse=solver != 'liblinear') File "/usr/local/lib/python3.6/dist-packages/sklearn/base.py", line 432, in _validate_data X, y = check_X_y(X, y, **check_params) File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 73, in inner_f return f(**kwargs) File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 803, in check_X_y estimator=estimator) File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 73, in inner_f return f(**kwargs) File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 599, in check_array array = np.asarray(array, order=order, dtype=dtype) File "/home/shoichirotaga/.local/lib/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray return array(a, dtype, copy=False, order=order) ValueError: could not convert string to float: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
該当のソースコード
import pandas as pd import pickle from sklearn.linear_model import LogisticRegression X_train = pd.read_table('train_change.feature_2.txt', header=None) y_train = pd.read_table('train_change.txt', header=None)[1] clf = LogisticRegression(penalty='l2', solver='sag', random_state=0) clf = clf.fit(X_train, y_train) with open('pickle_file.txt', 'wb') as f: pickle.dump(clf, f)
ここに言語名を入力
python3