Errno 36:文件名太长:"testLogisticRegression"
Errno 36 :File name too long: "testLogisticRegression"
我有一个分类功能。我在导出数据时遇到问题。这是堆栈跟踪:
[Errno 36] File name too long: "testLogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n intercept_scaling=1, l1_ratio=None, max_iter=100,\n multi_class='warn', n_jobs=None, penalty='l2',\n random_state=None, solver='warn', tol=0.0001, verbose=0,\n warm_start=False).xlsx"
我的代码:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = [model_l, model_m, model_lr, model_r, model_k]
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model in models:
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model))
classifieur(X, y)
功能有效。造成问题的只是文件的名称。我在 linux 环境中工作。
创建一个包含模型名称和模型值的字典,并将模型名称用作文件名:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = {'model_l': model_l, 'model_m': model_m, 'model_lr': model_lr, 'model_r': model_r, 'model_k': model_k}
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model_name, model in models.items():
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model_name))
我有一个分类功能。我在导出数据时遇到问题。这是堆栈跟踪:
[Errno 36] File name too long: "testLogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n intercept_scaling=1, l1_ratio=None, max_iter=100,\n multi_class='warn', n_jobs=None, penalty='l2',\n random_state=None, solver='warn', tol=0.0001, verbose=0,\n warm_start=False).xlsx"
我的代码:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = [model_l, model_m, model_lr, model_r, model_k]
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model in models:
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model))
classifieur(X, y)
功能有效。造成问题的只是文件的名称。我在 linux 环境中工作。
创建一个包含模型名称和模型值的字典,并将模型名称用作文件名:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = {'model_l': model_l, 'model_m': model_m, 'model_lr': model_lr, 'model_r': model_r, 'model_k': model_k}
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model_name, model in models.items():
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model_name))